Midterm Test Notes
Run until next Breakpoint
"Debug"->"Continue" or just click "Continue" F5
Remove all Breakpoints
"Debug"->"Delete all Breakpoints" Ctrl+Shift-F9
Complete the following unsigned Binary Subtractoin: 11100001 -10111111
0010 0010
Convert the following ASCII hex representation to a character string: 41 73 73 65 6D 62 6C 79
Assembly
Which register is known as a loop counter?
ECX
What storage unit is the closest/fastest on the chip?
Registers
Select the pseudo-code that corresponds to the following assembly code. .data ; General purpose variables a SDWORD ? b SDWORD ? c SBYTE ? d SBYTE ? upperLevel SDWORD 18 lowerLevel SDWORD 3 ; Strings yes BYTE "Yes",0 no BYTE "No",0 maybe BYTE "Maybe",0 .code main PROC MOV EAX , 0 CMP EAX, lowerLevel JNE option1 JMP option2 option1: MOV EDX, OFFSET yes CALL WriteString JMP endOfProgram option2: MOV EDX, OFFSET no CALL WriteString JMP endOfProgram option3: MOV EDX, OFFSET maybe CA
print(yes)
The two's complement of a binary value is formed by which process?
reversing (inverting) the bits and adding 1
In debugging mode, which of the following (when typed into the memory window's address bar) will directly jump to the first memory address of variable userName? userName &userName [userName] %userName
&userName
What does this do? END
(1) marks end of module (for this class, the module is the program) (2) can optionally set program entry point (the procedure to start executing first, e.g. main) (3) with no operands, execution starts on the first byte of the generated executable file
What will a Post-test loop do?
(Do-While) loop will execute one-or-more times. The control condition must therefore be checked immediately after the first execution of the loop body. As long as the control condition is true after the loop body is executed, a jump to the top of the loop body is made.
What will a Pre-test loop do and how do you control it?
(While loop) Will execute zero-or-more times. The control condition must therefore be checked before the first execution of the loop body.
What is the range of decimal values for a signed BYTE?
-128 to 127
This directive is used to mark the beginning of the code segment in memory.
.code
Write the syntax to set the size of the runtime stack to 2048 bytes.
.stack 2048
What is the range of decimal values for an unsigned DWORD?
0 to 4,294,967,295
Complete the following unsigned Binary Subtraction: 01110000 - 01101110 ----------
0000 0010
Which of the following binary values is equivalent to hexadecimal 4A2B?
0100 1010 0010 1011
What is the binary calue that is equivalent to hexadecimal 7CBE?
0111 1100 1011 1110
A _________________ Architecture's instructions are decoded to micro-programs which are executed by the CPU, whereas a _____________Architecture's instructions are directly executed by the CPU. Choose between CISC and RISC
1.) CISC 2. RISC
Language Hierarchy: Rank the following languages from low level (1) to high level (4).
1.) English 2.) Python 3.) ARM Assembly 4.) Machine Code
Please place the following steps of the instruction execution cycle in their proper order.
1.) Fetch the instructions at the address in the Instruction Pointer into the Instruction Register. 2.) Increment the Instruction Pointer to point to the next instruction. 3.) Decode the instruction in the Instruction Register 4.) If the instruction requires memory access, determine the memory address, and fetch the operand from memory into a CPU register, or send the operand from a CPU register to memory. 5.)Execute the instruction 6.)If the output operand is in memory, the control unit uses the write operation to store the data.
After the following MASM code is executed: MOV EAX, 212 MOV EBX, 19 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)?
11 19 3
Complete the following Unsigned Binary Addition (answers should also be in Binary): 10111010 +00100001
1101 1011
Convert the following value from signed decimal to 8-bit binary: -33
1101 1111
Complete the following Unsigned Binary Addition 10111010 +00110001
1110 1011
Suppose that result is declared as DWORD, and the following MASM code is executed: MOV EAX, 23 MOV EBX, 14 MOV ECX, 6 _label5: ADD EAX, EBX ADD EBX, 2 LOOP _label5 MOV result, EAX
137
How many bits long is a WORD on x86 systems?
16
The following data segment starts at memory address 1600h (hexadecimal) .data printString BYTE "MASM is fun",0 moreBytes BYTE 17 DUP(0) dateIssued DWORD ? dueDate DWORD ? elapsedTime WORD ? What is the hexadecimal address of dueDate?
1621h
Complete the following unsigned Hexadecimal Subtraction: C6F1 -A735
1FBC
How much memory can be addressed in Real-address mode?
1MB
In the following data definition, assume that List2 begins at offset 2000h. What is the offset of the third value (5)? List2 WORD 3,4,5,6,7
2004h Not sure why, look up
The following data segment starts at memory address 2300h (hexadecimal) .data printString BYTE "Assembly is fun",0 moreBytes BYTE 48 DUP(0) dateIssued DWORD ? dueDate DWORD ? elapsedTime WORD ? What is the hexadecimal address of dueDate?
2344h
What is the largest signed integer that may be stored in 32 bits?
2^31 - 1
Convert the following signed SWORD to a decimal value. 0111 1001 1111 0110
31,222
How many bits long is a DWORD (doubleword) on x86 systems?
32
Match the registers to the correct size. Not all sizes may be used and some sizes may be used more than once. EAX AX AH
32 bits 16 bits 8 bits
Convert the following string into its ASCII hex representation: Architect
41 72 63 68 69 74 65 63 74
Complete the following unsigned Hexadecimal Subtraction: 6A6F - 1F89 ------
4AE6
Convert the following string into its ASCII hex representation: Turing
54 75 72 69 6E 67
Convert the following unsigned WORD to a decimal value. 1101 0111 0011 0010
55,090
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 decimal value in the EAX register? What is the decimal value in the EBX register? What is the decimal value in the ECX register?
57 50 50
Convert the following unsigned WORD to a decimal value. 1111 1010 0000 1111
64,015
How many bytes long is a SQWORD on x86 systems?
8
How many bytes long is a QUADWORD on x86 systems?
8 (with margin: 0)
Complete the following Unsigned Hexadecimal Addition (answers should also be in Hexadecimal): 2C06 +571B
8321
Complete the following Unsigned Hexadecimal Addition 2C28 + 572B ------
8353
View identifier/register value
Add Watch or hover cursor over identifier in code window
After the following instruction sequence, show the values of the Carry __________, Zero ________, and Sign __________ flags mov al, 6 cmp al,5
Answer 1: Correct! 0 Answer 2: Correct! 0 Answer 3: Correct! 0
What mechanism is used to turn Assembly Language code to Machine Code? compiler assembler linker editor detangler loader
Assembler
A bus is a set of parallel wires used to conduct a group of electrical signals simultaneously.
Bus
Write a code snippet to get an unsigned integer value from the user and store it in a DWORD identifier called counter.
CALL ReadDec MOV counter, EAX
Which flag is set when the result of an unsigned arithmetic operation is too large to fit into the destination?
Carry
Toggle breakpoint
Click in grey area left of a line of code F9
Name the four basic parts of an assembly language instruction.
Code label, instruction mnemonic, operand(s), comment
Which utility program reads an assembly language source file and produces an object file?
Compiler
Language Hierarchy: The purpose of a Compiler is to...
Convert High/Low level Program Code to Assembly/Machine Code
What does MOV do?
Copy data from one location to another
Select the answer choice that best implements the following expression. Do not permit dword1, ECX, or EDX to be modified: For reference, NEG EAX will replace the value in EAX with its two's complement (e.g. 14d becomes -14d, or -20d becomes 20d). eax = -dword1 + (edx - ecx) + 1
Correct! mov eax,dword1 neg eax mov ebx, edx sub ebx, ecx add eax, ebx inc eax
Which of the following identifiers are allowed in MASM? (Check all that apply) 2towers BB-8 This_one? end namBear_Pig1
Correct! BB-8 Correct! This_one? Correct! manBear_Pig1
What type of tool can convert ARM Assembly to x86 Assembly?
Cross Assembler
What is the name of the lowest 8 bits of the EDX register? DL not listed DH DX
DL
When transferring instructions and data between the Main Memory Unit and the CPU, they will be placed on the____________ Address Bus.
Data
How are data labels and code labels different?
Data labels exist in the data segment as variable offsets. Code labels are in the code segment, and are offsets for transfer of control instructions.
View identifier (variable) in memory
Debug "Memory" window, enter &varName in Address Bar
Please select the appropriate description of the LOOP instruction. Jump if ECX is zero Decrement ECX, then Jump if ECX is nonzero Decrement ECX, then Jump if ECX is zero Jump if ECX is nonzero
Decrement ECX, then Jump if ECX is nonzero
Which register should contain an unsigned integer before calling WriteDec? EDI EBX EDX ECX ESI EAX
EAX
The simplest way to implement counted loops in MASM is to use the implied counter register _______ and the _________ instruction.
ECX LOOP
What preconditions exist for WriteString?
EDX must hold an address offset pointing to a BYTE array, which is null-terminated.
The ____________ register holds the 32-bit address of the next instruction to be fed to the instruction execution cycle.
EIP
Which register contains the starting address of data when calling DumpMem?
ES!
To avoid major issues when using LOOP, you should:
Ensure ECX initializes to a value greater than 0. Initializing to zero or a negative value will create extremely long (seemingly infinite) loops. Don't directly modify ECX within the loop body. You may accidentally skip over 0 or alter the number of times the loop executes. For nested counting loops, save the value of ECX before overwriting it for the inner loop, and restore it after finishing the inner loop.
Which function key is used to execute a library procedure, without going into the details of the procedure?
F10
In debugging mode, what is the keyboard shortcut to continue execution to the next breakpoint (or to the end of the program if no more breakpoints exist)? F11 F5 F9 F10
F5
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)?
F5
(True/False) Assembly Languages are portable.
False
Code labels may only appear on lines with no instructions.(T/F)
False
Groups of bytes in memory can only be interpreted a single way.(T/F)
False
MASM will throw an error when assembling the following data segment: .data myChecker BYTE 12h BYTE 34h BYTE 56h BYTE 78h BYTE 90h True/False
False
The ASCII code values for alphabetic letters (e.g. 'a') are smaller than for decimal digits (e.g. '1'). True/False
False
(True/False): 4b is a valid binary integer literal .
False 4 is not a valid binary digit.
(True/False): Assembly language directives execute at runtime.
False Directives are used by the assembler prior to runtime.
(True/False) The MUL instruction is used to multiply signed integers.
False IMUL must be used for signed integer multiplication.
(True/False): B2h is a valid hexadecimal integer literal.
False Integer literals with non-numeric characters as the first character must be preceded by a 0. Correct format would be 0B2h.
(True/False) The MUL instruction must have an explicit destination operand.
False MUL has an implied destination operand (EDX:EAX for 32-bit inputs, DX:AX for 16-bit inputs, and AX for 8-bit inputs).
(True/False): A hexadecimal literal may be written as 0x3A in MASM.
False Proper notation would be 3Ah or 03Ah
(True/False): All instructions have operands.
False Some have none (e.g. STD) while others have one or more (e.g. MUL)
(True/False): String literals must be enclosed in double-quotes.
False String literals may be enclosed either in single- or double-quotes.
(True/False): A MASM program must have a procedure named "main".
False The 'main' procedure can have any valid identifier, as long as the END directive properly points the assembler to start execution at that identifier address.
(True/False) An immediate may be a destination operand.
False* Destination operands must be capable of receiving data. Immediates are literal values and cannot represent registers or memory locations as instruction operands. *Note one exception, the OUT instruction, may have an 8-bit immediate specify an output port.
View other memory segments (stack)
Find memory address and enter the hex value in debug "Memory" window Address bar
Enter Debugging Mode
First set a breakpoint, then "Debug"->"Start Debugging" or "Local Windows Debugger" F5
Which library procedure returns the number of milliseconds elapsed since midnight?
GetMseconds
What does a pre-test loop (while) look like?
Initialize loop control variable(s) _top: Check condition using CMP If condition is false, jump to _endWhile code for LOOP BODY (including loop control update) Unconditional jump to _top _endWhile:
An Assembly Language is defined by the . . .
Instruction Set Architecture (ISA)
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.
What does JC do?
Jump if carry flag set
What does JG do?
Jump if leftOp > rightOp (signed)
What does JA do?
Jump if leftOp > rightOp (unsigned)
What does JNZ do?
Jump if result is nonzero
What does JE do?
Jump if result is zero
What does JECXZ do?
Jump if the counter register is zero
_____________ is an interesting instruction, because it operates as a combination of two other instructions, but this limits its jump range.
LOOP
Given the following data segment and assuming the code segment is in a procedure, identify everything that is wrong, and explain why. 1 .data 2 x DWORD 12 3 y DWORD 13 4 z WORD 25 5 6 ;...in main... 7 MOV EBX, z 8 MOV z, 12 9 MOV y, x 10 MOV EBX, 12
Line 7 has a size mismatch. EBX is a 32-bit register and identifier 'z' is a 16-bit WORD. Line 9 has mem for both operands, and MOV mem, mem is not valid for the MOV instruction.
Write this for MASM for k in range(10,n+1): print (no)
MOV EAX, 10 _again: CMP EAX, n JG _endLoop MOV EDX, OFFSET no CALL WriteString INC EAX JMP _again _endLoop:
Write the instructions for MASM if (k < n): print (yes) else: print (no)
MOV EAX, k CMP EAX, n JL _true1 MOV EDX, OFFSET no CALL WriteString JMP _theEnd _true1: MOV EDX, OFFSET yes CALL WriteString _theEnd:
Write the instructions for MASM if (k < n): print (maybe) else: if (k > n): print (no) else: print (yes)
MOV EAX, k CMP EAX, n JL _true1 ;k < n, so we print maybe JG _true2 ;k > n, so we print no MOV EDX, OFFSET yes ;else, so we print yes CALL WriteString JMP _theEnd _true1: MOV EDX, OFFSET maybe CALL WriteString JMP _theEnd _true2: MOV EDX, OFFSET no CALL WriteString _theEnd:
Write this for MASM while (k < n): print (yes) k += 2
MOV EAX, k _again: CMP EAX, n JGE _done MOV EDX, OFFSET yes CALL WriteString ADD EAX, 2 JMP _again _done:
Write this for MASM while 1: print (maybe) k += 1 if (k >= n): break
MOV EAX, k _again: MOV EDX, OFFSET maybe CALL WriteString INC EAX CMP EAX, n JL _again
if ((x < y) and (y < z)): print (yes) else: print (no)
MOV EAX, x CMP EAX, y JGE _false1 ;x !< y, so print no MOV EBX, z CMP y, EBX ;y !< z, so print no JGE _false1 ;otherwise, print yes MOV EDX, OFFSET yes CALL WriteString JMP _theEnd _false1: MOV EDX, OFFSET no CALL WriteString _theEnd:
if ((x < y) or (x > z)): print (no) else: print (maybe)
MOV EAX, x CMP EAX, y JL _true1 ; x < y, so print no CMP EAX, z JG _true1 ; x > z, so print no MOV EDX, OFFSET maybe ; otherwise, print maybe CALL WriteString JMP _theEnd _true1: MOV EDX, OFFSET no CALL WriteString theEnd:
Write this for MASM for k in range(10,0,-1): print (k)
MOV ECX, 10 _again: MOV EAX, ECX CALL WriteDec CALL CrLf LOOP _again
Write a code snippet to print a software engineer-defined, null-terminated string named greeting to the console window.
MOV EDX, OFFSET greeting CALL WriteString
Which of the following is NOT a valid MOV operation? Table 4-1 might be helpful. (check any/all that apply) MOV reg,mem MOV mem,reg MOV imm,imm MOV mem,mem MOV reg,imm MOV imm,mem MOV reg,reg MOV mem,imm
MOV reg,mem MOV mem,reg Correct! MOV imm,imm Correct! MOV mem,mem MOV reg,imm Correct! MOV imm,mem MOV reg,reg MOV mem,imm
Given the following data declarations and code (within main), what is printed to the console window? .data yes BYTE "Yes",0 no BYTE "No",0 maybe BYTE "Maybe: ",0 .code MOV EAX, 20 CMP EAX, 10 JG _printMaybe _printNo: MOV EDX, OFFSET no JMP _finished _printYes: MOV EDX, OFFSET yes JMP _finished _printMaybe: MOV EDX, OFFSET maybe CALL WriteString CMP EAX, 15 JL _printYes JMP _printNo _finished: CALL WriteString
Maybe: no
Given the following data declarations and code (within main), what is printed to the console window? .data yes BYTE "Yes",0 no BYTE "No",0 .code MOV EAX, -10 CMP EAX, 4 JG _printYes MOV EDX, OFFSET no JMP _finished _printYes: MOV EDX, OFFSET yes _finished: CALL WriteString
No
Given the following data declarations and code (within main), what is printed to the console window? .data yes BYTE "Yes",0 no BYTE "No",0 .code MOV EAX, 10 CMP EAX, 0 JS _printYes MOV EDX, OFFSET no JMP _finished _printYes: MOV EDX, OFFSET yes _finished: CALL WriteString
No
Is this a Post-Test loop or a Pre-Test loop? while 1: x = x + x if (x > 1000): break ; initialize running total MOV EAX, x _dblLoop: ; Double x while x <= 1000 ADD EAX, EAX CMP EAX, 1000 JLE _dblLoop MOV x, EAX ; ...
Post_test loop
Is this a Post-Test loop or a Pre-Test loop? while (x <= 1000): x = x + x ; initialize accumulator MOV EAX, x _dblLoop: Double x while x <= 1000 CMP EAX, 1000 JG _endLoop ADD EAX, EAX JMP _dblLoop _endLoop: MOV x, EAX ; ...
Pre-test loop
What would you call an ordered list of organized instructions existing somewhere in memory, and associated with a data structure for storage of data?
Program
Which Operation Mode provides compatibility for legacy 8086 programs?
Real-Address mode
Operands my be any of the following: (select all that apply)
Register Name
Toggle Watch Decimal/Hex view
Right click in Watch window, toggle "Hexadecimal Display"
Add Watch value
Right click on variable/register in code->"Add Watch" Shift+F9
In the IA-32 architecture, which of the following are valid 16-bit register references? ESI SP AH CX SS BL
SP CX SS
What instruction will subtract the value in the source operand from that of the destination operand, and save the result in the destination operand?
SUB
Define Parity Flag
Set if the least-significant byte in the result contains an even number of 1 bits.
Define Carry Flag
Set when an unsigned arithmetic operation generates a carry (or borrow) out of the most significant bit of the result.
When is the Overflow Flag set?
Set when the result of a signed arithmetic operation is too large or too small to fit in the destination
Define Sign Flag
Set when the result of an arithmetic or logical operation generates a negative result
Define Zero Flag
Set when the result of an arithmetic or logical operation generates a result of zero
Given the following data segment, identify everything that is wrong, and explain why. x_value DWORD 5 7Eleven BYTE "My job!",0 NickName BYTE "My nickname is "Big Sal"",0 X_VALUE DWORD 500 Age ;user's age; DWORD ?
Since MASM is not case-sensitive, x_value and X_VALUE are the same variable. Variable names must be unique within their scope, which in this case is the entire module. (MASM will prompt a Symbol redefinition error). 7Eleven is an invalid variable name (can't start with a digit). For NickName, you may use enclosed double-quotes, but only if the outer quotes are single-quotes. Having double-quotes inside double-quotes will cause an error. For the Age identifier, the first semicolon makes all of the rest of the line into a comment.
What are these responsible for? DWORD, WORD, BYTE,...
Specify memory space to be allocated for 'variable' storage
Convert the following ASCII hex representation to a character string: 53 74 61 74 69 6F 6E 21
Station!
Step Into
Step to next instruction (will enter called procedures) F11
Step Over
Step to next instruction (will not enter called procedures) F10
Step Out
Step to the first instruction after the current procedure returns Shift + F11
What component's primary duty is synchronizing processes inside a computer?
System Clock
Fill in the blanks: The MASM assembler is used for locating ____ errors, but the debugging system is used for locating ____, ____, or ____ errors.
The MASM assembler is used for locating syntax errors, but the debugging system is used for locating logic, run-time, or execution errors.
What are identifiers?
They are like variable names, function names, and labels. These names are all replaced with their numeric memory locations or their constant value assignments
What are the data movement instructions and what do they do?
They copy data from one location to another. They are: MOV MOVSX LODSB XCHG PUSH
(True/False) In debugging mode, the contents of internal memory and registers can be viewed when a breakpoint is encountered.
True
(True/False) The ADD instruction must have an explicit destination operand.
True
(True/False): A code label is followed by a colon (:), but a data label does not end with a colon.
True
(True/False): An identifier cannot begin with a numeric digit.
True
(True/False): Assembly language directives can be written in any combination of uppercase and lowercase letters.
True
(True/False): END main is a directive that tells the operating system where to begin execution of the program
True
(True/False): MOV is an example of an instruction mnemonic.
True
A primary limitation on the speed of internal communication on a machine is the width of the internal bus. True/False
True
By default, code labels are visible only within the procedure in which they are assigned (created).(T/F)
True
The following is a valid data definition statement: str1 \ BYTE "This string is quite long!", 0 True or False
True
Which library procedure writes a single character to standard output?
WriteChar
Which Irvine Library procedure should be used to print negative integers?
WriteInt WriteDec would work for positive values, but negative values will be printed as large positive values.
When branching in MASM, you will normally jump to ___________ . instruction pointer (EIP) a stack label (representing an address in the stack segment) a data label (representing an address in the data segment) a code label (representing an address in the code segment)
a code label (representing an address in the code segment)
Integer Literal Expressions are evaluated to integer literals at _____________ -time.
assembly
In debugging mode, a breakpoint is a point in the program where execution will be paused.
breakpoint
What does this do? INVOKE
calls a procedure at address given by the expression, passing comma-delimited arguments on the stack or registers
A program is considered portable if it . . .
can be executed on multiple platforms.
In order to implement either conditional or unconditional branching, you have to define a _____________.
code label. code labels are identifiers representing an address in the code segment, and are defined by writing the identifier and then a colon.
What does this do? ENDM
define the end of a macro
What does this do? ENDP
define the end of a procedure
What does this do? PROC
define the start of a procedure(procedures are much like functions - more on this later)
What does INCLUDE do?
insert the source code from specified file into current source during assembly
What does .code do?
marks the beginning of code segment
What does .data do?
marks the beginning of data segment
Unconditional branching means...
means jumping to another location in the program without checking any conditions.
Conditional branching means ...
means that we either branch or don't branch depending on the outcome of a logical condition.
Given the following data segment, and assuming it starts at memory address 1400h, what is the first address of each variable? .data myName BYTE "Elmer Fudd",0 yourName BYTE 30 DUP(0) myAge DWORD 45 yourAge DWORD ? myScore DWORD ? yourScore DWORD ?
myName 1400h 11 0Bh NULL terminator takes 1 byte yourName 1400h + 0Bh = 140Bh 30 1Eh 30 DUP(0) creates 30 bytes init'd to 0 myAge 140Bh + 1Eh = 1429h 4 4h yourAge 1429h + 4h = 142Dh 4 4h myScore 142Dh + 4h = 1431h 4 4h yourScore 1431h + 4h = 1435h 4 4h
Given the following data segment, and assuming it starts at memory address 1400h, what is the first address of each variable? .data num SDWORD ? count WORD ? val DWORD ? column DWORD ? row DWORD ? tabChar BYTE 09h
num 1400h 4 4h count 1400h + 04h = 1404h 2 2h val 1404h + 2h = 1406h 4 4h column 1406h + 4h = 140Ah 4 4h row 140Ah + 4h = 140Eh 4 4h tabChar 140Eh + 4h = 1412h 1 1h
A loop which executes at least one time, and possibly more, is called a... once-or-more loop post-test loop multiples loop pre-test loop
post-test loop
What does .stack do?
specify the size of the runtime stack
Conditional jumps check flags in which register before jumping? address register branch register status register control register
status register
Which of the following identifiers are invalid, and why? count0 1newval Spacer* sym4? loop
valid invalid - Identifiers cannot start with a number invalid - Asterisks may not be part of identifiers. valid invalid - "loop" is a reserved word, instruction