CS 271 Module 5

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

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

An input/output parameter may be passed by value.

False

High-level languages always pass arrays to subroutines by value.

False

The POP instruction can have an immediate operand.

False

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

False, ESP is always decremented when data is pushed onto the stack.

Which of the following is true about the PUSH instruction?

It decrements the stack pointer (by 2 or 4), and then copies the operand into the stack at the location pointed to by the stack pointer.

Which of the following code sequences assigns the value 10 to EBX?

MOV EDX, 20 PUSH EDX MOV ECX, 10 PUSH ECX POP EBX POP EDX

Which parameter-passing method is commonly used by compilers?

Passing parameters on the stack.

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.

What does CALL push to the stack?

The address of the instruction immediately following the CALL instruction.

A stack frame is _____

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

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

True

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

True

The PUSH instruction can have an immediate operand.

True

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

nested

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

on the stack

There are several important uses of runtime stacks in programs (select all that apply):

*The stack provides temporary storage for local variables. *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.

Assume ESP = 00F4h, and then PUSHAD 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. 32d = 20h. 00F4h - 0020h = 00D4h

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

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

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

4

Another name for a stack frame is

Activation record

Which of the following are normally part of the stack frame? (Select all that apply)

Arguments Local Variables Saved Register Values Return Address

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

ESP

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

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.

What directives are used to bracket a procedure?

PROC and ENDP

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

PUSHAD

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

PUSHF

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)

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

Pass Parameters in Registers

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.

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.

An input parameter may be passed by reference.

True

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

arguments

Select the proper syntax for establishing a subprocedure.

procedureName PROC ;... ;... RET ;return to calling procedure procedureName ENDP

ESP always points to ______

the last value to be added to, or pushed on, the top of stack.


Kaugnay na mga set ng pag-aaral

Networking and Connecting to the Internet Quiz - 98%

View Set

Chapter 8: Segment and Interim Reporting

View Set

Unit 3 Lesson 9 Textbook Reading

View Set