Module 8
What is the (string) result of adding the following digit strings, character by character? a BYTE "2458",0 b BYTE "6301",0
"hgei",0 '2' + '6' = 50 + 54 = 104 = 'h' '4' + '3' = 52 + 51 = 103 = 'g' '5' + '0' = 53 + 48 = 101 = 'e' '8' + '1' = 56 + 49 = 105 = 'i'
Suppose that a program's data and executable code require 1,024 bytes of memory. A new section of code must be added; it will be used with various values 39 times during the execution of a program. When implemented as a macro, the macro code requires 89 bytes of memory. When implemented as a procedure, the procedure code requires 115 bytes (including parameter-passing, etc.), and each procedure call requires 13 bytes. How many bytes of memory will the entire program require if the new code is added as a procedure?
1646
For string primitives, which register is the 32-bit accumulator?
EAX
Which of the following string primitives will modify the ESI register? Check all that apply. MOVSB LODSB SCASB STOSB CMPSB
MOVSB LODSB CMPSD
Which structure is the following true for? _________ have a calling mechanism involving the EIP.
Procedures
STOSW will write how many bytes to memory?
2 BYTES
Which structure is the following true for? _________ have a return mechanism involving the system stack.
Procedures
Suppose that a program's data and executable code require 2048 bytes of memory. A new section of code must be added which will be used in a loop which repeats 50 times. When implemented as a macro, the macro code requires 48 bytes of memory per expansion. When implemented as a procedure, the procedure code requires 128 bytes of memory (including parameter-passing, etc.), and each procedure call requires 5 bytes of overhead. How many bytes of memory will the entire program require if the new code is added as a macro?
2096 Bytes 2048 (Program before adding code) + 1*48 (48 bytes per expansion, 1 expansion inside loop) = 2096 bytes
Primitives will increment by the size (in bytes) of the TYPE Used to move "forward" through an array
CLD - Clear direction flag
If the string direction flag is not set, string operations will move backward through the string.
False
The REPNE prefix checks the value of the Zero flag but requires its operand-instruction (the instruction which follows it) to modify the flag.
True
Suppose that a program's data and executable code require 1,024 bytes of memory. A new section of code must be added; it will be used with various values 57 times during the execution of a program. When implemented as a macro, the macro code requires 97 bytes of memory. When implemented as a procedure, the procedure code requires 148 bytes (including parameter-passing, etc.), and each procedure call requires 6 bytes. How many bytes of memory will the entire program require if the new code is added as a procedure?
1514
Suppose that a program's data and executable code require 2048 bytes of memory. A new section of code must be added which will be used (with various values) 30 times during the execution of a program. When implemented as a macro, the macro code requires 48 bytes of memory per expansion. When implemented as a procedure, the procedure code requires 128 bytes of memory (including parameter-passing, etc.), and each procedure call requires 5 bytes of overhead. How many bytes of memory will the entire program require if the new code is added as a procedure?
2326 Bytes 2048 (Program before adding code) + 128 (procedure code) + 30*5 (5 bytes per call, 30 calls) = 2326 bytes
Suppose that a program's data and executable code require 2048 bytes of memory. A new section of code must be added which will be used in a loop which repeats 50 times. When implemented as a macro, the macro code requires 48 bytes of memory per expansion. When implemented as a procedure, the procedure code requires 128 bytes of memory (including parameter-passing, etc.), and each procedure call requires 5 bytes of overhead. How many bytes of memory will the entire program require if the new code is added as a procedure?
2426 Bytes 2048 (Program before adding code) + 128 (procedure code) + 50*5 (5 bytes per call, 1 call per loop, 50 loop iterations) = 2426 bytes
Suppose that a program's data and executable code require 2048 bytes of memory. A new section of code must be added which will be used (with various values) 30 times during the execution of a program. When implemented as a macro, the macro code requires 48 bytes of memory per expansion. When implemented as a procedure, the procedure code requires 128 bytes of memory (including parameter-passing, etc.), and each procedure call requires 5 bytes of overhead. How many bytes of memory will the entire program require if the new code is added as a macro?
3488 Bytes 2048 (Program before adding code) + 30*48 (48 bytes per expansion, 30 expansions) = 3488 bytes
Suppose that a program's data and executable code require 1,024 bytes of memory. A new section of code must be added; it will be used with various values 35 times during the execution of a program. When implemented as a macro, the macro code requires 78 bytes of memory. When implemented as a procedure, the procedure code requires 167 bytes (including parameter-passing, etc.), and each procedure call requires 11 bytes. How many bytes of memory will the entire program require if the new code is added as a macro?
3754
Suppose that a program's data and executable code require 1,024 bytes of memory. A new section of code must be added; it will be used with various values 42 times during the execution of a program. When implemented as a macro, the macro code requires 109 bytes of memory. When implemented as a procedure, the procedure code requires 142 bytes (including parameter-passing, etc.), and each procedure call requires 12 bytes. How many bytes of memory will the entire program require if the new code is added as a macro?
5602
Inside a loop which executes 1000 times, is it better to use a macro or a procedure? Why?
A macro is better. The code in the loop is only expanded once, but is executed many times. This means that there will only be one macro expansion. However, if a procedure is used, then all the overhead from a procedure call (building the stack frame, changing the instruction pointer, etc...) will occur 1000 times causing execution delay.
For string primitives, which register is the 8-bit accumulator?
AL
For string primitives, which register is the 16-bit accumulator?
AX
Which of the following string primitives will compare the BYTEs stored in the memory locations pointed to by EDI and ESI? SCASB STOSB MOVSB CMPSB LODSB
CMPSB
What is the implied index for the STOSB instruction?
EDI
What is the implied index for the LODSB instruction?
ESI
The REP prefix checks the value of ECX but will not modify it.
False
The REP prefixes may be used with most instructions (MOV, CMP, ADD, etc...).
False
When a macro is invoked, the assembler handles the insertion of CALL and RET instructions.
False CALL and RET are specific to procedures, not macros.
(True/False) If a procedure uses the LOCAL directive, the procedure doesn't need a RET statement.
False While the setup and takedown of the activation record is handled by the LOCAL directive, the return statement is not. The programmer must still write the return statement and account for any passed parameters.
Given the following partial data segment and program, what is displayed to the console? NOTE: WriteChar displays the character in the AL register. .data pal BYTE "I prefer pi.",0 .code main PROC MOV ESI, OFFSET pal MOV ECX, LENGTHOF pal SUB ECX, 2 CLD _loopIn: LODSB CALL WriteChar LOOP _loopIn MOV ECX, LENGTHOF pal SUB ECX, 1 STD _loopOut: LODSB CALL WriteChar LOOP _loopOut CLD exit main ENDP
I prefer pi.ip referp I
Which of the following string primitives will copy a BYTE from the memory location pointed to by ESI to the AL register? MOVSB LODSB SCASB STOSB CMPSB
LODSB
Which structure is the following true for? For _________, arguments are substituted exactly as entered, without checking for memory, registers, or literals.
Macros
Which structure is the following true for? For _________, the entire code is substituted for each call.
Macros
Which structure is the following true for? _________ may have LOCAL labels.
Macros and Procedures
In a procedure using the LOCAL directive, where are the local variables created?
On the runtime stack, immediately above the old EBP value.
Which structure is the following true for? _________ are translated only once, and can be called many times.
Procedures
Which of the following would be appropriate to scan through one string, stopping when a character in AL is successfully matched to a character in the string? Assume AL, ECX, ESI, and EDI have already been set appropriately (if necessary). REPNE CMPSB REPE CMPSB REPE SCASB REPNE SCASB
REPNE SCASB
Which of the following string primitives will compare the BYTE stored in the memory locations pointed to by EDI to the contents of the AL register? MOVSB LODSB SCASB STOSB CMPSB
SCASB
Which of the following string primitives will modify the EDI register? Check all that apply. SCASB STOSB MOVSB CMPSB LODSB
SCASB STOSB MOVSB CMPSB
Primitives will decrement by the size (in bytes) of the TYPE Used to move "backward" through an array
STD - Set direction flag
Which of the following string primitives will copy a BYTE from the AL register to the memory location pointed to by EDI? MOVSB LODSB SCASB STOSB CMPSB
STOSB
SquareCalc MACRO x, outAddr PUSH EAX PUSH EBX ; save registers PUSH EDI MOV EAX,x MOV EBX,EAX MUL EBX ; x * x in eax DEC EAX ; x * x - 1 in eax MOV EDI,outAddr MOV [EDI],EAX ; save eax in memory address (edi) POP EDI POP EBX ; restore registers POP EAX ENDM Invoke the macro with value 68 and store the result in result.
SquareCalc 68,OFFSET result
What mechanism allows a macro with labels to be used multiple times in a program?
The LOCAL directive.
What mechanism is responsible for implementing inline expansion?
The MASM preprocessor.