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
What are the Instruction Execution steps?
Step 1-6
Step 1: The control unit fetches the next instruction from the instruction queue.
Step 2: The control unit increments the instruction pointer.
Step 3: The control unit decodes the instruction’s function to determine what the function will do.
Step 4: If the instruction uses an input operand located in memory, the control unit uses a read operation to retrieve the operand. Sometimes this involves address calculations.
Step 5: the ALU executes the instruction, using the named registers and internal registers as operands. It also updates a few status flags.
Step 6: If the output operand is in memory, the control unit uses a write operation to store the data.
What is the pseudo-code that corresponds to the following assembly code.
.data a DWORD ? b DWORD ? c BYTE ? d BYTE ?
.code main PROC mov eax, 1 cmp AH, c jg option1 jmp option3 option1: mov edx, OFFSET yes call WriteString jmp endOfProgram option2: mov edx, OFFSET no call WriteString jmp endOfProgram option3: mov edx, OFFSET maybe call WriteString endOfProgram: exit main ENDP END main
if (c < 0)
print (yes);
else
print (maybe);
What is the pseudo-code that corresponds to the following assembly code.
.data a DWORD ? b DWORD ? c BYTE ? d BYTE ?
.code main PROC mov eax, 0 mov ebx, a startLoop: cmp eax, ebx jge endOfProgram mov edx, OFFSET no call WriteString inc eax jmp startLoop mov edx, OFFSET maybe call WriteString endOfProgram: exit main ENDP END main
for (k = 0; k < a; k++)
print (no);
The MOVZX instruction is only used with unsigned integers.
True
The MOVSX instruction is only used with unsigned integers.
False
What does the CARRY flag do?
Indicates unsigned integer overflow.
What does the OVERFLOW flag do?
Indicates the result of a signed arithmetic operation is too large or too small to fit into the destination.
What does the ZERO flag do?
Indicates that an operation produced zero.
What does the SIGN flag do?
Indicates that an operation produced a negative result.
What does the PARITY flag do?
Indicates whether or not an even number of 1 bits occurs in the least significant byte of the destination operand.
What does the AUXILIARY CARRY flag do?
The Auxiliary flag is set (to 1) if during an “add” operation there is a carry from the low nibble (lowest four bits) to the high nibble (upper four bits), or a borrow from the high nibble to the low nibble, in the low-order 8-bit portion, during a subtraction.
The MOVSX instruction sign-extends an integer into a larger operand.
True
What code best implements the following expression. Do not permit dword1, ECX, or EDX to be modified:
eax = -dword1 + (edx - ecx) + 1
mov eax,dword1 neg eax mov ebx,edx sub ebx,ecx add eax,ebx inc eax
The following instructions will set:
a. the Carry flag
b. the Sign flag
mov al,0FEh
sub al,2
a. False
b. True
If the LOOP instruction sets ECX to zero, a jump to the destination label will take place.
False
Which of the following affect the Carry flag?
inc
dec
neg
Neg only
What will be the value of EAX when the following sequence of instructions has executed?
push 5
push 10
push 20
pop eax
20
Which library procedure sets the Zero flag if the AL register contains the ASCII code for a decimal digit (0–9)?
IsDigit
Which library procedure locates the cursor at a specific row and column on the screen?
Gotoxy
Which I/O device is used for standard input?
Keyboard
What does the PUSH instruction do?
It decrements the stack pointer (by 2 or 4) and copies the operand into the stack at the location pointed to by the stack pointer.
Which CALL instruction writes the contents of EAX to standard output as a signed decimal integer?
WriteInt
Which library procedure displays the CPU flags and 32-bit registers?
DumpRegs
The linker combines object files into an executable file.
True
By default, labels are visible only within the procedure in which they are declared.
True
Which of the following code sequences assigns the value 0x10 to EBX? (select all that are correct) a. mov edx,20h push edx mov ecx,10h push ecx pop ebx pop edx
b. mov ecx,10h mov edx,20h push ecx push edx pop ebx pop edx
c. mov edx,20h push edx mov ecx,10h push ecx pop ebx pop edx
d. push 20h mov ecx,10h push ecx pop eax pop ebx
A and C
The instructions used to manipulate the ESP regieter are?
CALL, PUSH, POP, RET
Mechanically speaking, the CALL instruction pushes its return address on the stack and copies the called procedure’s address into the
instruction pointer.
True
Adding 5 to 0FBh in an 8-bit register sets the Zero flag.
True
What are the valid uses of the XCHG instruction?
XCHG mem,reg
XCHG reg,reg
XCHG reg,mem
Adding 0FFh and 05h in an 8-bit register sets the Overflow flag.
False
The ________ procedure advances the cursor to the beginning of the next line in the console window.
Crlf
The USES operator, coupled with the PROC directive, lets you list the names of all registers modified within a procedure.
True
ESP always points to the ______
last value to be added to, or pushed on, the top of stack.
Which register contains an integer before calling WriteDec?
EAX
Which library procedure writes an unsigned 32-bit integer to standard output in hexadecimal format?
WriteHex
Which library procedure reads a 32-bit signed decimal integer from standard input?
ReadInt