Final Exam X86 Assembly Ankey
Short Description
This is the answer key to a sample final exam for an X86 assembly language course....
Description
Question # 1. Short Answer Problems (34 points) a.
What is the value of AL after the following instructions have executed? (10 points, 2 pts each) i.
mov al,4Bh and al,74h
ii.
mov al,86h or
iii.
al,42h
; AL = C6h
mov al,72h xor al,0A5h
iv.
; AL = 40h
; AL = D7h
mov al,01101011b al,01101011b stc rcl al,2
; AL = 1010 1110
v. mov al,10000101b al,10000101b clc rcr al,1
b.
; AL = 0100 0010
What is the binary value of AX after the follo wing instructions have executed? (6 points, 3 pts each) i.
mov ax,0000000010011101b mov bx,1010101010000000b shld ax,bx,1
ii.
; AX = 0000 0001 0011 1011
mov ax,0000000010011101b mov bx,1010101010001011b shrd ax,bx,2
; AX = 1100 0000 0010 0111
c.
What will be the hexadecimal values of DX and AX after the following instructions have executed? (12 points, 4 pts each) i.
mov dx,000Fh mov ax,6342h mov bx,100h div bx
; DX = 0042h AX = 0F63h
ii.
mov dx,-16 mov ax,2 imul dx
; DX = FFFFh
AX = FFE0h
iii.
mov ax,6B49h mov dx,0095h shl ax,1 rcl dx,1
; DX = 012Ah AX = D692h
d.
What are the correct values of the Carry, Zero, and Sign flags after the following instructions execute? (6 points, 3 pts each) i.
mov al, 6 cmp al, 5
ii.
; CF = 0
ZF = 0
SF = 0
; CF = 0
ZF = 0
SF = 0
mov al,00110011b test al,2
Question # 2. Short Programming Problems (25 points) a.
Write a sequence of two instructions that copies bits 0-5 from AL to bits 0-5 in BL. Bits 6-7 in BL should be cleared, and AL should be unchanged. (5pts) mov bl,al and bl,00111111b
b.
Write a sequence of two instructions that copies the integer in bits 4-7 from the AL register into bits 0-3 of the BL register. The upper 4 bits of AL will be cleared, as will the upper 4 bits of BL. . (5pts) shr al,4 mov bl,al
2
c.
Code instructions that jump to the label L1 when either bit 2 or 3 is set in the DL register (do not modify DL). (5pts) test dl,1100b jnz L1
d.
; (00001100b)
Write instructions that implement the following pseudo-code using conditional jump instructions. Do not use the .IF directive. Assume that integers are signed. (5pts) if
(eax > ecx ) mov dl, +7 else mov dl, -2
cmp eax, ecx
OR
cmp eax, ebx
jng L1
jg L1
mov dl, +7
mov dl, -2
jmp L2 L1:
mov dl, -2
L2:
e.
jmp L2 L1:
mov dl, +7
L2:
Implement the following pseudo-code with assembly language statements without using the .WHILE, the .IF or any other directive. (5pts) while ( int2 >= int1 ) { add ebx, 3 if ( ebx > int2 ) mov ebx, 4 else mov ebx, int1 }
top:
mov eax, int2 cmp eax, int1 jl
L3
add ebx, 3 cmp ebx, int2 jg
L1
mov ebx, int1 jmp L2 L1:
mov ebx, 4
L2:
jmp top
L3:
3
Question # 3. Tracing Problems (27 points) a.
Suppose eax, ebx, and ecx contained three signed integers. What will be the purpose of the following code? (5pts) cmp
eax, ebx
jle
L1
mov
eax, ebx
L1: cmp
eax, ecx
jle
L2
mov
eax, ecx
L2: call WriteInt
Solution:
b.
The purpose will be to display the smallest of the 3 integers.
What will be the result in array after the following instructions execute? (5pts) .data array
dword 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
var1
dword 4
.code cld mov esi, offset array mov edi, esi mov ecx, lengthof array L1: lodsd mul var1 stosd loop L1
Solution:
c.
Array will contain the following: 40 36 32 28 24 20 16 12 8 4
What will be the results in all the registers? Show the result next to each line. (12 points,2pt for every output line) .data var1
word 2000h
var2
word 4000h
arrayB
byte 60h, 70h, 10h, 50h, 40h
.code main proc mov
bx, 0A59Dh
movzx eax, bx
; eax
= 00000A59D
movzx edx, bl
; edx
= 0000009D
movsx eax, bx
; eax
= FFFFC45F
movsx cx, bl
; cx
= 005F
xchg
ax, var2
; var2 = 2000
mov
var1, ax
;
mov
al, [arrayB + 4]
; al
mov
bx, 0C45Fh
= 40
main endp end main
4
d.
What will be the final values of cx and dx when the following code executes? (5pts) .data array SWORD
4, -2, 5, 8, -3, 7, 1, 0
.code mov cx, 1 mov esi, 2 mov ax, array[esi] mov bx, array[esi+4] cmp ax, 3 jae L2 cmp bx, 4 jb L1 jmp L3 L1: mov cx, 4 L2: mov dx, 5 jmp L4 L3: mov dx, 6 L4:
Solution:
CX = 1
DX = 5
Question # 4. Flowchart (4 points) Draw a flowchart that corresponds to the following code:
L1:
mov
esi, OFFSET array
mov
ecx, LENGTHOF array
mov
eax, 0
add
eax, [esi]
add
esi, TYPE array
loop
L1
mov
sum, eax begin
ecx = LENGTHOF array
eax = 0
mov esi,OFFSET array
L1:
add eax,[esi]
add esi,TYPE array
ecx = ecx 1
yes
ecx > 0?
no sum = eax
end
5
Question # 5. Programming (10 points)
--- use the back of the page if needed ----
Using the following table as a guide, write a program that asks t he user to enter an integer test score between 0 and 100. The program should display the appropriate letter grade: Score Range 90 to 100 80 to 89 70 to 79 60 to 69 0 to 59
Letter Grade A B C D F
Hint: You may use the pseudo .IF, .ELSEIF,.ELSE and .ENDIF directives. GOOD LUCK TITLE Letter Grade INCLUDE Irvine32.inc .data str1 BYTE "Enter an integer score: ",0 str2 BYTE "The letter grade is: ",0 .code main PROC call mov call call call
Clrscr edx,OFFSET str1 WriteString ReadInt Crlf
.IF eax >= 90 mov al,'A' .ELSEIF eax >= 80 mov al,'B' .ELSEIF eax >= 70 mov al,'C' .ELSEIF eax >= 60 mov al,'D' .ELSE mov al,'F' .ENDIF mov call call call
edx,OFFSET str2 WriteString WriteChar Crlf
; input score from user
; multiway selection structure to ; choose the correct grade letter
; display grade letter in AL
exit main ENDP END main
6
View more...
Comments