Sie sind auf Seite 1von 10

Chapter 4 Test Bank

Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.
Last update: 11/04/2002
Copyright Kip Irvine. All rights reserved. You may use and modify this test for instructional
purposes as long as you have adopted Assembly Language for Intel-Based Computers (Irvine) for
your current semester course. You are welcome to edit and extract questions from this test as long
as you do not reproduce or distribute the questions outside of your own classroom.

Fill in the Blanks and Short Answer


Use the following data definitions until notified otherwise:
byte1
byte2
word1
word2
word3
word4
dword1
dArray

BYTE
BYTE
WORD
WORD
SWORD
SWORD
DWORD
DWORD

0FFh,1,2
14h
0FFFFh,1,2
3
7FFFh,8000h
9000h
10h,20h,30h,40h
10 DUP(?)

1.

Write one or more statements that move the contents of word1 to word2.
mov ax,word1
; (any general-purpose 16-bit register may
be used)
mov word2,ax

2.

For each of the following instructions, indicate whether it is legal (L) or illegal (I):
a.
b.
c.
d.

3.

mov
mov
mov
mov

movzx
movzx
movzx
movsx

ax,byte1
edx,bl
word2,al
dl,al

L
L
I
I

Indicate the hexadecimal value of the destination operand next to each instruction. Use the letter I
to indicate that a particular instruction is illegal:
mov dx,word3
movsx eax,byte1
mov dh,al
mov bx,dx

5.

L
I
I
L

For each of the following instructions, indicate whether it is legal (L) or illegal (I):
a.
b.
c.
d.

4.

byte2,0FFh
word1,byte2
word2,10000h
si,word1

a.
b.
c.
d.

DX = 7FFFh
EAX = FFFFFFFFh
DH = FFh
BX = FFFFh

Indicate the hexadecimal value of the destination operand next to each instruction. Use the letter I
to indicate that a particular instruction is illegal:
mov
mov
mov
mov

ax,[word3+2]
eax,[dword1+4]
al,[byte1+1]
eax,[word3+4]

a.
b.
c.
d.

8000h
00000020h
1
I (illegal)

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

6.

Where marked by a letter (a, b, c, d), indicate the hexadecimal value of the destination operand:
mov
inc
dec
mov
neg
add

7.

ax,word1
ax
ax
ax,word3
ax
ax,0C2A5h

a. AX = 0000h
b. AX = FFFFh
c. AX = 8001h
d. AX = 42A6h

Where marked by a letter (a, b, c, d), indicate the hexadecimal value of the destination operand:
mov
add
sub
mov
add
neg

al,7Fh
al,2
al,5
al,80h
al,80h
al

a: ZF,CF,SF,OF= 0,0,1,1
b: ZF,CF,SF,OF= 0,0,0,1
c: ZF,CF,SF,OF= 1,1,0,1
d: ZF,CF,SF,OF= 1,0,0,0

8.

Which instruction loads the low byte of the EFLAGS register into AH?

LAHF

9.

Write an instruction that moves the 32-bit address of word1 into the ESI register (assume 32-bit
Protected mode).
mov esi,OFFSET word1

10. Write an instruction that moves the lower 16 bits of dword1 into the BX register (hint: use PTR).
mov bx,WORD PTR dword1
11. Write an instruction that moves the lower 8 bits of word2 into the AL register.
mov al,BYTE PTR word2
12. Write an instruction that moves EBX to location word1:
mov DWORD PTR word1, ebx
13. What is the value of the expression (TYPE word1)?

14. What is the value of the expression (TYPE dword1)?

15. What is the value of the expression (LENGTHOF word1)?

16. What is the value of the expression (SIZEOF word1)?

Short Programming Problems


Use the following data definitions until notified otherwise:
byte1
byte2
word1
word2
word3
word4
dword1
dArray

BYTE
BYTE
WORD
WORD
SWORD
SWORD
DWORD
DWORD

0FFh,1,2
14h
0FFFFh,1,2
3
7FFFh,8000h
9000h
10h,20h,30h,40h
10 DUP(?)

17. Implement the following expression in assembly language, using 32-bit integers (you may modify
any registers you wish):
eax = dword1 + ebx - ecx
mov eax,dword1
add eax,ebx

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

sub eax,ecx
18. Implement the following expression in assembly language, using 32-bit integers (you may modify
any registers you wish):
eax = -dword1 + (edx - ecx) + 1
sub
mov
neg
add
inc

edx,ecx
eax,dword1
eax
eax,edx
eax

; eax = -dword1

19. Implement the following expression in assembly language, using 32-bit integers. The notation
dword[1] corresponds to an array reference in C++ or Java:
dArray[0] = dArray[1] + dArray[2]
mov eax,[dArray+4]
add eax,[dArray+8]
mov dArray,eax
20. Use the following data declarations to write an assembly language loop that copies the string from
source to target. Use indexed addresing with EDI, and use the LOOP instruction.
source
target
mov
mov
L1: mov
mov
inc
loop

BYTE
BYTE

"String to be copied",0
SIZEOF source DUP(0),0

edi,0
ecx,SIZEOF source
al,source[edi]
target[edi],al
edi
L1

Multiple-Choice
21. The following statement will assemble without errors:
mov WORD PTR [eax], 1234h
a. true
b. false
answer: a
22. The following instruction will produce FFFFFFFCh in EAX:
movsx eax,-4
a. true
b. false
answer: a
23. The SAHF instruction copies the Sign, Overflow, and Carry flags to the AL register.
a. true
b. false
answer: b
24. The following instructions will set the Overflow flag:
mov al,0D7h

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

add al,74h
a. true
b. false
answer: b
25. The following instruction will assemble:
inc [esi]
a. true
b. false
answer: b
26. The following instructions will set the Overflow flag:
mov al,125
sub al,-4
a. true
b. false
answer: a
27. The syntax for the MOV instruction is: MOV destination, source.
a. true
b. false
answer: a
28. The MOV instruction requires both operands to be the same size.
a. true
b. false
answer: a
29. The MOV instruction permits a move between two memory operands.
a. true
b. false
answer: b
30. The EIP register cannot be the destination operand of a MOV, ADD, or SUB instruction.
a. true
b. false
answer: a
The MOV instruction does not permit an immediate value to be moved to a segment register.
a. true
b. false
answer: a
31. The MOVZX instruction can use a variable as the destination operand.
a. true
b. false
answer: b
32. The MOVSX instruction sign-extends an integer into a larger operand.

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

a. true
b. false
answer: a
33. The DS register can be the destination operand of a MOV instruction.
a. true
b. false
answer: b
34. The ES register can the source operand of a MOV instruction.
a. true
b. false
answer: a
35. The SAHF instruction copies the EFLAGS register into a 32-bit memory location.
a. true
b. false
answer: b
36. The INC instruction does not affect the Carry flag.
a. true
b. false
answer: a
37. If AL contains +127 and you add 3 to AL, the Overflow flag will be set.
a. true
b. false
answer: a
38. If BX and DX contain positive integers and they are added, producing a negative result, the
Overflow flag will be clear.
a. true
b. false
answer: b
39. The Overflow flag may be set when adding a positive integer to a negative integer.
a. true
b. false
answer: b
40. The following instruction is legal: inc [esi]
a. true
b. false
answer: b
41. Adding 7Fh and 05h in an 8-bit register sets the Overflow flag.
a. true
b. false
answer: a
42. Adding 0FFh and 05h in an 8-bit register sets the Overflow flag.

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

a. true
b. false
answer: b
43. Adding 5 to 0FBh in an 8-bit register sets the Zero flag.
a. true
b. false
answer: a
44. The following instructions will set the Carry flag:
mov al,0FEh
sub al,2
a. true
b. false
answer: b
45. The following instructions will set the Sign flag:
mov al,0FEh
sub al,2
a. true
b. false
answer: a
46. Select the answer choice that best implements the following expression. Do not permit dword1,
ECX, or EDX to be modified:
eax = -dword1 + (edx - ecx) + 1
a.
mov
neg
sub
add
inc

eax,dword1
eax
edx,ecx
eax,edx
eax

mov
neg
mov
sub
add
inc

eax,dword1
eax
ebx,edx
ebx,ecx
eax,ebx
eax

neg
mov
sub
add
inc

dword1
ebx,edx
ebx,ecx
eax,ebx
eax

mov
mov
sub
add
inc

eax,dword1
edx,ebx
ebx,ecx
eax,ebx
eax

b.

c.

d.

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

answer: b
Some of the following questions have more than one correct answer. Circle all correct answers:

Use the following data definitions until notified otherwise:


byte1
byte2
word1
word2
word3
word4
dword1
dArray

BYTE
BYTE
WORD
WORD
SWORD
SWORD
DWORD
DWORD

0FFh,1,2
14h
0FFFFh,1,2
3
7FFFh,8000h
9000h
10h,20h,30h,40h
10 DUP(?)

47. What is the hexadecimal value of AX when this code executes?


mov esi,OFFSET word1
add esi,4
mov ax,[esi]
a. 1
b. 2
c. FFFFh
d. 3
answer: b
48. What is the final hexadecimal value of AX when this code executes?
mov ebx,OFFSET dword1
sub ebx,2
mov ax,[ebx]
a. 0000h
b. 0010h
c. 9000h
d. 0020h
answer: c
49. What is the final hexadecimal value of AL when this code executes?
mov ebx,OFFSET byte1
mov al,[ebx+3]
a. 1
b. 2
c. 14h
d. 3
answer: c
50. What is the final hexadecimal value of EAX when this code executes?
mov edx,8
mov eax,dword1[edx]

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

a. 00000010h
b. 20000000h
c. 00300000h
d. 00000030h
answer: d
51. In Protected mode, which of the following define(s) a pointer variable containing the offset of
word1?
a. ptr1 DWORD word1
b. word1 DWORD ptr1
c. ptr2 DWORD PTR word1
d. ptr2 DWORD OFFSET word1
answers: a, d
52. Suppose the statement PWORD TYPEDEF PTR DWORD has already appeared in a program.
Which of the following data declarations would be correct?
a. PTR DWORD var1 ?
b. var2 PWORD ?
c. var3 PTR DWORD ?
d. var4 PTR PWORD ?
answers: b, c

Example 2
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

.data
varX DWORD 9,8,7,6,5,4,3,2,1,0
varY DWORD (LENGTHOF varX) DUP(0)
.code
mov esi,OFFSET varY + (SIZEOF varX) - 4
mov edi,4
mov ecx,LENGTHOF varX - 1
L1: mov eax,varX[edi]
mov [esi],eax
add edi,4
sub esi,4
loop L1

53. Refer to Example 2. After the loop executes, what will be the values at locations varY, varY+4,
and varY+8?
a. 0, 0, 0
b. 0, 1, 2
c. 1, 2, 3
d. 0, 0, 1
answer: d
54. Refer to Example 2. After the loop executes, what will be the values in the last three positions
(array elements) of varY?
a. 0, 0, 0
b. 8, 9, 0

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

c. 6, 7, 8
d. 7, 8, 9
answer: c
55. Refer to Example 2. If line 9 were changed to the following, what would be the final values at
locations varY, varY+4, and varY+8?
9:

mov [esi-4],eax

a. 0, 0, 0
b. 0, 1, 2
c. 1, 2, 3
d. 0, 0, 1
answer: b

Use the following data for the remaining questions in this section:
word1 WORD 1000h,2000h,3000h,4000h,5000h
dword1 DWORD 10000h,20000h,30000h,40000h
56. What is the final value of AX after this code has executed?
mov esi,OFFSET word1
mov ecx,5
mov eax,100h
L1: add ax,[esi]
add ax,16
add esi,TYPE word1
Loop L1
a. F150h
b. 0150h
c. F016h
d. 0016h
answer: a
57. What is the final value of AX after this code has executed?
mov edx,OFFSET word1+8
mov ecx,2
mov ax,0
L1: mov ax,[edx]
add ax,20h
sub edx,4
Loop L1
a. 8040h
b. 9040h
c. 4020h
d. 3020h

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

answer: d
58. Suppose we want EAX to contain the sum of the dword1 array when the following (incomplete)
code finishes executing:
1:
2:
3:
4:
5:
6:

mov edi,OFFSET dword1


mov ecx,LENGTHOF dword1
?
?
?
loop L1

Which of the following choices would best fill in lines 3, 4, and 5?


a.
3:
4:
5:

mov
L1: add
add

eax,[edi]
eax,dword1
edi,2

3:
4:
5:

mov
L1: add
add

eax,0
eax,[edi]
edi,TYPE dword1

3:
4:
5:

mov
L1: add
add

eax,0
eax,[edi]
edi,2

b.

c.

d.
3:
mov
4:
L1: add
5:
add
answer: b

DWORD PTR [edi],0


eax,[edi]
edi,TYPE dword1

Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition

10

Das könnte Ihnen auch gefallen