CS2011 Sample Midterm
1. Debug displays the following output during the execution of a program (the instruction mnemonic has been removed):
AX=5343
BX=0005 CX=3032 DX=0000
SP=0100 BP=0000 SI=0000
DI=0000
DS=131F
ES=130C SS=1320 CS=131C
IP=001A NV UP EI PL NZ AC PE NC
131C:001A 7FEC <instruction mnemonic would be here>
a) (5 points) Which conditional jump instruction is it? (give the assembly language mnemonic)
b) (5 points) If no jump is taken, what value will be in the IP after this instruction executes?
c) (5 points) If the jump does happen, what value will be in the IP after this instruction executes (i.e. where will it be jumping to)?
d) (5 points) If BX “points to” a location in memory (like in indirect addressing), what is the 20 bit effective address (absolute address) of the memory location pointed to?
2. (20 points) Write 8086 assembly language code to implement the following high-level construct. Assume all comparisons are made on signed numbers.
IF ((AL < 12) AND (BL > 2)) THEN
CX = CX + 1
ELSE
CX = CX – 3
ENDIF
3. Assuming 8-bit arithmetic, give the sum (in hex) and the values of the zero flag, sign flag, carry flag, and overflow flag when E7 (hex) is added to
a) (5 points) 99 (hex)
sum = ______ zero = ______sign = ______carry = ______overflow = ______
b) (5 points) 8A (hex)
sum = ______ zero = ______sign = ______carry = ______overflow = ______
c) (5 points) 19 (hex)
sum = ______ zero = ______sign = ______carry = ______overflow = ______
4. An array is defined in an assembly language program as follows:
.data
truephrase db “Exams are NEVER fun!”
a)
(5 points) Write the assembly language instructions that
will copy the letter f from the array into the DL register. Use direct offset addressing.
b) (5 points) Write the assembly language instructions that will copy the letter f from the array into the DL register. Use indirect addressing without displacement.
c) (5 points) Write the assembly language instructions that will copy the letter f from the array into the DL register. Use one of the following addressing modes (your choice!): base-offset, base-indexed, base-indexed with displacement.
5. (10 points) Each register in the 8086 has a special purpose. Give the name and special purpose of the following registers (what is it/what can it be used for that all or most other registers can not be):
a) DS:
b) CS:
c) BX (this purpose is shared with SI and DI):
d) CX:
e) IP:
6. A byte of memory contains the hexadecimal value 9A. What decimal number does this represent if the byte is interpreted as containing:
a) (5 points) An eight-bit unsigned integer.
b) (5 points) An eight-bit signed integer in sign-magnitude form
7. (10 points) Assume that AX contains 0008H, and BX contains 0005h. Show the contents of AX after each of the following instructions executes (do each part independently). Give your answers in hex:
a.
DIV BL
b. MUL BL