Sunteți pe pagina 1din 6

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 ; AL =


ii. mov al,86h
or al,42h ; AL =


iii. mov al,72h
xor al,0A5h ; AL =


iv. mov al,01101011b
stc
rcl al,2 ; AL =


v. mov al,10000101b
clc
rcr al,1 ; AL =


b. What is the binary value of AX after the following instructions have executed? (6 points, 3 pts each)

i. mov ax,0000000010011101b
mov bx,1010101010000000b
shld ax,bx,1 ; AX =


ii. mov ax,0000000010011101b
mov bx,1010101010001011b
shrd ax,bx,2 ; AX =



2
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 =
AX =


ii. mov dx,-16
mov ax,2
imul dx ; DX =
AX =


iii. mov ax,6B49h
mov dx,0095h
shl ax,1
rcl dx,1 ; DX =
AX =

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 ; CF = ZF = SF =


ii. mov al,00110011b
test al,2 ; CF = ZF = SF =


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)







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)




3
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)





d. 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













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
}















4
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




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




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 =
movzx edx, bl ; edx =
mov bx, 0C45Fh
movsx eax, bx ; eax =
movsx cx, bl ; cx =
xchg ax, var2 ; var2 =
mov var1, ax ;
mov al, [arrayB + 4] ; al =
main endp
end main

5
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 = DX =


Question # 4. Flowchart (4 points)

Draw a flowchart 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



6
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 the 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

S-ar putea să vă placă și