CS 271 Midterm
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
Which of the following String Literals are allowed in MASM? (Check all that apply) 'Fancy' "nested 'quotes' " 'simple 'quotes' ' 'W','o','r','s','t','!',0 "Hot ", 'Dog', 33, 0
'Fancy' "nested 'quotes' " 'W','o','r','s','t','!',0 "Hot ", 'Dog', 33, 0
This directive is used to mark the beginning of the code segment in memory.
.code
Which directive identifies the part of a program containing instructions? Use correct syntax.
.code
Write the syntax to set the size of the runtime stack to 2048 bytes.
.stack 2048
Find the hexadecimal big-endian form of the 32-bit representation of 25,215 (dec)
00 00 62 7F25215d = 627Fh, so the 32-bit hex form would be 00 00 62 7F. This is the same as the big-endian representation.
Assume ESP = 00F4h, and then PUSHAD is executed. What is the new value of ESP?
00D4hPUSHAD pushes eight (8) four-byte registers on the stack, so ESP is decremented by 4*8=32. 32d = 20h. 00F4h - 0020h = 00D4h
Assume ESP = 00F4h, and then PUSH EAX is executed. What is the new value of ESP?
00F0hESP is decremented by 4 (the size of EAX). 00F4h - 0004h = 00F0h
Assume ESP = 00F4h, and then POP AX is executed. What is the new value of ESP?
00F6hESP is incremented by 2 (the size of AX). 00F4h + 0002h = 00F6h
Instruction Execution Cycle
1. Fetch the instruction at the address in the Instruction Pointer into the Instruction Register. 2. Increment the Instruction Pointer to point to next instruction's address. 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. Store resultant operands.
What is the largest unsigned integer that may be stored in 24 bits?
16,777,215
How much memory can be addressed in Real-address mode?
1MB
What is the minimum size of a data type, in bytes, to be impacted by system endianness. (Whole numbers only
2
What will be the value of EAX when the following sequence of instructions has executed? PUSH 5 PUSH 10 PUSH 20 POP EAX
20
How many bits are there in 35 MB (note: bytes, so binary prefixes apply)
293,601,280 bits35 * 220 Bytes * 8 bits/Byte = 36,700,160 Bytes * 8 bits / Byte = 293,601,280 bits
What is the largest signed integer that may be stored in 32 bits?
2^31 - 1
How many bits long is a DWORD (doubleword) on x86 systems?
32
What is the size of the general-purpose registers?
32 bits
What is the width of the address and data buses?
32 bits
How many bytes long is a DWORD (doubleword) on x86 systems?
4
What will be the value of EAX when the following sequence of instructions has executed? PUSH 5 PUSH 10 POP EBX POP EAX
5
What are the minimum numbers of binary bits needed to represent the unsigned decimal integers (a) 33 and (b) 309
6 and 9
Find the hexadecimal little-endian form of the 32-bit representation of 25,215 (dec)
7F 62 00 0025215d = 627Fh, so the 32-bit hex form would be 00 00 62 7F. Inverting the byte-ordering we arrive at 7F 62 00 00.
If you are using an integer constant in one of your CS271 programs, which constant method must you use?
=
What would you call an ordered list of organized instructions existing somewhere in memory, and associated with a data structure for storage of data?
A program!
Define "Bus"
A set of parallel "wires" for transferring a set of electrical signals simultaneously.
Which of the following are valid 8-bit register references? If so, describe what they reference? If not, why? AL DH SH EL
AL: Yes, refers to bits 0-7 of EAX DH: Yes, refers to bits 8-15 of EDX SH: No, this would be ambiguous, because we have ESP, ESI, and SS registers EL: No, ES register can't be byte-referenced.
What unit on a CPU chip is responsible for computing basic addition and subtraction operations?
ALU
On a computer, where is simple integer math computed?
ALU - Arithmetic/Logic Unit
Given the data-segment declaration myArray DWORD 35 DUP(?), write a statement to calculate the number of bytes in the array and assign this to a constant named ArraySize.
ArraySize = ($ - myArray)$ gets the data segment address of the current line, and subtracting off the address of myArray provides the length in BYTES of myArray.
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 segment register points to the beginning of the code segment?
CS
In the IA-32 architecture, what are valid 16-bit register references?
CX, SS, SP
Which flag is set when the result of an unsigned arithmetic operation is too large to fit into the destination?
Carry Flag
Name at least four CPU status flags.
Carry, Overflow, Parity, Auxiliary Carry, Sign, Direction, Zero
Name the four basic parts of an assembly language instruction.
Code label, instruction mnemonic, operand(s), comment
When transferring instructions and data between the Main Memory Unit and the CPU, they will be placed on the Data 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.
Please select the appropriate description of the LOOP instruction.
Decrement ECX, then Jump if ECX is nonzero
Compared to higher-level languages, which of the following are benefits of Assembly Language programming? (Check all that apply)
Direct Manipulation of Memory Hands-on Code Optimization
Which library procedure displays the CPU flags and 32-bit registers?
DumpRegs
Which register should contain an unsigned integer before calling WriteDec?
EAX
Which register is known as a loop counter?
ECX
What preconditions exist for WriteString?
EDX must hold an address offset pointing to a BYTE array, which is null-terminated.
When branching, which register's value changes? (Enter the three-letter register abbreviation only)
EIP
Why does protected mode prevent programs from changing the EIP register directly?
EIP contains the memory address of the next instruction to be fetched. Since the programmer ordinarily will not know the absolute address where any of the instructions are stored, protected mode restricts access to EIP, and allows it to be changed only by the operating system.
In 32-bit mode, which register points to the top of the stack?
ESP
Language Hierarchy: Rank the following languages from low level (1) to high level (4): English, python, assembly, machine code
English, python, assembly, machine code
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)?
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
What is the hex value of the most significant byte of an SDWORD named myNum if it is initialized to the value -420,000 (decimal)?
FF-420,000 in 4-byte 2's complement representation is FF F9 97 60. The MSB is the leftmost, so FF
(True/False) A single computer architecture may have programs written for it using more than one Assembly Language (x86, RISC-V, ...).
False
(True/False) Assembly Language programs are 'higher level' than C programs.
False
(True/False) In debugging mode, the values of watched variables/registers may only be viewed in hexadecimal format.
False
(True/False) The POP instruction can have an immediate operand.
False
Given an odd-parity system, the following data would be flagged as having an error. 1101 1011 0010 1010
False
If an integer's sign bit is 1, the integer is positive.
False
If the LOOP instruction sets ECX to zero, a jump to the destination label does take place.
False
PUSHF is used to preserve all general purpose register contents on the stack.
False
Simple parity checks can correct any single-bit errors.
False
The ASCII code values for alphabetic letters (e.g. 'a') are smaller than for decimal digits (e.g. '1').
False
The CPU clock cycle length is the only contributing factor to the speed of operations on a computer.
False
The Stack Segment register always points to the top of the runtime stack.
False
The equals sign directive (=) may be used for both integer constants and string constants.
False
The number 15.6 can be represented exactly in IA-32 Floating Point Unit 32-bit IEEE 754 format.
False
(True/False): Assembly language directives execute at runtime.
False Directives are used by the assembler prior to runtime.
(True/False) System endianness impacts the storage of data on a bit-by-bit level.
False Endianness impacts storage of data on a byte-by-byte level. Bit ordering within bytes is not changed.
Even-parity systems' parity checks can detect an Even number of errors.
False Even numbers of errors are undetectable by parity check.
(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 can have an implied destination operand (EDX:EAX for 32-bit inputs, EAX for 16-bit inputs, AX for 8-bit inputs). It may also be used with 2 or even 3 operands!
(True/False) If RET was left out of a procedure, execution would stop at the ENDP directive.
False RET updates EIP to return to the calling procedure. Without it, execution will run right over the ENDP and continue to the next address in memory immediately after the procedure.
(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) The order of bytes in memory for strings is different on little-endian systems than big-endian systems.
False Strings are arrays of BYTEs, and single-byte data types aren't impacted by endianness.
(True/False): 4b is a valid binary integer literal .
False 4 is not a valid binary digit.
(True/False): A hexadecimal literal may be written as 0x3A in MASM.
False Proper notation would be 3Ah or 03Ah
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.
(True/False) Assembly Language programs are portable to a variety of computer architectures.
False, assembly languages are architecture specific.
(True/False) Using the myArray definition from Question 2, the following line correctly calculates the number of elements in myArray:numElements = ($ − myArray) / 2
FalsemyArray is an array of DWORD, so you would have to divide by 4 to get the number of elements.
How is data pulled from memory?
First, the address where the data resides is put in MAR, then on the address bus, then a 'memory read' is triggered and the data is pulled from that particular memory cell, put on the data bus, and then into the MDR.
How many bytes does it take to represent the following set of characters in ASCII: HELLO
Five.One byte per ASCII character, five ASCII characters.
Which library procedure returns the number of milliseconds elapsed since midnight?
GetMseconds
Which library procedure locates the cursor at a specific row and column on the screen?
Gotoxy
Which register points to the address of the next instruction to be executed?
IP - Instruction Pointer (EIP in IA32)
Which register holds the opcode of current instruction being executed?
IR - Instruction Register
Which of the following is true about the POP instruction?
It copies the data pointed to by the stack pointer into the operand, and then increments the stack pointer (by 2 or 4).
Which of the following is true about the PUSH instruction?
It decrements the stack pointer (by 2 or 4), and then copies the operand into the stack at the location pointed to by the stack pointer.
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 of the following statements correct makes a constant integer defining a maximum integer value of 365?
MAXVAL = 365
Which of the following defines a text macro named MESSAGE that contains this string data? "I'm good at this!",0
MESSAGE TEXTEQU <"I'm good at this!",0>
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
Define a MASM constant for your name as a NULL-terminated string.
MY_NAME EQU <"Name O. Student",0>
if you're passing a pointer, which of the three parameter types might your parameter be classified as?
May be either an output parameter or an input-output parameter. In fact, it may even be an input parameter (for example with Irvine's WriteString).
What are some disadvantages of passing parameters using globals?
Modifying a global in a procedure modifies it outside the procedure.Use of globals makes a procedure far less modular.
What is the main purpose of caching?
Moving information from slower storage to faster storage, where it can be accessed more quickly.
Where is a major data transfer bottleneck in a computer, and what helps resolve it?
One major bottleneck is the data bus, because both the program instructions and the data must be retrieved from from the same memory to be executed or used. Caching helps reduce the impact.
I need a program to calculate the odds of winning a lottery. The user enters the range of possible numbers and the number of picks required. For example, the user might enter 42 for the range, with 5 picks on one ticket. This will involve calculating the number of combinations of r items taken from a set of n items (i.e., nCr). The program should display the odds of winning with one ticket. For example: The odds of winning with 5 picks from 42 lottery numbers: 1 in 850668. How would you modularize this problem? First write an ordered outline, then show a hierarchy chart of your modularization.
One way to break the problem into its logical components: Display a title screen Get the user's numbers Calculate the oddsCalculate nCrCalculate factorials Display result
Which flag is set when the result of a signed arithmetic operation is either too large or too small to fit into the destination?
Overflow Flag
What instruction (with any necessary operands) would pop the top 32 bits of the runtime stack into the EBP register?
POP EBP
A procedure is declared using the _____ and ____ directives.
PROC and ENDP
What directives are used to bracket a procedure?
PROC and ENDP
What instruction would I use to save the current value of the flags register?
PUSHFD
Which parameter-passing method does Irvine Library procedure ReadString use? What are the pre/postconditions, receives/returns?
Parameters are passed in registers.Preconditions: Array is type BYTE, buffer size large enough to accommodate user input.Postconditions: Registers changed EDX, EAXReceives EDX (address of string buffer) and ECX (buffer size, allows user input size ECX-1).Returns EDX (address of user string) and EAX (number of characters stored)
Which parameter-passing method is commonly used by compilers?
Passing parameters on the stack.
The CALL instruction functions similarly to which of the following?
Push, then Jump
Which directive is used when defining 64-bit IEEE long reals?
REAL8
Which of the following instructions modify the ESP register?
RET, POP, CALL, PUSH
What storage unit is the closest/fastest on the chip?
Registers
What instruction will subtract the value in the source operand from that of the destination operand, and save there result in the destination operand?
SUB
Which flag is set when an arithmetic or logical operation generates a negative result?
Sign Flag
Identify the sizes of the sign, exponent, and normalized mantissa for a Double Precision x86 floating point value.
Sign: 1 bits Exponent: 11 bits Normalized Mantissa: 52 bits
Identify the sizes (in bits) of the sign, exponent, and normalized mantissa for a Single Precision x86 floating point value.
Sign: 1 bits Exponent: 8 bits Normalized Mantissa: 23 bits
Name some benefits of little-endian byte ordering.
Simpler typecasting, quick even/odd parity checks, arithmetic function optimization.
What are the smallest and largest values which can be represented with an signed SDWORD
Smallest: -231 = -2,147,483,648Largest: 231-1 = 2,147,483,647
What are the smallest and largest values which can be represented with an unsigned DWORD
Smallest: 0Largest: 232-1 = 4,294,967,295
In 32-bit mode, aside from the stack pointer (ESP), what other register points to stack addresses?
Stack Segment (SS), possibly EBP depending on usage
Conditional jumps check flags in which register before jumping?
Status register
What component's primary duty is synchronizing processes inside a computer?
System clock
Write a statement to declare a symbolic constant using the equal-sign directive that contains the ASCII code (09h) for the Horizontal Tab.
TABKEY = 09h
Which register holds the current micro-instruction?
The Control Register
Which register holds the current machine instruction?
The Instruction Register (IR)
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 is the Address Bus used for?
The address bus is used to communicate a specific memory location for reads or writes, e.g. Read from "this address on the address bus"
What does PUSH OFFSET myVar, where myVar is a data-segment variable, put on the stack?
The address of (pointer to) the memory location where the value of myVar is stored.
What does CALL push to the stack?
The address of the instruction immediately following the CALL instruction.
A stack frame is _____
The area of the stack set aside for passed arguments, return address, local variables, and saved registers.
What does PUSH myVar, where myVar is a data-segment variable, put on the stack?
The current value in memory at the location myVar refers to.
Why is a stack called a LIFO structure?
The last value pushed on the stack is the first value to be popped from the stack.
There are several important uses of runtime stacks in programs
The stack provides temporary storage for local variables. The stack makes a convenient temporary save area for registers when they are used for more than one purpose. When the CALL instruction executes, the stack is used to store the address where the called procedure will return to When calling a subroutine, you pass input values called arguments by pushing them on the stack.
When using the LOOP instruction, one should be wary of which common issues/problems? (Check all that apply)
Too many instructions in the loop body Initializing ECX to a value less than or equal to zero. Modifying ECX directly within the loop body. Overwriting ECX's original value in a nested loop body without preserving its outer loop counter value.
(True/False) A single computer architecture may have programs written for it using more than one assembler (MASM, NASM, FASM, ...)
True
(True/False) Assembly Language instructions have a nearly 1:1 correspondence with Machine Code.
True
(True/False) High-level language (HLL) programs are portable to a variety of computer architectures.
True
(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) The PUSH instruction can have an immediate 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): Assembly language directives can be written in any combination of uppercase and lowercase letters.
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
A subprocedure's stack frame contains the return address and its local variables.
True
Adding 5 to 0FBh in an 8-bit register sets the Zero flag.
True
By default, code labels are visible only within the procedure in which they are assigned (created).
True
Given an odd-parity system, the following data would be flagged as having an error. 1111 1111 0000 1010
True
In MASM all text following a semicolon (on the same line) is treated as a comment and ignored when the program is converted to machine code.
True
In debugging mode, a breakpoint is a point in the program where execution will be paused.
True
Mechanically speaking, the CALL instruction pushes its return address on the stack and copies the called procedure's address into theinstruction pointer.
True
One cause of bit errors is signal noise.
True
Passing by reference requires accessing a parameter's offset from inside the called procedure.
True
Simple parity checks can detect any odd number of errors in a bit stream.
True
The INC instruction does not affect the Carry flag.
True
The MASM assembler is used for locating syntax errors, but the debugging system is used for locating logic, run-time, or execution errors.
True
The MOVSX instruction sign-extends an integer into a larger operand.
True
The USES operator, coupled with the PROC directive, lets you list the names of all registers modified within a procedure and preserves them automatically for you.
True
The byte ordering method used on the internet is big-endian.
True
The following are both valid data definitions: List1 BYTE 10, 20 BYTE 30, 40
True
The following instructions will set the Sign flag: mov al,0FEh sub al,2
True
The linker combines object files into an executable file.
True
The number 59.421875 can be represented exactly in IA-32 Floating Point Unit 32-bit IEEE 754 format.
True
There are 8 general purpose registers.
True
True/False) Intel x86-64 systems are little endian
True
True/False) The following statement correctly uses TEXTEQU to assign the symbol SETUP_ESI to a code statement that moves the offset of myArray to the ESI register:SETUP_ESI TEXTEQU <mov esi, OFFSET myArray>
True
True/False): An identifier cannot begin with a numeric digit.
True
True/False): END main is a directive that tells the operating system where to begin execution of the program
True
he following is a valid data definition statement: str1 \ BYTE "This string is quite long!", 0
True
True/False) Simple parity checks can detect any single-bit error.
True Simple parity checks can detect any odd number of bit errors.
After the following MASM code is executed: MOV EAX, 19 MOV EBX, 18 MOV ECX, 17 ADD EAX, EBX SUB EAX, ECX
What is the decimal value in the EAX register? 20 What is the decimal value in the EBX register? 18 What is the decimal value in the ECX register? 17
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)? 11 What is the value in the EBX register (in decimal)19 What is the value in the EDX register (in decimal)?3
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.
f the AH register is modified by the software engineer, is there any change in the EAX register? Why or why not?
Yes, the AH register is part of the EAX register. Specifically, the bits 0-7 of the AH are exactly bits 8-15 of EAX.
What is an instruction?
a control phrase for a computer, "instructs" the computer on what to do
Another name for a stack frame is
activation record
The stack frame inside a procedure is also known as the
activation record
Values passed to a subroutine by a calling program are called
arguments
Which utility program reads an assembly language source file and produces an object file?
assembler
The byte-ordering scheme which stores integers in memory with the most significant byte at the lowest address (first) is called:
big endian
System endianness affects:
byte-wise ordering
Which of the following CALL instructions writes the contents of EAX to standard output as a signed decimal integer?
call WriteInt
________ branching means that we either branch or don't branch depending on the outcome of a logical condition. _________ branching means jumping to another location in the program without checking any conditions.
conditional, unconditional
What type of tool can convert ARM Assembly to x86 Assembly?
cross assembler
A stack is also called a FIFO structure (First-In, First-Out) because the last value put into the stack is always the first valuetaken out.
false
An input/output parameter may be passed by value.
false
Code labels may only appear on lines with no instructions.
false
High-level languages always pass arrays to subroutines by value.
false
In the IA32 architecture, ESP (the stack pointer) is incremented each time data is pushed onto the stack.
false
MASM is case-sensitive
false
System endianness will impact the ordering (indexing) of elements in an array.
false
The EQU directive permits a constant to be redefined at any point in a program.
false
When an argument is passed by value, a copy of the address is pushed on the stack.
false
x86-64 systems default to big-endian byte ordering.
false
During which phase of the instruction execution cycle is the program counter incremented?
fetch
The basic parts of an instruction, in order from left to right, are:
label, mnemonic, operand(s), comment
The byte-ordering scheme which stores integers in memory with the least significant byte at the lowest (first) address is called:
little endian
Which of the following identifiers are allowed in MASM? (Check all that apply)
manBear_Pig1 This_one?
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
mov eax,dword1 neg eax mov ebx,edx sub ebx,ecx add eax,ebx inc eax
Which of the following are valid data definition statements that create an array of unsigned bytes containing decimal 10, 20, and 30, named myArray?
myArray BYTE 10, 20, 30
Select a data definition statement that creates an array of 500 signed doublewords named myList and initializes each array element to the value -1.
myList SDWORD 500 DUP (-1)
Which of the following best describes the relationship from assembly language instructions to machine language instructions?
nearly one to one
A/An ________ procedure call occurs when a called procedure calls another procedure before the first procedure returns.
nested
Which offers a more flexible approach, passing arguments to procedures in registers, or on the stack?
on the stack
When values are received by a called subroutine, they are called
parameters
What parameter-passing method do most/all of Irvine's library procedures use?
pass parameters in registers
A loop which executes at least one time, and possibly more, is called a...
post-test loop
In a vonNeumann architecture, how are programs organized?
programs are stored in memory and executed according to an instruction execution cycle.
What general types of parameters are passed on the stack?
reference parameters, value parameters
The two's complement of an binary value is formed by which process?
reversing (inverting) the bits and adding 1
An argument passed by reference consists of a memory address offset.
true
Arrays are passed by reference to avoid copying each element into the stack/registers.
true
integer Literal Expressions are evaluated to integer literals at assembly -time.
true
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