CS271 Module 5

Ace your homework & exams now with Quizwiz!

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).

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

ESP

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

False. It is decremented

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

POP

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

POPA

Pops all the 16-bit general-purpose registers onto the stack in the reverse order that PUSHAD pushes them: EDI, ESI, EBP, ESP, EBX, EDX, ECX, EAX.

POPAD

Pops all the 32-bit general-purpose registers onto the stack in the reverse order that PUSHAD pushes them: EDI, ESI, EBP, ESP, EBX, EDX, ECX, EAX.

PUSHA

Pushes all the 16-bit general-purpose registers onto the stack in the following order: EAX, ECX, EDX, EBX, ESP (value before executing PUSHAD), EBP, ESI, and EDI

PUSHAD

Pushes all the 32-bit general-purpose registers onto the stack in the following order: EAX, ECX, EDX, EBX, ESP (value before executing PUSHAD), EBP, ESI, and EDI

Use Shared Memory (global variables)

Simply set up the contents of the variables, then call the procedure. The called procedure then uses those values as necessary, may assign new values, and then returns. (Not recommened)

4

The RET instruction (without operands) will pop how many bytes off the stack?

True

The USES operator, coupled with the PROC directive, lets you list the names of all registers modified within a procedure and preserves them automatically for you.

Arguments

Values passed to a subroutine by a calling program are called __________.

Stack parameters reduce code clutter because registers do not have to be saved and restored. Stack parameters are compatible with high-level languages.

What advantages do stack parameters have over register parameters? - Stack parameters reduce code clutter because registers do not have to be saved and restored. - Programs using stack parameters execute more quickly. - Stack parameters are compatible with high-level languages. - Register parameters are optimized for speed.

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

What are some disadvantages of passing parameters using globals?

PROC and ENDP

What directives are used to bracket a procedure?

The address of the instruction immediately following the CALL instruction.

What does CALL push to the stack?

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

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

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

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

Value parameters Reference parameters

What general types of parameters are passed on the stack? - Value parameters - Stack frames - Reference parameters - Activation records - Local variables

Stack overflow

What happens if the runtime stack is not properly managed?

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.

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

False

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

True

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

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

A stack frame is _____

True

A subprocedure's stack frame contains the return address and its local variables.

nested

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

True

An input parameter may be passed by reference.

00F6h ESP is incremented by 2 (the size of AX).

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

00F0h. ESP is decremented by 4

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

00D4h PUSHAD pushes eight (8) four-byte registers on the stack, so ESP is decremented by 4*8=32.

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

True

Mechanically speaking, the CALL instruction pushes its return address on the stack and copies the called procedure's address into theinstruction pointer.

True

Passing by reference requires accessing a parameter's offset from inside the called procedure.

Activation Record

The stack frame inside a procedure is also known as the ____________.

When calling a subroutine, you pass input values called arguments by pushing them on the stack. When the CALL instruction executes, the stack is used to store the address where the called procedure will return to. The stack makes a convenient temporary save area for registers when they are used for more than one purpose. The stack provides temporary storage for local variables.

There are several important uses of runtime stacks in programs (select all that apply): - When calling a subroutine, you pass input values called arguments by pushing them on the stack. - When the CALL instruction executes, the stack is used to store the address where the called procedure will return to. - The stack makes a convenient temporary save area for registers when they are used for more than one purpose. - The stack provides temporary storage for local variables.

Pass Parameters in Registers

What parameter-passing method do most/all of Irvine's library procedures use?

PUSHAD or PUSHA

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

False

When an argument is passed by value, a copy of the address is pushed on the stack.

In program space. an area of memory addresses allocated to one program's code segment, data segment, stack segment, etc...

Where in memory is the runtime stack?

Local Variables Return Address Saved Register Values Arguments

Which of the following are normally part of the stack frame? (Select all that apply) - Local Variables - Calling Procedure Starting Address - Return Address - Saved Register Values - Arguments

RET PUSH POP CALL

Which of the following instructions modify the ESP register? (Check all that apply) - RET - PUSH - POP - CALL - JMP - INC - JNE - DEC

Parameters are passed in registers. 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)

Which parameter-passing method does Irvine Library procedure ReadString use? What are 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

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

Passing parameters on the stack.

Which parameter-passing method is commonly used by compilers?

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

Why is a stack called a LIFO structure?

Pass Parameters in Registers

method to pass parameters is to use the CPU general-purpose registers to temporarily store the parameters for a procedure.

Input parameter

data passed by a calling procedure to a called procedure.

Input-Output parameter

passed by reference, but not only will the parameter will be used by the called procedure, the memory containing it will also be modified by the called procedure

Output parameter

passing the address of an argument variable to a called procedure when it is called

POPFD

pops the top of the stack into the EFLAGS register

PUSHFD

pushes the 32-bit EFLAGS register to the stack

Pass Parameters on the Runtime Stack

put the arguments onto the runtime stack and then let the called procedure copy, overwrite, or reference them as needed


Related study sets

Ch 20 NCLEX, Pellico Ch. 8 Nursing Assessment: Respiratory Function (Prep-U), Respiratory PrepU

View Set

Human Activity and the Biosphere

View Set

World History Chapter 16 Section 2

View Set

Congenital Deformities of the Foot & Ankle

View Set

Environmental Laws and Regulations

View Set

IT Security Audits Ch. 1-4 Questions

View Set