You are on page 1of 5


Question # 1. True False (10 points; 2 points each)

Please indicate whether each statement is True (T) or False (F).

The LOOPZ instruction first checks to see whether ECX is not
equal to zero and ZF=1; then LOOPZ decrements ECX and
jumps to the destination label.
The RET instruction pops the top of the stack into the instruction
The TEST instruction performs a nondestructive AND operation
between each pair of matching bits in two operands
After a CMP Instruction, when the destination operand is
smaller than the source operand the sign flag is equal the
overflow flag
EAX contains an integer before calling WriteDec

Question # 2. Short Answers (45 points)

1. Answer the following questions with a short answer (12 points, 3 point each)

Which library procedure writes a single
character to standard output? WriteChar
Which library procedure locates the cursor
at a specific row and column on the screen? Gotoxy
Which library procedure reads a 32-bit
signed decimal integer from standard input? ReadInt
Which library procedure reads a string from
standard input? ReadString

2. In the following instruction sequence, show the values of the Carry, Zero, and Sign
flags where indicated: (6 points, 3 points each)

mov al, 00110011b
test al, 2

CF= 0 ZF= 0 SF= 0

mov al, 5
cmp al, 7

CF= 1 ZF= 0 SF= 1

3. What will be the value of EAX when the following sequence of instructions has
executed? (5 points)

push 10
push 20
push 30
pop eax
pop eax
pop eax

eax = 10

4. In the following instruction sequence, show the changed values of AL where
indicated, in binary: (12 points, 3 points each)

mov al, 11001111b
and al, 00101010b

al = 00001010b

mov al, 00111100b
or al, 83h

al = 10111111b

mov al, 94h
xor al, 37h

al = 10100011b

mov al, 9Eh
not al

al = 01100001b

5. What will be the final values of CX and DX when the following code executes? (10
array SWORD 8,2,3,5,-4,6,0,4
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

Answer: CX = 1 DX = 6

Question # 3. Short Programming Problems (20 points)

1. Write code that jumps to label L1 if bits 4, 5, and 6 are all set in the BL register (10

Clear all bits except bits 4, 5, and 6. Then compare the result with 0111000 binary

and bl, 0111000b ; clear unwanted bits
cmp bl, 0111000b ; check remaining bits
je L1 ; all set? jump to L1

2. Suppose EAX, EBX, and ECX contained three unsigned integers. Explain what does the
following code excerpts do? (10 points)

cmp eax,ebx
jae L1
mov eax,ebx
L1: cmp eax,ecx
jae L2
mov eax,ecx
L2: call WriteInt

Display the largest of the three integers

3. Use the following data declarations to write an assembly language procedure named
CopyString that copies the string from source to target. Use indexed addresing with
EDI, and use the LOOP instruction. (10 points)
source BYTE "String to be copied",0
target BYTE SIZEOF source DUP(0),0

CopyString PROC
mov edi,0
mov ecx, SIZEOF source
L1: mov al, source[edi]
mov target[edi], al
inc edi
loop L1
CopyString ENDP

Question # 4. Programming (15 points)

Write a program that does the following:
(1) fill a 32-bit array intArray with 50 random integers;
(2) Loop through the array, displaying each value, and count the number of negative
values; (3) After the loop finishes, display the count.
You may use in your program the following procedure calls from the Irvine Library:

Randomize Initializes the starting value for Random32 procedure. You need to
call Randomize once at the beginning of your program.
Random32 Generates 32-bit pseudorandom integer in the range 0 to FFFFFFFFh,
returning its value in EAX.
WriteInt Writes signed 32-bit signed integer in decimal format. Pass the integer
in EAX.
Crlf Advances the cursor to the beginning of the next line on the screen.
WriteDec Writes unsigned 32-bit unsigned integer in decimal format. Pass the
integer in EAX.

TITLE Question Four

intArray SDWORD 50 DUP(?)
count DWORD 0

main PROC
call Randomize

; Fill the array with random values

mov esi,OFFSET intArray ; point to the array
mov ecx,LENGTHOF intArray ; loop counter

L1: call Random32 ; EAX = random value
call WriteInt
call Crlf
mov [esi],eax
add esi,4
loop L1

; Search for negative values

mov esi,OFFSET intArray ; point to the array
mov ecx,LENGTHOF intArray ; loop counter

L2: cmp dword ptr [esi],0 ; compare value to zero
jge L3 ; negative value?
inc count ; yes: add to count

L3: add esi,4
loop L2

mov eax,count
call WriteDec
call Crlf

main ENDP
END main