Final Review Questions Flashcards
For the following segment, what is SIZEOF myChecker (in decimal - ignore the .0000 from Canvas)
.data myChecker BYTE 12h BYTE 34h BYTE 56h BYTE 78h BYTE 90h
1 byte.
The _________ operator returns a value that is equivalent to multiplying the number of elements in a single data declaration by the size, in bytes, of a single element of a data declaration.
SIZEOF
The _________ operator overrides the default type of a label (variable), and can also be used to combine elements of a smaller data type and move them into a larger operand.
PTR
What do these do?
- lodsb
- stosb
- cld
- std
lodsb: load string byte
stosb: store string byte
cld: clear direction flag
std: set direction flag
True or False? If the string direction flag is not set, string operations will move backward through the string.
False. It only moves backwards when the direction flag is set.
Suppose that you are given the following partial data segment, which starts at address offset 0x1000 :
.data
idArray WORD 3546, 1534, 12, 3481, 154, 6423
x DWORD LENGTHOF idArray
y DWORD SIZEOF idArray
z DWORD TYPE idArray
x contains what value, in decimal?
y contains what value, in decimal?
Y contains 6. There are 6 elements in the array, so it has the lengthof 6.
X contains 12, or the LENGTHOF the array * its TYPE size.
Suppose that you are given the following partial data segment: .data myPtrCheck BYTE 12h, 34h, 56h, 78h, 90h, ABh, CDh, EFh .code ... mov eax, DWORD PTR [myPtrCheck+2]
EAX contains what value, in hexadecimal?
AB907856h
It starts with 2 bytes beyond the first element of the array (on the third element).
Although strings generally are stored sequentially, once it is stored as a single DWORD using PTR, then it becomes in reverse order.
Assume that your program has access to the following data segment (starting at address 0x310):
.data
id DWORD 7
matrix WORD 50 DUP(10 DUP(?))
What is the hexadecimal address of matrix[7][3] (the 4th element of the 8th row)?
3A6.
This is a 50 x 10 matrix, with each row taking 210 bytes. Therefore, to figure out the address of the 8th row, add 7210 = 140. Next, we add 32 = 6, which will make 146 on top of the original address.
Since the data segment starts at 310h, and we add 4 for the DWORD and 146 for the matrix navigation, we end up with 3A6.
How would you write this as a postfix expression?
56 / (42 * 2.6 * 2) + (256 / (128 - 64)) * 3 ^ 12
56 42 2.6 * 2 * / 256 128 64 - / 3 12 ^ * +
How would this postfix expression look when represented as infix?
3 3 * 5 4 2 * / -
3 * 3 - 5 / (4 * 2)
What FPU manipulations corresponds to the given infix notation?
Z = (A+B-C)/D*E
finit fld A fld B fadd fld C fsub fld D fdiv fld E fmul fstp Z
How do you generate random numbers?
First, call Randomize just once (e.g. main). Whenever you call RandomRange (N>0 in eax), it’ll return random number between 0 and N-1. Therefore, you need to find the range (hi-lo + 1), put that range in eax, and add that to the minimum.
;generate and display random integer n mov eax, N_MAX sub eax, N_MIN inc eax call RandomRange add eax, N_MIN mov esi, [ebp+12] mov [esi], eax call WriteDec call CrLF
What specifically is indexed addressing?
Indexed addressing: Used for global array references, array name with subscript [distance] Mov edi, 0 Mov list[edi], eax Add edi, 4 Mov list[edi], ebx
What specifically is register indexed addressing?
Register indirect addressing: Get the address of list into esi, and then use [esi]. Mov esi, [ebp+8] Mov eax, [esi] Add esi, 4 mov eax, [esi]
What specifically is base-indexed addressing?
Base-indexed addressing: Starting address in one register, offset in another, and add and access memory (used for referencing array elements in procedures). Mov edx, [ebp+8] Mov ecx, 20 Mov eax, [edx+ecx] Mov ebx, 4 Add eax, [edx+ebx] Mov [edx+ecx], eax
Given the following register states, and using Indexed Addressing, which of the following lines of code will move the 11th element of the list array (of DWORDs) to the EAX register?
EDX register contans the address of the first element of list.
ESI register contains the address of the eleventh element of list.
EBX register contains the value 40,
mov eax, list[ebx]
In indexed addressing, you use the list and a subscript of the index distance you want. Because you want to add 10*4 to the original address, you want list[40].
Given the following register states, and using Register Indirect Addressing, which of the following lines of code will move the 11th element of the list array (of DWORDs) to the EAX register?
EDX register contans the address of the first element of list.
ESI register contains the address of the eleventh element of list.
EBX register contains the value 40,
mov eax, [esi]
When you use register indirect addressing, you store the address of the element you want directly in a register, and then dereference that register to access the value.
Given list, an array of WORDs, what element is addressed by list[8]?
Hint: It’s Love.
5th element.
Given the following register states, and using Base Indexed Addressing, which of the following lines of code will move the 11th element of the list array (of DWORDs) to the EAX register?
EDX register contans the address of the first element of list.
ESI register contains the address of the eleventh element of list.
EBX register contains the value 40,
mov eax, [edx + ebx]
In base indexed addressing, there are two registers keeping track of two things: (1) the base address of the array and (2) the distance in bytes from the first element.
Here, edx contains the addrss of the first element of the list, and ebx contain 40, the distance offset in bytes of the 11th element.
The following instruction will increment the stack pointer (ESP) by how many bytes?
ret 16
20 bytes. By default, it’ll also get rid of the return address (as a DWORD) when it goes back there.
What would the stack look like (and at what distance from the ebp is everything)?
.data
x DWORD 153461
y WORD 37
z WORD 90
.code main PROC push x push y push z call someProcedure ... exit main ENDP
someProcedure PROC
push ebp
mov ebp, esp
[ebp] - ebp [ebp+4] - @ret [ebp+8] - z - 90 [ebp+10] - y - 37 [ebp+12] - x - 153461
In essence, the distance from the top of the stack depends on the value closer to the stack (since it had decremented to get to that point). Therefore, 90 is at [ebp+8] even though it’s only a WORD because the stack pointer decremented down to [ebp+4] to accommodate the DWORD return address.
Suppose that you are given the following program (with memory addresses shown on the left).
What hexadecimal value does EIP hold immediately after “inc EAX” has executed?
.data
0x100 x DWORD 153461
0x104 y BYTE 37
0x105 z BYTE 90
.code main PROC 0x12 push x 0x17 mov AH, y 0x1C mov AL, z 0x21 call someProcedure 0x26 inc EAX 0x2B mov EBX, z 0x30 xor EAX, EBX 0x35 exit main ENDP END MAIN
It should be 2B, the address of the very next instruction.
Given the following partial data segment, what value would I put in the brackets in list[n] to access the 5th element of list? (Ignore the .0000 that Canvas may append to your answer).
.MAX = 50 .data list DWORD MAX DUP(0) a DWORD 25 b DWORD 15
- Again, you’d want to add 4*4 = 16.
For this problem, suppose that you are working with the partial data segment given below. Assume that the memory address of balance is 0x44. What hexadecimal address belongs to the last item in history?
HISTLIMIT = 100
.data balance DWORD 0 account WORD ? history WORD HISTLIMIT DUP(?) isValid BYTE 0
110h.
44h starts at decimal 68, and the first item in history will start 4+2 later, or at 74. The last item in history will be 99*2 more than that, which is 110h.
Suppose that you are given the following MASM data segment declarations: .data idNumber BYTE ? status WORD 0 list DWORD 42 DUP(?) count DWORD ?
The address of idNumber is 0x4E00.
What is the hexadecimal address of the 14th element of list? What is the hexadecimal address of count?
First, the starting address is 0x4E00, or 19968. Then, you add 1+2, or a starting address of 19971.
list: 0x4E37. To find the 14th element, just add 134 = 20023, or 4E37h.
count: 0x4EAB. To find count, add all 42 elements, 424 = 0x4EAB.
Assume that LO and HI have already been assigned as constants with LO
First, you can simply subtract directly to find HI-LO+1, and then add LO. mov eax,HI sub eax,LO inc eax call RandomRange add eax,LO mov x, eax
Second, you can decrement LO, so that when you subtract it, you're actually getting HI-(LO-1), or HI-LO+1. mov eax,HI mov ebx,LO dec ebx sub eax,ebx call RandomRange add eax,LO mov x, eax
main PROC push OFFSET result push x call factorial main ENDP
factorial PROC push ebp mov ebp, esp mov eax, 1 mov ecx, *****A****** again: mul ecx loop again mov edi, ******B***** mov ******C*****, eax pop ebp ret *****D***** factorial ENDP
A: {ebp+8]. Here, you want to use the actual value of x (since you’re multiplying).
B: [ebp+12]. Here, you want to use the offset of result (b/c edi is normally for that).
C: [edi]. In order to actually save the value in the address of result, you need to use edi as a register index.
D: 8. Because you had pushed only two DWORDs, you only need to get rid of 2*4 = 8.
What hexadecimal number will ESP contain when the “mov eax,1” instruction is executed? The initial address at the top of the stack is 0x0A50.
main PROC push OFFSET result push x call factorial main ENDP
factorial PROC
push ebp
mov ebp, esp
mov eax, 1
Generally, you decrement every time you push something onto the stack. Therefore, since you’ve pushed 4 things onto the stack, you should add 4*4 = 12 to get to the original stack address (including ebp).
Therefore, subtract 16 from 0A50h, and you’ll get 0A40.