Question # 1.
Question # 1. Short Answer Problems (34 points)
Short Answer Problems (34 points)
a.a. What is the value of AL after the following instructions What is the value of AL after the following instructions have executed? (10 points, 2 pts each)have executed? (10 points, 2 pts each) i.
i. mov al,4Bhmov al,4Bh and
and al,74h al,74h ;; AL = AL = 40h40h
ii.
ii. mov al,86hmov al,86h or
or al,42h al,42h ;; AL = AL = C6hC6h
iii.
iii. mov al,72hmov al,72h xor
xor al,0A5h al,0A5h ;; AL = AL = D7hD7h
iv.
iv. mov mov al,01101011al,01101011bb stc
stc rcl
rcl al,2 al,2 ;; AL = AL = 1010 11101010 1110
v.
v. mov mov al,10000101al,10000101bb clc
clc rcr
rcr al,1 al,1 ;; AL = AL = 0100 00100100 0010
b.
b. What is the binary value of AX after the folloWhat is the binary value of AX after the follo wing instructions have executed? (6 points, 3 pts each)wing instructions have executed? (6 points, 3 pts each)
i.
i. mov ax,0000000010011101bmov ax,0000000010011101b mov bx,1010101010000000b mov bx,1010101010000000b shld
shld ax,bx,1 ax,bx,1 ;; AX = AX = 0000 0001 0011 10110000 0001 0011 1011
ii.
ii. mov ax,0000000010011101bmov ax,0000000010011101b mov bx,1010101010001011b mov bx,1010101010001011b shrd
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, andSign flags after the following instructions execute? (6 points, 3 pts each)
i. mov al, 6
cmp al, 5 ; CF = 0 ZF = 0 SF = 0
ii. mov al,00110011b
test al,2 ; CF = 0 ZF = 0 SF = 0
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)
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 ; (00001100b) jnz L1
d. Write instructions that implement the following pseudo-code using conditional jump instructions. Do not use the
.IF directive. Assume that integers aresigned. (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 jmp L2
L1: mov dl, -2 L1: mov dl, +7
L2: L2:
e. 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:
Question # 3. Tracing Problems (27 points)
a. Supposeeax,ebx, andecx 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: The purpose will be to display the smallest of the 3 integers.
b. 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: Array will contain the following: 40 36 32 28 24 20 16 12 8 4
c. 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
mov bx, 0C45Fh
movsx eax, bx ; eax = FFFFC45F
d. What will be the final values of cx anddx 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 aflowchart that corresponds to the following code:
mov esi, OFFSET array mov ecx, LENGTHOF array mov eax, 0
L1: add eax, [esi]
add esi, TYPE array loop L1
mov sum, eax
begin
ecx = LENGTHOF array
eax = 0
mov esi,OFFSET array
add eax,[esi] L1:
add esi,TYPE array
ecx = ecx 1
ecx > 0? yes
sum = eax no
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 Letter Grade 90 to 100 A
80 to 89 B
70 to 79 C
60 to 69 D
0 to 59 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 Clrscr
mov edx,OFFSET str1 ; input score from user call WriteString
call ReadInt call Crlf
.IF eax >= 90 ; multiway selection structure to
mov al,'A' ; choose the correct grade letter
.ELSEIF eax >= 80 mov al,'B' .ELSEIF eax >= 70 mov al,'C' .ELSEIF eax >= 60 mov al,'D' .ELSE mov al,'F' .ENDIF mov edx,OFFSET str2 call WriteString
call WriteChar ; display grade letter in AL
call Crlf exit
main ENDP END main