Unit 4: Assembly Language Part II Review

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/55

flashcard set

Earn XP

Description and Tags

FIX LATER

56 Terms

1
New cards

What is the heap used for?

Dynamic memory that can be allocated and deallocated at runtime

2
New cards

What are the two parts of heap memory?

Heap data and heap management

3
New cards

What is heap data?

Memory that can be allocated and deallocated

4
New cards

What is heap management?

A table that tracks which heap memory is allocated and which is free

5
New cards

Where is the heap management table stored?

In the heap area, not in registers

6
New cards

What are the steps to allocate n units from the heap?

Find a free block of size n in the heap management table, mark it used, and return its address

7
New cards

What are the key features of heap memory in ANNA?

Only allocation is supported, with no deallocation

8
New cards

How does ANNA implement heap management?

With a single pointer to the next free word in the heap

9
New cards

In ANNA heap memory, what does memory before the heap pointer represent?

Heap memory that is already used or allocated

10
New cards

Where is the heap placed in ANNA memory layout?

After code and data, before the stack

11
New cards

What is the ANNA memory layout order?

Code, Data, Heap, Stack

12
New cards

Where does the ANNA stack start?

At address 0x8000

13
New cards

For int *p = new int[n] in ANNA, what does p receive and what happens to the heap pointer?

p receives the current heap pointer, and the heap pointer advances by n words

14
New cards

For Node *p = new Node with int val and Node *next, what memory is allocated and how are fields set?

Two words are allocated, val is stored at the first word, and next is stored at the second word

15
New cards

What is a function call in assembly?

A transfer of control to a function label with arguments and return address arranged by the calling convention

16
New cards

What is the return address of a function call?

The address of the instruction after the call, used by ret to resume the caller

17
New cards

What are typical caller responsibilities in a calling convention?

Place arguments, save caller-saved registers if needed, call the function, and retrieve the return value

18
New cards

What are typical callee responsibilities in a calling convention?

Save callee-saved registers, set up a frame, execute the body, restore state, and return the result

19
New cards

What is a function prologue?

Code at function entry that sets up the stack frame and saves needed registers

20
New cards

What is a function epilogue?

Code at function exit that restores the stack and registers and returns to the caller

21
New cards

How do you write a simple complete assembly function?

Use a label, prologue, body, epilogue, and ret while following the calling convention

22
New cards

How do you write a function call in assembly?

Set up arguments, call the function label, then use the return value and clean up as the convention requires

23
New cards

What hardware support is used for function calls and returns?

call pushes the return address and jumps to the function, and ret pops the return address and jumps back

24
New cards

What is stack memory used for?

Function call management, local variables, parameters, return addresses, and saved registers

25
New cards

What is an activation record?

The stack frame for one function invocation containing parameters, locals, saved registers, and return address

26
New cards

What is the stack pointer?

A register that points to the current top of the stack

27
New cards

What is the frame pointer?

A register that points to the base of the current activation record

28
New cards

Why use a frame pointer?

It gives stable access to locals and parameters even when the stack pointer changes

29
New cards

What is a calling convention?

An agreement on argument passing, return values, register preservation, and stack cleanup

30
New cards

In which direction does the stack typically grow?

Downward toward lower addresses

31
New cards

What does push do?

It decrements the stack pointer and stores a value at the new top of stack

32
New cards

What does pop do?

It loads a value from the top of stack and increments the stack pointer

33
New cards

What happens to activation records during recursion?

Each recursive call gets its own activation record on the stack

34
New cards

What is a segmentation fault?

Accessing an address outside the program's allowed segment

35
New cards

What is a null pointer dereference?

Dereferencing a pointer whose value is NULL

36
New cards

What is stack overflow?

The stack limit is reached, so there is no space for another activation record

37
New cards

What is heap overflow?

The heap limit is reached, so an allocation cannot be satisfied

38
New cards

What is array out-of-bounds?

Using an index outside the bounds of an array

39
New cards

What is buffer overflow?

Writing data beyond a buffer boundary and overwriting adjacent memory

40
New cards

Why do array out-of-bounds and buffer overflow often not cause segmentation faults?

The adjacent overwritten memory is still within the program segment

41
New cards

What is double free?

Deallocating memory that was already deallocated

42
New cards

What is invalid free?

Deallocating memory that was never dynamically allocated or not using the block start address

43
New cards

What is dangling pointer dereference?

Dereferencing a pointer to memory that was previously deallocated

44
New cards

What is a memory leak?

Failing to deallocate memory once it is no longer needed

45
New cards

What are ways to handle memory errors?

Exceptions, garbage collection, language limitations, programmer detection, and crashes or aborts

46
New cards

How do exceptions handle memory errors?

They automatically detect and throw an exception, the program can catch and recover, and an uncaught exception aborts the program

47
New cards

How does garbage collection handle memory errors?

It automatically deletes unneeded memory, requires no explicit deallocation, and makes leaks less likely but still possible

48
New cards

What is the language limitation approach to memory errors?

Restrict pointer operations so pointers cannot point to invalid memory

49
New cards

In C++ vs Java, which memory errors are not possible in Java?

Segmentation fault, double free, invalid free, and dangling pointer dereference

50
New cards

In C++ vs Java, how does Java handle null dereference, stack overflow, heap overflow, array out-of-bounds, and buffer overflow?

It handles them as exceptions

51
New cards

In C++, how are array out-of-bounds and buffer overflow detected?

They are usually not detected unless they cause a segmentation fault

52
New cards

Why does C++ not detect array out-of-bounds?

It does not perform automatic bounds checks, often for performance

53
New cards

What are problems with C++ not detecting array out-of-bounds?

Silent memory corruption, security bugs, and incorrect output

54
New cards

In C++, what happens for segmentation fault, null dereference, stack overflow, double free, and invalid free?

The program crashes

55
New cards

In C++, what happens for heap overflow?

It raises an exception

56
New cards

In C++ and Java, when is a memory leak detected?

It is not detected until heap overflow