Vous êtes sur la page 1sur 5

1

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

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?
Which library procedure locates the cursor
at a specific row and column on the screen?
Which library procedure reads a 32-bit
signed decimal integer from standard input?
Which library procedure reads a string from
standard input?

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


mov al, 5
cmp al, 7

CF= ZF= SF=


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

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 =


mov al, 00111100b
or al, 83h


al =


mov al, 94h
xor al, 37h


al =


mov al, 9Eh
not al


al =



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

Answer: CX = DX =

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










4
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




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












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

Vous aimerez peut-être aussi