MASM Procedures & Intro to the Runtime Stack (Module 5)

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/43

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

44 Terms

1
New cards

PUSH

Push on Runtime Stack. Decrements the ESP value (the stack pointer) and then loads a source operand onto the stack's top.

2
New cards

POP

Pop from Runtime Stack. Loads the value from the stack's top (ESP points to this value) to the location specified by the destination operand.

3
New cards

PUSHAD

PUSHAD pushes eight (8) four-byte registers on the stack

4
New cards

POPAD

Pop All GP Registers. Pops the top 32 BYTEs from the top of the stack into eight general-purpose registers in the following order: EDI, ESI, EBP, ESP, EBX, EDX, ECX, EAX

5
New cards

PUSHFD

Push EFLAGS Register. Pushes the 4 BYTE EFLAGS (Status Flags) register onto the stack.

6
New cards

POPFD

Pop EFLAGS Register. Pops the top 4 BYTEs of the stack into the EFLAGS (Status Flags) Register.

7
New cards

CALL

Call a Procedure. Saves on the stack the memory location of the instruction that follows the CALL instruction, then branches to the called procedure's memory location.

8
New cards

RET

Return from Procedure. Pops off the return address located on the top of the stack into the EIP register (the instruction pointer).

9
New cards

In 32-bit mode, which register points to the top of the stack?

ESP

10
New cards

Why is a stack called a LIFO structure?

The last value pushed on the stack is the first value to be popped from the stack.

11
New cards

Assume ESP = 00F4h, and then PUSH EAX is executed. What is the new value of ESP?

00F0h

ESP is decremented by 4 (the size of EAX). 00F4h - 0004h = 00F0h

12
New cards

Assume ESP = 00F4h, and then POP AX is executed. What is the new value of ESP?

00F6h

ESP is incremented by 2 (the size of AX). 00F4h + 0002h = 00F6h

13
New cards

(True/False) The PUSH instruction can have an immediate operand.

True

14
New cards

(True/False) The POP instruction can have an immediate operand.

False

15
New cards

What directives are used to bracket a procedure?

PROC and ENDP

16
New cards

(True/False) If RET was left out of a procedure, execution would stop at the ENDP directive.

False

RET updates EIP to return to the calling procedure. Without it, execution will run right over the ENDP and continue to the next address in memory immediately after the procedure.

17
New cards

What does CALL push to the stack?

The address of the instruction immediately following the CALL instruction.

18
New cards

Which parameter-passing method does Irvine Library procedure ReadString use? What are the pre/postconditions, receives/returns?

Parameters are passed in registers.

Preconditions: Array is type BYTE, buffer size large enough to accommodate user input.

Postconditions: Registers changed EDX, EAX

Receives EDX (address of string buffer) and ECX (buffer size, allows user input size ECX-1).

Returns EDX (address of user string) and EAX (number of characters stored)

19
New cards

What does PUSH OFFSET myVar, where myVar is a data-segment variable, put on the stack?

The address of (pointer to) the memory location where the value of myVar is stored.

20
New cards

What does PUSH myVar, where myVar is a data-segment variable, put on the stack?

The current value in memory at the location myVar refers to.

21
New cards

What are some disadvantages of passing parameters using globals?

Modifying a global in a procedure modifies it outside the procedure.Use of globals makes a procedure far less modular.

22
New cards

Which parameter-passing method is commonly used by compilers?

Passing parameters on the stack.

23
New cards

If you're passing a pointer, which of the three parameter types might your parameter be classified as?

May be either an output parameter or an input-output parameter. In fact, it may even be an input parameter (for example with Irvine's WriteString).

24
New cards

What single instruction would I use to save all general purpose registers?

PUSHAD

25
New cards

(True/False) In the IA32 architecture, ESP (the stack pointer) is incremented each time data is pushed onto the stack.

False

26
New cards

What instruction would I use to save the current value of the flags register?

PUSHF

27
New cards

PUSHF is used to preserve all general purpose register contents on the stack.

False

28
New cards

Which of the following is true about the POP instruction?

It copies the data pointed to by the stack pointer into the operand, and then increments the stack pointer (by 2 or 4).

29
New cards

The CALL instruction functions similarly to which of the following?

Push, then Jump

30
New cards

ng instructions always modify the ESP register? (Check all that apply)

31
New cards

A stack frame is _____

The area of the stack set aside for passed arguments, return address, local variables, and saved registers.

32
New cards

A/An ________ procedure call occurs when a called procedure calls another procedure before the first procedure returns.

nested

33
New cards

(True/False) A subprocedure's stack frame contains the return address and its local variables.

True

34
New cards

(True/False) An input parameter may be passed by reference.

True

35
New cards

(True/False) Passing by reference requires accessing a parameter's offset from inside the called procedure.

True

36
New cards

When values are received by a called subroutine, they are called __________.

parameters

37
New cards

(True/False) High-level languages always pass arrays to subroutines by value.

False

38
New cards

(True/False) Arrays are passed by reference to avoid copying each element into the stack/registers.

True

39
New cards

Which offers a more flexible approach, passing arguments to procedures in registers, or on the stack?

on the stack

40
New cards

Where is the runtime stack located in memory?

It is located in the Stack Segment of the program's memory space (Main Memory/RAM).

41
New cards

Instructions that utilize the runtime stack

PUSH, POP, CALL, and RET. They all modify the ESP (Stack Pointer) register.

42
New cards

Consequence of improper runtime stack management

Stack overflow (running out of stack space), stack underflow (popping too many times), or corrupting the return address, which leads to program crashes.

43
New cards

A copy of the actual data is passed to the procedure. Changes made inside the procedure do not affect the original variable in the caller.

Passing by Value

44
New cards

The memory address of the variable is passed. Changes made inside the procedure do affect the original variable in the caller.

Passing by Reference/Address