271 - MODULES 5/6
A stack is also called a FIFO structure (First-In, First-Out) because the last value put into the stack is always the first value taken out.
False
An input/output parameter may be passed by value.
False
PUSHF is used to preserve all general purpose register contents on the stack.
False
The POP instruction can have an immediate operand
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
A value determined by the procedure, and communicated back to the calling procedure.
Return Value
Given an odd-parity system which checks parity 16 bits at a time, the following data would be flagged as having an error. 1111 1001 1011 1000
TRUE
Given an odd-parity system which checks parity 16 bits at a time, the following data would be flagged as having an error. 1111 1111 0000 1010
TRUE
One cause of bit errors is signal noise.
TRUE
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.
In the IA32 architecture, ESP (the stack pointer) is incremented each time data is popped from the stack.
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
Passing by reference requires accessing a parameter's offset from inside the called procedure.
True
The PUSH instruction can have an immediate operand
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.
True
What general types of parameters are passed on the stack? Local variables Stack frames Activation records Value parameters Reference parameters
Value parameters Reference parameters
A/An ________ procedure call occurs when a called procedure calls another procedure before the first procedure returns.
nested
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?
00F0hESP 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?
00F6hESP is incremented by 2 (the size of AX). 00F4h + 0002h = 00F6h
Given an even-parity system which checks parity 16 bits at a time, the following data would be flagged as having an error. 1111 1111 0000 1010
FALSE
Assuming ESP = 0400h, EAX = 40d, EBX = 120d at the beginning of main, show the state of the runtime stack at Execution Point A. Signify a return address as "Return @ from ProcName" where ProcName is the name of the called procedure. main PROC CALL someProc1 ; ... exit main ENDP someProc1 PROC PUSH EAX CALL someProc2 ; ... POP EAX RET someProc1 ENDP someProc2 PROC PUSH EBX ; Execution Point A ; ... POP EBX RET someProc2 ENDP
Address(in Runtime Stack) Value Description 03F0h 120d Value of EBX 03F4h Return @ from someProc2 03F8h 40d Value of EAX 03FCh Return @ from someProc1 0400h ??? Unknown
A value or reference passed to a procedure.
Argument
If they did not have error detection/correction, WiFi systems would almost never send/receive signals containing bit errors.
FALSE
Simple parity checks can correct any single-bit errors.
FALSE
Assume ESP equals 1C3Fh at Execution Point A. Trace the following code to Execution Point B, then answer the questions below. MOV EAX, 7 MOV EBX, 11 MOV ECX, 42 MOV EDX, 99 ; Nine Nine! ; Execution Point A PUSH EAX PUSH ECX PUSH EDX PUSH EBX POP EBX ; Execution Point B POP EDX POP EAX POP EDX At Execution Point B, what is the decimal value in EBX? At Execution Point B, what is the hexadecimal value in ESP? At Execution Point B, what is the decimal value in[ESP] ?
EBX 11 ESP 1C33 [ESP] 99
The RET instruction pops the top of the stack into what register?
EIP
In 32-bit mode, which register points to the top of the stack?
ESP
An even parity system requires an ________ number of '1'-bits for parity.
Even
Initialized State X 17 Y 20 Z 13 ESP 0F1Ch [ESP] 42 PUSH X INC X ; Execution Point A PUSH Y ; Execution Point B POP X INC X ; Execution Point C POP Z ; Execution Point D
Ex point A: X 18 Y 20 Z 13 ESP 0F18h [ESP] 17 Ex point B: X 18 Y 20 Z 13 ESP 0F14h [ESP] 20 Ex point C: X 21 Y 20 Z 13 ESP 0F18h [ESP] 17 Ex point D: X 21 Y 20 Z 17 ESP 0F1Ch [ESP] 42
Given an even-parity system which checks parity 16 bits at a time, the following data would be flagged as having an error. 1001 1011 0110 1000
FALSE
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 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.
A subprocedure's stack frame contains the return address and its local variables.
True
An argument passed by reference consists of a memory address offset.
True
An input parameter may be passed by reference.
True
Arrays are passed by reference to avoid copying each element into the stack/registers.
True
Initialized State X 17 Y 20 Z 13 ESP 0F1Ch [ESP] 42 Trace the following code fragment and update the register and memory contents: PUSH X PUSH Y POP X POP Y
X 20 Y 17 Z 13 ESP 0F1Ch [ESP] 42
There are several important uses of runtime stacks in programs (select all that apply): a)The stack makes a convenient temporary save area for registers when they are used for more than one purpose. b) When the CALL instruction executes, the stack is used to store the address where the called procedure will return to. c) When calling a subroutine, you pass input values called arguments by pushing them on the stack. d) The stack provides temporary storage for local variables.
a, b, c ,d (ALL)
Which of the following is true about the POP instruction? a) It copies the data pointed to by the stack pointer into the operand, and then decrements the stack pointer (by 2 or 4). b) It increments the stack pointer (by 2 or 4), and then copies the data pointed to by the stack pointer into the operand. c) It copies the data pointed to by the stack pointer into the operand, and then increments the stack pointer (by 2 or 4). d)It copies the data pointed to by the stack pointer into the operand, and then increments the stack pointer by 1.
c) It copies the data pointed to by the stack pointer into the operand, and then increments the stack pointer (by 2 or 4).
ESP always points to ______ a) the next, empty, location below the stack. b) the beginning of the stack when your program first began. c) the next, empty, location above the stack. d) the last value to be added to, or pushed on, the top of stack.
d) the last value to be added to, or pushed on, the top of stack.
Select the proper syntax for establishing a subprocedure.
procedureName PROC ;... ;... RET ;return to calling procedure procedureName 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
A value or reference received by a procedure.
Parameter
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)
Which parameter-passing method is commonly used by compilers?
Passing parameters on the stack.
00000000 main PROC ; ... Execution Point A 0000011C CALL doSomething 00000120 MOV result, EAX ; ... 0000023E exit 0000023F main ENDP 0000023F checkThings PROC ; ... 00000243 XOR BX, 0A00h ; Execution Point B ; ... 00000274 RET 00000275 checkThings ENDP 00000275 doSomething PROC ; ... 000002A0 CALL checkThings 000002A5 MOV EAX, EDX ; ... 000002F3 RET 000002F4 doSomething ENDP Assume there are no stack operations other than the shown CALL and RET instructions, and ESP = 00000900h at Execution Point A. At Execution Point B: What is the current value of the stack pointer (in 4 byte hex)? What is the value at the top of the stack (in 4 byte hex)?
What is the current value of the stack pointer (in 4 byte hex)? 8F8 What is the value at the top of the stack (in 4 byte hex)? 2A5