Week Two Flashcards
For compound conditions using AND, should each condition jump to a falseBlock or a trueBlock?
- check condition1 using CMP
- if condition1 is false, jump to falseBlock
- check condition2 using CMP
- if condition2 is false, jump to falseBlock
- code for TRUE block
- jump to endBlock
- falseBlock:
- code for FALSE block
- endBlock
For compound conditions using OR, should each condition jump to a falseBlock or a trueBlock?
- check condition1 using CMP
- if condition1 is true, jump to trueBlock
- check condition2 using CMP
- if condition2 is true, jump to trueBlock
- code for FALSE block
- jump to endBlock
- trueBlock:
- code for TRUE block
- endBlock
For an if statement, where should the condition jump to?
- check condition using CMP
- if condition is false, jump to end
- code for TRUE block
- end:
For an if - else statement, should the condition jump to a falseBlock or a trueBlock?
Method One • check condition using CMP • if condition is false, jump to falseBlock • code for TRUE block • jump to end • falseBlock: • code for FALSE block • end:
Method Two • check condition using CMP • if condition is true, jump to trueBlock • code for FALSE block • jump to end • trueBlock: • code for TRUE block • end:
For an if - else: if - else statement, should the condition jump to a falseBlock or a trueBlock?
- check condition1 using CMP
- if condition1 is true, jump to trueBlock1
- check condition2 using CMP
- if condition2 is true, jump to trueBlock2
- code for FALSE block
- jump to endBlock
- trueBlock1:
- code for TRUE block1
- jump to endBlock
- trueBlock2:
- code for TRUE block2
- endBlock:
J(conditional) instructions: JE JL JG JLE JGE JNE
• JE jump if destination = source • JL jump if destination < source • JG jump if destination > source • JLE jump if destination <= source • JGE jump if destination >= source • JNE jump if destination not = source • NOTE: These conditions are for signed integers – OK to compare negative to non-negative, etc.
What does the PUSH instruction do?
The PUSH instruction first decrements ESP and then copies a source operand into the stack. A 16-bit operand causes ESP to be decremented by 2. A 32-bit operand causes ESP to be decremented by 4.
What does the POP instruction do?
The POP instruction first copies the contents of the stack element pointed to by ESP into a 16- or 32-bit destination operand and then increments ESP. If the operand is 16 bits, ESP is incremented by 2; if the operand is 32 bits, ESP is incremented by 4.
Define a MASM constant for your name as a z-byte terminated string.
MY_NAME EQU
What is the size of the string in the following MASM data segment declaration?
.data
stones BYTE ”You Can’t Always Get What You Want.”, 10, 13, 0
35 for the text + 1 for each number following = 38
What is the purpose of a breakpoint during a program debugging session?
It pauses execution, so the programmer can view the contents of memory, registers, etc.
Which function key is used to execute a library procedure, without going into the details of the
procedure?
F ______
F10: step over
When execution is paused at a breakpoint, which function key is used to continue execution to the next breakpoint (or to the end of the program if no more breakpoints exist)? F \_\_\_\_\_\_
F5: continue
The MASM assembler is used for locating __________ errors, but the debugging system is used for
locating _________ errors.
a. syntax
b. logic, run-time, or execution
What is a pre-test loop?
A while loop. Comparison is made before each iteration.
; initialize accumulator mov eax, x dblLoop: ; Double x while x <= 1000 cmp eax, 1000 jg endLoop ; if condition false, jump to end add eax, eax jmp dblLoop
endLoop:
mov x, eax
What is a post-test loop?
A do-while or repeat until loop. Comparison is made after each iteration.
; initialize accumulator mov eax, x dblLoop: ; Double x while x <= 1000 add eax, eax cmp eax, 1000 jle dblLoop ; If condition true, jump top mov x, eax
What is a counted loop?
A for loop.
; initialize accumulator, first number, and loop control
mov eax, 0
mov ecx, 10
sumLoop: ; add integers from 10 to 1
add eax, ecx
loop sumLoop ; subtract 1 from ecx, if ecx ≠ 0,
; go to sumLoop
; Print result
call WriteDec ; displays 55
How do you convert hex to:
a. signed binary
b. signed decimal
c. unsigned binary
d. unsigned decimal
a. Simply convert to binary
b. Find the two’s complement of hex number and then convert to decimal, placing a negative sign in front of the decimal number
c. Simply convert to binary
d. Simply convert to decimal
How do you convert decimal to:
a. signed binary
b. signed hex
a. Convert the positive integer to binary. Then find the two’s complement by flipping the bits and adding one.
b. Either find the hex equivalent of the binary two’s complement, or convert the positive integer to binary. Then find the two’s complement by subtracting each hex digit from 15 and adding one.
How do you convert decimal to:
a. unsigned binary
b. unsigned hex
a. Divide the number by 2 and turn the remainders into binary from bottom to top. Decimal 28 to binary: 28/2 = 14 R 0 14/2 = 7 R 0 7/2 = 3 R 1 3/2 = 1 R 1 1/2 = 0 R 1 Binary = 0001 1100
b. Convert to binary, then convert each nibble to a hex digit.
The following data segment starts at memory address 0x3000 (hexadecimal) 0 .data 1 printString BYTE "Assembly is fun",0 2 moreBytes BYTE 19 DUP(0) 3 dateIssued DWORD ? 4 dueDate DWORD ? 5 elapsedTime WORD ?
What is the hexadecimal address of dueDate?
Line 1 = 0x3000 + 16d = 0x3010
Line 2 = 0x3010 + 19d = 0x3023
Line 3 = 0x3023 + 4d = 0x3027
Thus line 4’s hexadecimal address starts at 0x3027
The following data segment starts at memory address 0x2300 (hexadecimal)
.data
printString BYTE “Do not add decimal to hex”,0
someBytes WORD 42 DUP(0)
moreBytes BYTE 10, 20, 30, 40, 50, 60, 70, 80, 90
questionAddr DWORD ?
ignoreMe WORD ?
What is the hexadecimal address of questionAddr?
Line 1 = 0x2300 + 26d = 0x231A
Line 2 = 0x231A + 2*42 = 0x236E
Line 3 = 0x236E + 9 = 0x2377
Thus line 4’s hexadecimal address starts at 0x2377
After the following MASM code is executed: mov eax,57 mov ebx,50 mov ecx,50 add eax,ebx sub eax,ecx
What is the value in the eax register (in decimal)?
What is the value in the ebx register (in decimal)?
What is the value in the ecx register (in decimal)?
a. 57
b. 50
c. 50
After the following MASM code is executed: mov eax,111 mov ebx,11 mov edx,0 div ebx
What is the value in the eax register (in decimal)?
What is the value in the ebx register (in decimal)?
What is the value in the edx register (in decimal)?
a. 10
b. 11
c. 1