All Answers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 63

Chapter 1 Test Bank

Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

Fill in the Blanks and Short Answer


1.

Which popular programming language is well-known for executing its target programs on a virtual
machine?

2.

In any numbering system, the ____ specifies the number of different symbols that can be assigned
to a single digit.

3.

Translate the following decimal numbers to binary:


a. 33
b. 16
c. 7
d. 72

4.

Translate the following decimal numbers to hexadecimal:


a. 33
b. 95
c. 257
d. 74

5.

Add the following binary integers: 101101 and 00111011

6.

Form the 8-bit two's complement of each binary integer:


a. 00000001
b. 00001000
c. 11110000
d. 00001111

7.

Translate the following signed decimal numbers to binary:


a. 33
b. 78
c. 7
d.

8.

Convert the following string to a sequence of hexadecimal ASCII codes: "AX123"

Multiple-Choice
(Some of the following questions have more than one correct answer. Circle all correct answers.)
9.

A program that combines object files into an executable program is called a _________.
a. compiler

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

b. loader
c. linker
d. assembler
10. If virtual machine V2 is radically different that virtual machine V1, what major problem results
when we try to run V2 programs on machine V1?
a. translation is too difficult
b. machine V2 cannot run V1 programs
c. V1 would have to be written in microcode
d. V2 would have to be implemented by software
11. A computer directly executes programs written in its _______ language.
a. system
b. native
c. interpreted
d. machine
12. What is the value of the booloean expression X (Y Z), when X=true, Y=false, and Z=true?
a. true
b. false
13. Is the expression X (Y Z) equivalent to (X Y) (X Z) for all possible inputs of X, Y, and
Z?
a. yes
b. no
14. The following C++ expression can be written using only two lines of assembly language code:
X = (Y + 4) * 3;
a. true
b. false
15. A dynamic link library (DLL) is usually written in C++ or assembly language.
a. true
b. false
16. A interpreter decodes and executes one program statement at a time.
a. true
b. false
17. A virtual machine may only be constructed from software.
a. true
b. false
18. The operating system is considered a virtual machine in the example hierarchy shown in this
chapter.

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

a. true
b. false
19. If ISA-level instructions could be executed directly by computer hardware, a microcode interpreter
would be unecessary.
a. true
b. false
20. A single hexadecimal digit can be used to represent 5 binary bits.
a. true
b. false
21. The most significant bit in a binary byte is numbered bit 7.
a. true
b. false
22. The sum of all powers of 2 between 20 and 27 is 255.
a. true
b. false
23. A quadword is 8 bytes.
a. true
b. false
24. A word (on Intel systems) is 16 bits.
a. true
b. false
25. A doubleword is 64 bits.
a. true
b. false
26. A signed integer stores the sign in the least significant bit (LSB).
a. true
b. false
27. If an integer's sign bit is 1, the integer is negative.
a. true
b. false
28. A signed byte can be equal to +128.
a. true
b. false
29. Boolean algebra was invented by Samuel M. Boole, an American inventor who lived in the 1920's.
a. true

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

b. false
30. The expression X Y is true only when X and Y are both true.
a. true
b. false
31. The expression X Y is only true when X and Y are both true.
a. true
b. false
32. The expression X Y is true when X is false and Y is true.
a. true
b. false
33. The expression (X Y) is true when X and Y are both false.
a. true
b. false
34. The three most basic operators in Boolean algebra are AND, OR, and NOT.
a. true
b. false
35. The integer range of standard ASCII codes is:
a. -128 to +127
b. 0 to 127
c. 0 to 270
d. 0 to 65,535
36. How many bits are used by Unicode characters?
a. 7
b. 8
c. 16
d. 24
37. Which type of program must usually run on multiple platforms?
a. device driver
b. business application
c. embedded system
d. assembler
38. Which of the following best describes the relationship between assembly language and machine
language?
a. one to many
b. one to one

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

c. many to one
d. many to many
39. A program is considered portable if it . . .
a. can be rewritten in a different programming language without losing its meaning.
b. can be quickly copied from conventional RAM into high-speed RAM.
c. can be executed on multiple platforms.
d. none of the above
40. A device driver would ordinarily be written in . . .
a. machine language
b. assembly language
c. a platform-independent language, such as Java
d. an application-oriented language
41. Which of the following are embedded systems applications?
a. an accounting program
b. a javascript program running on a Web page
c. a Nintendo video game
d. a phone book searching program in a cellular phone
42. Suppose a program written in language L1 must be executed on a machine running a program
running in language L0. What important operation must take place?
a. translation of the entire L1 program into L0 code
b. translation of the L0 program into L1 code
c. creation of a language L3 that interprets L0 instructions
d. interpretation of each L1 statement using L0 code as the L1 program is running
43. Conventional machine language instructions are executed by which virtual machine level?
a. microarchitecture level
b. ISA level
c. assembly language level
d. operating system level
44. Which language (or virtual machine) uses short mnemonics such as ADD and SUB to identify
instructions?
a. conventional machine language
b. ISA-level language
c. assembly language
d. microcode interpreter
45. What is the largest unsigned integer that may be stored in 16 bits?
a. 32767

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

b. 65536
c. 65535
d. 32768
46. What is the largest signed integer that may be stored in 32 bits?
a. 232 1
b. 232
c. 231 1
d. 231
47. The two's complement of an integer is formed by doing which of the following?
a. reversing (inverting) the bits and adding 1
b. adding 1 and reversing the bits
c. calculating the integer's additive inverse
d. changing the highest bit to a 1
48. Which of the following unsigned decimal values is equivalent to binary 10110101 ?
a. 179
b. 181
c. 182
d. 175
49. Which of the following unsigned decimal values is equivalent to binary 11110000 ?
a. 216
b. 150
c. 240
d. 238
50. Which list contains the correct hexadecimal translation (in order) of the following unsigned
decimal integers? 33, 95, 257
a. 21, 5F, 101
b. 22, 5E, 11A
c. 6A, 5F, 101
d. 51, 149, 599
51. Which of the following signed decimal values is equivalent to binar 11110000 ?
a. 8
b. 16
c. 240
d. +240
52. Which of the following signed decimal values is equivalent to binar 00001111 ?

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

a.
b.
c. 15
d. +15
53. Which of the following binary values is equivalent to hexadecimal 4A2B?
a. 0100 1010 0010 1101
b. 0100 1010 0010 1011
c. 0100 1010 0010 1011
d. 0110 1011 0010 1001
54. Which of the following binary values is equivalent to hexadecimal 7CBE?
a. 0111 1101 1011 1110
b. 0111 1011 1011 1100
c. 0111 1100 1100 1110
d. 0111 1100 1011 1110
55. Which of the following is the binary translation of signed decimal 33 ?
a. 11011111
b. 10101011
c. 11001100
d. 11100011

Chapter 2 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

Fill in the Blanks and Short Answer


1

The technique of executing instructions in parallel is called ________.

56. Which unit in the IA-32 instruction cycle receives machine instructions from the BIU and inserts
them into the instruction queue?
57. Which unit in the IA-32 instruction cycle performs page protection checks?
58. Which component of an operating system is responsible for switching control between tasks?
59. Identify three types of segments that would be referenced by segment registers.
60. If you were to multiply 1.5 by 2.6, which part of the CPU would you use?
61. Name two RISC-like features incorporated by Intel into the IA-32 family.
62. In the Flat segmentation model, which table holds the addresses of segments?

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

63. List at least five types of ports found on a typical PC motherboard.


64. Which support processor synchronizes the CPU and the rest of the computer?
65. Which support processor transfers data to the printer?
66. Why are serial ports typically slower than parallel ports?

Multiple-Choice
67. Which two 32-bit registers are known as extended index registers?
a. SI, DI
b. EAX, EBX
c. ESI, EDI
d. EBP, ESP
68. What is the name of the lowest 8 bits of the EDX register?
a. DL
b. DH
c. DX
d. none of the above
69. How much memory can be addressed in Real-address mode?
a. 640 K
b. 1 MB
c. 16 MB
d. 4 GB
70. How much memory can be addressed in Protected mode?
a. 640 K
b. 1 MB
c. 16 MB
d. 4 GB
71. What special feature makes VRAM better-suited to use with a video adapter than DRAM?
a. VRAM uses static RAM
b. VRAM is dual-ported
c. VRAM does not require a refresh cycle
d. VRAM holds its memory when power is turned off
72. Which of the following linear addresses matches the segment-offset address 08F0:0200?
a. 09100h
b. 09200h
c. 0AF0h

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

d. 08F2h
73. Which type of I/O device uses the 16550 UART chip?
a. USB port
b. printer port
c. serial port
d. parallel port
74. If you wanted to turn a device on and off using computer software, which type of port interface
would be best?
a. USB
b. keyboard
c. serial
d. parallel
75. What is the name of the bus architecture commonly used with Pentium processors?
a. ISA
b. PCI
c. EISA
d. RAM-BUS
76. Segment-offset addressing is used in which processor mode(s)?
a. Protected
b. Virtual-8086
c. Real-address
d. System management
77. How is Virtual-8086 mode similar to Real-address mode?
a. permits the use of virtual memory (paging)
b. uses a segment descriptor table to track memory usage
c. uses only 16-bit registers for input-output
d. simulates 8086-based computer running in Real-address mode
78. High-speed memory that reduces the frequency of access by the CPU to conventional memory is
called
a. local memory
b. cache memory
c. system memory
d. virtual memory
79. Why are device drivers needed, given that BIOS programs can do the same task?
a. device drivers allow for the introduction of new devices
b. device drivers have faster performance than BIOS programs

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

c. BIOS programs are only used by the operating system in Real-address mode
d. device drivers have more direct access to hardware than BIOS programs
80. An interpreter program inside the CPU is written in a language called a(n) _______.
a. machine language interpreter
b. digital driver program
c. microprogram
d. system decoder
81. If you wanted to find out whether an integer contained an even number of 1 bits, which status flag
would be useful?
a. carry
b. overflow
c. sign
d. parity
82. In regard to multitasking, a task's state consists of which three elements?
a. status flags, program counter, register contents
b. register contents, task variables, program counter
c. task variables, segment descriptor, register contents
d. segment descriptor, status flags, task variables
83. Within the CPU, all calculations and logic operations take place inside the ___________ .
a. registers
b. ALU
c. CU
d. MBU
84. The three types of buses connected to the CPU are:
a. data, address, control
b. data, system, address
c. address, control, memory
d. fetch-decode, control, execution
85. If a clock oscillates 10 billion times per second, what is the duration of a single clock cycle?
a. 1 nanosecond
b. 1.0 x 10-9 seconds
c. 1.0 x 1010 seconds
d. 1.0 x 10-10 seconds
86. During which phase of the instruction execution cycle is the program counter incremented?
a. decode
b. execute

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

10

c. operand fetch
d. fetch
87. The control unit (CU) coordinates the sequencing of steps involved in executing machine
instructions.
a. True
b. False
88. The ALU performs only addition, subtraction, multiplication, and division operations.
a. True
b. False
89. Data travels along a bus one bit at a time.
a. True
b. False
90. The most basic unit of time for machine instructions is called the machine cycle.
a. True
b. False
91. The upper half of the EAX register is called AX.
a. True
b. False
92. The lower half of the EBX register is called BX.
a. True
b. False
93. The Overflow flag is based on signed arithmetic.
a. True
b. False
94. The Zero flag is clear when the result of an arithmetic operation is zero.
a. True
b. False
95. Registers in the floating-point unit are 80 bits long.
a. True
b. False
96. Microprograms are interpreted and executed by machine instructions.
a. True
b. False
97. In Real-address mode, only one program can run at a time.
a. True

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

11

b. False
98. In Virtual-8086 mode, only a single virtual machine can run at one time.
a. True
b. False
99. In the multi-segment model (Protected mode), each program is given its own local descriptor
table.
a. True
b. False
100.Segment limit and base address are both fields within a segment descriptor.
a. True
b. False
101.In Protected mode, the total memory used by all running programs can never be larger than the
computer's physical memory.
a. True
b. False
102.The four parts of a CPU are:
a. data bus, memory unit, control unit, arithmetic logic unit
b. address bus, registers, control unit, arithmetic logic unit
c. clock, memory unit, control unit, instruction fetch unit
d. clock, registers, control unit, arithmetic logic unit
103.What is the name of the time delay in a CPU caused by differences between the speed of the CPU,
the system bus, and memory circuits?
a. wait cycle
b. wait state
c. dead cycle
d. memory write cycle
104.List the three primary steps of the instruction execution cycle, in sequential order:
a. fetch, decode, memory write
b. fetch, memory read, execute
c. decode, fetch, execute
d. fetch, decode, execute
105.Which stage in the IA-32 instruction cycle is responsible for translating logical addresses to linear
addresses and performing protection checks?
a segment unit
b. code prefetch unit
c. execution unit

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

12

d. paging unit
106.What are the six stages, or units involved in executing a single IA-32 instruction?
a. code prefetch, instruction decode, execution, segment, paging, memory store
b. bus interface, instruction decode, parallel analysis, execution, segment, paging
c. bus interface, code prefetch, instruction decode, execution, segment, paging
d. bus interface, code prefetch, instruction decode, execution, address translation, paging
107.Which flag is set when an unsigned value is too large to fit into a destination operand?
a. Sign
b. Carry
c. Overflow
d. Auxiliary Carry
108.In a 4-stage non-pipelined processor, how many clock cycles are required to execute 3
instructions? (Assume that each stage executes in a single clock cycle.)
a. 12
b. 8
c. 6
d. cannot be determined
109.In a 4-stage single-pipelined processor, how many clock cycles are required to execute 3
instructions? (Assume that each stage executes in a single clock cycle.)
a. 12
b. 8
c. 6
d. cannot be determined
110.In a 6-stage dual-pipelined processor, how many clock cycles are required to execute 5
instructions? (Assume that stage 4 requires two clock cycles, and that stage 4 has two pipelines.)
a. 10
b. 11
c. 12
d. 15
111. Which of the following correctly describes the sequence of reading from memory during a single
clock cycle?
a.

Read line set low; Address placed on bus; Operand placed on data bus by memory
controller; Read line set high, indicating that data bus contains the requested data.

b.

Address placed on bus; Operand placed on data bus by memory controller; Read line set
low; Read line set high, indicating that data bus contains the requested data.

c.

Address placed on bus; Read line set low; Read line set high, indicating that data bus
contains the requested data; Operand placed on data bus by memory controller.

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

13

d.

Address placed on bus; Read line set low; Operand placed on data bus by memory
controller; Read line set high, indicating that data bus contains the requested data.

112.Which register is known as a loop counter?


a. EAX
b. EBX
c. ECX
d. EDX
113.Which mode is the native state of the Intel processor?
a. Protected mode
b. Virtual-8086 mode
c. Real-address mode
d. System management mode
114.Real-address mode combines which two values to form addresses?
a. page, segment
b. segment, offset
c. descriptor, segment
d. offset, descriptor
115.When the CPU tries to execute part of a program that has been swapped out to disk, it executes a
a. descriptor table load
b. general protection fault
c. page fault
d. page translation
116.What is the term used for executing horizontal and vertical retrace on a CRT video monitor?
a. digital delay
b. trace mapping
c. DAC (digital to analog conversion)
d. raster scanning
117.Which type of RAM is typically used for cache memory?
a. static RAM
b. dynamic RAM
c. CMOS RAM
d. Video RAM
(Some of the following questions have more than one correct answer. Circle all correct answers.)
118.Which of the following describe(s) RISC processors?
a. short, simple instructions, executed quickly

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

14

b. complex high-level instructions


c. requires microcode interpreter
d. instructions are executed directly by hardware
119.Which of the following is(are) advantages of USB ports over parallel ports?
a. bidirectional data transfer
b. query devices to get name and type of device
c. permits a hub to be connected
d. can suspend power to devices
120.Which type of output is the most general and portable to different computer systems?
a. writing directly to video memory
b. using C++ stream output statements
c. calling operating system functions
d. calling BIOS functions
121.Which type of output will execute the most quickly?
a. writing directly to video memory
b. using C++ stream output statements
c. calling operating system functions
d. calling BIOS functions

Chapter 3 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

Fill in the Blanks and Short Answer


1

Show an example of a valid hexadecimal integer constant.

122.Show an example of a valid 8-bit binary integer constant.


123.Show an example of an integer expression that performs both multiplication and modulus
arithmetic.
124.What is the order of operations in the expression 6 + 25 * 4 ?
125.A command that is recognized and executed by the assembler while the source code is being
assembled is a(n) __________.
126.A _________ is a word that has special meaning to the assembler and can only be used in its
correct context.
127.Identify two types of labels in assembly language programs.

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

15

128.Show an example of an instruction mnemonic.


129.Which directive enables block-style comments?
130.In the AddSub program in Section 3.2, which statement displays the contents of the registers?
131.In the AddSub program in Section 3.2, which directive marks the last line in the program?
132.In the AddSub program in Section 3.2, which directive copies necessary definitions and setup
information from a text file?
133.Which directive is used when defining signed 16-bit integers?
134.Which directive is used when defining unsigned 16-bit integers?
135.Which directive is used when defining signed 32-bit integers?
136.Which directive is used when defining unsigned 16-bit integers?
137.Which directive is used when defining 80-bit integers?
138.Which directive can by used in place of the BYTE directive for unsigned integers?
139.Write a data definition statement that creates a signed 16-bit integer named myWord and leaves
its contents uninitialized.
140.Which directive defines a segment containing only uninitialized data?
141.Declare a symbolic constant named COUNT that equals 25.
25)

COUNT = 25 (or COUNT EQU

142.Use COUNT from the previous question in a data definition statement that creates an uninitialized
array of 32-bit unsigned integers named myArray.
143.Given the following array definition, write a constant declaration named ArraySize that
automatically calculates the size in bytes, of the array:
newArray DWORD 10,20,30,40,50

Multiple-Choice
144.Which directive identifies the part of a program containing instructions?
a. .DATA
b. .CODE
c. .STACK
d. .PROG
145.Which directive(s) are used when defining both signed and unsigned 64-bit integers?
a. QWORD and SQWORD
b. DWORD
c. QWORD

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

16

d. DWORD and SDWORD


146.In the AddSub program in Section 3.2, the exit statement calls which predefined MS-Windows
function to halt the program?
a. HaltProgram
b. ExitProcess
c. OS_Return
d. Exit_Program
147.Which of the following are valid data definition statements that create an array of unsigned bytes
containing decimal 10, 20, and 30, named myArray.
a.
b.
c.
d.
148.In the following data definition, assume that List2 begins at offset 2000h. What is the offset of the
third value (5)?
List2 WORD 3,4,5,6,7
a.
b.
c.
d.
149.Which letter choice shows the memory byte order, from low to high address, of the following data
definition?
BigVal DWORD 12345678h
a.
b.
c.
d.
150.Given the following array definition, which letter choice contains a valid constant declaration
named ArrayCount that automatically calculates the number of elements in the array?
newArray DWORD 10,20,30,40,50
a.
b.
c.
d.
151.Select a data definition statement that creates an array of 500 signed doublewords named myList
and initializes each array element to the value 1.

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

17

a.
b.
c.
d.
152.Which of the following defines a text macro named MESSAGE that contains this string data?
"I'm good at this!",0
a.
b.
c.
d.
153.Which directive is used when defining 64-bit IEEE long reals?
a. REAL4
b. REAL8
c. REAL64
d. REAL
154.A character constant must be enclosed in single quotes.
a. True
b. False
155.An identifier in assembly language may not be more than 247 characters long.
a. True
b. False
156.An identifier may begin with a digit.
a. True
b. False
157.The following is a valid identifier: AB@62_$
a. True
b. False
158.The following is a valid identifier: AB62$ T
a. True
b. False
159.A label used for data must not end with a colon (:).
a. True
b. False
160.A code label always ends with a colon (:).
a. True

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

18

b. False
161.The PROC directive marks both the beginning and ending of a procedure.
a. True
b. False
162.The .CODE directive must always occur before the .DATA directive.
a. True
b. False
163.In the following statement, EAX is called the destination operand:
mov EAX,10000h
a. True
b. False
164.If the source code for an assembly language program is modified, you must run both the assembler
and linker to update the program's executable code.
a. True
b. False
165.The listing file does not contain a disassembly of each instruction.
a. True
b. False
166.The listing file contains a list of segments and groups in a program.
a. True
b. False
167.The listing file contains a list of program symbols.
a. True
b. False
168.The following is a valid data definition statement:
helloStr WORD 10000h,20000h
a. True
b. False
169.The following is a valid data definition statement:
helloStr DWORD 2
a. True
b. False
170.The following is a valid data definition statement:
str1 \
BYTE "This string is quite long!",0

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

19

a. True
b. False
171.The following are both valid data definition statements:
List1 BYTE 10,20
BYTE 30,40
a. True
b. False
172.The following sequence of statements is invalid:
.code
mov eax,edx
.data
myByte BYTE 10
.code
mov al,myByte
a. True
b. False
173.The EQU directive permits a constant to be redefined at any point in a program.
a. True
b. False
174.The TEXTEQU directive permits a constant to be redefined at any point in a program.
a. True
b. False
(Some of the following questions have more than one correct answer. Circle all correct answers.)
175.The two types of real-number constants are:
a. decimal, binary
b. encoded, binary
c. decimal, encoded
d. BCD, ASCII

176.Which of the following are true about assembly language instructions and directives?
a. a directive is executed at runtime
b. an instruction is executed at runtime
c. a directive is executed at assembly time
d. an instruction is executed at assembly time

177.The basic parts of an instruction, in order from left to right, are:

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

20

a. label, mnemonic, operand(s), comment


b. comment, label, mnemonic, operand(s)
c. label, mnemonic, comment
d. mnemonic, operand(s), comment

178.Operands may be any of the following:


a. constant or constant expression
b. reserved word
c. register name
d. variable name (memory)

179.Which utility program reads an assembly language source file and produces an object file?
a. compiler
b. linker
c. assembler
d. loader

180.A map file is produced by which of the following utility programs?


a. assembler
b. linker
c. loader
d. text editor

181.Which file(s) contain a human-readable listing of segment (and segment group) names?
a. listing
b. source
c. map
d. executable

182.Which of the following will generate assembly errors?


a. var1 BYTE 1101b, 22, 35
b. var2 BYTE "ABCDE",18
c. var3 BYTE '$','98778',
d. var4 BYTE 256,19,40

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

21

183.The byte-ordering scheme used by computers to store large integers in memory with the highorder byte at the lowest address is called:
a. big endian
b. byte-major
c. little endian
d. byte-minor

Chapter 4 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

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(?)

184.Write one or more statements that move the contents of word1 to word2.
185.For each of the following instructions, indicate whether it is legal (L) or illegal (I):
a.
b.
c.
d.

mov
mov
mov
mov

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

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

movzx
movzx
movzx
movsx

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

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

a.
b.
c.
d.

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

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

22

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

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

a.
b.
c.
d.

190.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=
b: ZF,CF,SF,OF=
c: ZF,CF,SF,OF=
d: ZF,CF,SF,OF=

191.Which instruction loads the low byte of the EFLAGS register into AH?
192.Write an instruction that moves the 32-bit address of word1 into the ESI register (assume 32-bit
Protected mode).
193.Write an instruction that moves the lower 16 bits of dword1 into the BX register (hint: use PTR).
194.Write an instruction that moves the lower 8 bits of word2 into the AL register.
195.Write an instruction that moves EBX to location word1:
196.What is the value of the expression (TYPE word1)?
197.What is the value of the expression (TYPE dword1)?
198.What is the value of the expression (LENGTHOF word1)?
199.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(?)

200.Implement the following expression in assembly language, using 32-bit integers (you may modify
any registers you wish):
eax = dword1 + ebx - ecx
201.Implement the following expression in assembly language, using 32-bit integers (you may modify
any registers you wish):
eax = -dword1 + (edx - ecx) + 1
202.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]

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

23

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

BYTE
BYTE

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

Multiple-Choice
204.The following statement will assemble without errors:
mov WORD PTR [eax], 1234h
a. true
b. false
205.The following instruction will produce FFFFFFFCh in EAX:
movsx eax,-4
a. true
b. false
206.The SAHF instruction copies the Sign, Overflow, and Carry flags to the AL register.
a. true
b. false
207.The following instructions will set the Overflow flag:
mov al,0D7h
add al,74h
a. true
b. false
208.The following instruction will assemble:
inc [esi]
a. true
b. false
209.The following instructions will set the Overflow flag:
mov al,125
sub al,-4
a. true
b. false
210.The syntax for the MOV instruction is: MOV destination, source.
a. true
b. false
211.The MOV instruction requires both operands to be the same size.
a. true
b. false
212.The MOV instruction permits a move between two memory operands.
a. true

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

24

b. false
213.The EIP register cannot be the destination operand of a MOV, ADD, or SUB instruction.
a. true
b. false
The MOV instruction does not permit an immediate value to be moved to a segment register.
a. true
b. false
214.The MOVZX instruction can use a variable as the destination operand.
a. true
b. false
215.The MOVSX instruction sign-extends an integer into a larger operand.
a. true
b. false
216.The DS register can be the destination operand of a MOV instruction.
a. true
b. false
217.The ES register can the source operand of a MOV instruction.
a. true
b. false
218.The SAHF instruction copies the EFLAGS register into a 32-bit memory location.
a. true
b. false
219.The INC instruction does not affect the Carry flag.
a. true
b. false
220.If AL contains +127 and you add 3 to AL, the Overflow flag will be set.
a. true
b. false
221.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
222.The Overflow flag may be set when adding a positive integer to a negative integer.
a. true
b. false
223.The following instruction is legal: inc [esi]
a. true

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

25

b. false
224.Adding 7Fh and 05h in an 8-bit register sets the Overflow flag.
a. true
b. false
225.Adding 0FFh and 05h in an 8-bit register sets the Overflow flag.
a. true
b. false
226.Adding 5 to 0FBh in an 8-bit register sets the Zero flag.
a. true
b. false
227.The following instructions will set the Carry flag:
mov al,0FEh
sub al,2
a. true
b. false
228.The following instructions will set the Sign flag:
mov al,0FEh
sub al,2
a. true
b. false
229.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

b.

c.

d.
mov eax,dword1
mov edx,ebx

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

26

sub ebx,ecx
add eax,ebx
inc eax
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(?)

230.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
231.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
232.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
233.What is the final hexadecimal value of EAX when this code executes?
mov edx,8
mov eax,dword1[edx]
a. 00000010h
b. 20000000h

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

27

c. 00300000h
d. 00000030h
234.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
235.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 ?

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

236.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
237.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
c. 6, 7, 8
d. 7, 8, 9
238.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

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

28

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

Use the following data for the remaining questions in this section:
word1 WORD 1000h,2000h,3000h,4000h,5000h
dword1 DWORD 10000h,20000h,30000h,40000h
239.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
240.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
241.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:

mov

eax,[edi]

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

29

4:
5:

L1: add
add

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

3:
4:
5:

mov
L1: add
add

DWORD PTR [edi],0


eax,[edi]
edi,TYPE dword1

b.

c.

d.

Chapter 5 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

True/False
1

A link library contains procedures that have already been assembled into object code.

242.The PROTO directive is required when calling a library procedure.


243.The assembler knows the exact address of a library procedure.
244.The linker combines object files into an executable file.
245.The Irvine32.lib procedures cannot link directly to kernel32.lib
246.Kernel32.dll is called a dynamic link library.
247.Real-mode programs should link to Irvine16.lib.
248.The ReadString procedure inserts a carriage return (0Dh) at the end of the input string.
249.The ReadChar procedure echoes the input character on the screen.
250.The Random32 procedure limits the largest random number to 0FFFFh
251.The WriteBin procedure does not display leading zeros.
252.The WriteHex procedure does not display leading zeros.
253.The WriteDec procedure does not display a minus sign.
254.The first value added to a stack is also the first one to be removed.
255.The runtime stack is managed by the CPU and supporting hardware.
256.The SS register points to the last value pushed on the stack.
257.When using the Irvine32 library, you should always push 32-bit values on the stack.
258.The POP instruction copies a value from the stack to an operand before incrementing the stack
pointer.
259.In Protected mode, immediate values pushed on the stack are always 32 bits long.
260.The PUSHA instruction pushes all the 32-bit general-purpose registers on the stack.

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

30

Fill in the Blanks and Short Answer


261.Which file acts as a bridge between Irvine32.lib and kernel32.dll?
262.Which I/O device is used for standard input?
263.Which library procedure writes a single character to standard output?
264.Which library procedure locates the cursor at a specific row and column on the screen?
265.Which library procedure reads a 32-bit signed decimal integer from standard input?
266.Which library procedure displays the CPU flags and 32-bit registers?
267.Which library procedure generates a 32-bit pseudorandom integer in a caller-specified range?
268.Which library procedure writes an unsigned 32-bit integer to standard output in hexadecimal
format?
269.Which library procedure reads a string from standard input?
270.Which register contains the offset of a character array when calling GetCommandTail?
271.Which register contains an integer before calling WriteDec?
272.Which register contains the starting address of data when calling DumpMem?
273.Write code that causes a 500 millisecond delay, using a library procedure.
274.Write a statement that moves a video color constant to EAX. The constant should represent black
text on a white background, using the constants described in the Irvine32.inc file.
275.What will be the value of EAX when the following sequence of instructions has executed?
push 5
push 10
push 20
pop eax
276.What will be the value of EAX when the following sequence of instructions has executed?
push 5
push 10
pop ebx
pop eax
277.What will be the value of ECX when the following sequence of instructions has executed?
push 5
push 10
pop ebx
pop eax
pop ecx

Short Programming Problems


278.Write a sequence of statements that read a signed integer from standard input and write the same
integer to standard output. Use library procedures.
279.Given the following string definition, write a sequence of statements that write the string to
standard output. Use a library procedure.
str1 BYTE "Display this string",0
280.Given the following data definition, write a sequence of statements that display a dump of the data
in 32-bit hexadecimal, using the DumpMem procedure from the link library.
array DWORD 10h,20h,30h,40h

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

31

281.Write statements that use library procedures to generate a single unsigned pseudorandom integer
between 0 and 999 and write it to standard output:
282.Write a procedure named ShowBinary that displays the following array as a sequence of binary
bits. Include the use of the LENGTHOF, OFFSET, and TYPE operators, and call the WriteBin
procedure.
array DWORD 10h,20h,30h,40h
283.Write a procedure named Read10 that reads exactly ten characters from standard input into an
array of BYTE named myString. Use the LOOP instruction with indirect addressing, and call the
ReadChar procedure from the book's link library. (ReadChar returns its value in AL.)
284.Code a PROC declaration for a procedure named MySub. Use the USES operator to preserve the
EAX and EBX registers.
285.Draw a flowchart that corresponds to the following code:
mov ecx,LENGTHOF array
mov eax,0
mov esi,OFFSET array
L1: add eax,[esi]
add esi,TYPE array
loop L1
mov sum,eax

Multiple-Choice
(Some of the following questions have more than one correct answer. Circle all correct answers.)
286.Which of the following CALL instructions writes the contents of EAX to standard output as a
signed decimal integer?
a. call WriteInteger
b. call WriteDec
c. call WriteHex
d. call WriteInt
287.Which of the following code sequences assigns the value 10h to EBX?
a.
mov
push
mov
push
pop
pop

edx,20h
edx
ecx,10h
ecx
ebx
edx

mov
mov
push
push
pop
pop

ecx,10h
edx,20h
ecx
edx
ebx
edx

b.

c.
push 20h
mov ecx,10h
push ecx

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

32

pop
pop

eax
ebx

push
push
push
pop
pop
pop

30h
10h
20h
edx
ebx
eax

d.

288.The process of dividing a problem into general tasks, and then separating general tasks into more
specific tasks is called . . .
a. process-oriented design
b. functional decomposition
c. top-down design
d. object-oriented design
289.Which of the following are valid design criteria for the Integer Summation Program (Section 5.6)?
a. separate procedures make the program run faster
b. separate procedures make the program's structure easier to understand
c. LOOP instructions might be out of range if all code were placed in the main procedure
d. the program is easier to maintain and understand when all the code is in a single procedure
290.Which of the following are true about the PUSH instruction?
a. It decrements the stack pointer (by 2 or 4) and copies the operand into the stack at the location
pointed to by the stack pointer.
b. It copies the operand into the stack at the location pointed to by the stack pointer, and then
decrements the stack pointer (by 2 or 4).
c. It increments the stack pointer (by 2 or 4) and copies the operand into the stack at the location
pointed to by the stack pointer.
d. It increments the stack pointer by 1 and copies the operand into the stack at the location pointed
to by the stack pointer.

Chapter 6 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

True/False
1

For any two integers n and m, ((n XOR m) XOR m) produces n.

291.The AND instruction has only one operand.


292.The TEST instruction does not alter the destination operand.
293.The OR instruction can be used to set an operand's value to zero.
294.The XOR instruction can be used to toggle (complement) the bits in a number.
295.The OR instruction modifies the Sign, Zero, and Parity flags according to the value of the
destination operand.
296.The Parity flag indicates whether the lowest word of a destination operand has an even number of
1 bits.

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

33

297.The NOT instruction reverses the sign of a number.


298.The JB instruction jumps if the (unsigned) first operand is less than the (unsigned) second
operand.
299.The JG instruction is used when comparing unsigned integers.
300.The JO instruction is used after an operation involving signed integers.
301.The JCXZ instruction jumps to a target label when the ECX register is equal to zero.
302.The BTR instruction copies a selected bit into the Carry flag and clears the selected bit.
303.The BT instruction copies a selected bit into the Zero flag.
304.The LOOPZ instruction jumps to a target label when the Zero flag is set and ECX is greater than
zero.
305.A WHILE loop can be constructed with a CMP instruction at the bottom of the loop, followed by a
conditional jump instruction.
306.In a finite-state machine, transitions between states usually occur when a new value has been read
from input.
307.The following finite-state machine could be used to successfully validate the string "234+":

digit

C
digit
start

+,-

digit

Fill in the Blanks and Short Answer


308.In the following instruction sequence, show the changed values of AL where indicated, in binary:
mov
and
mov
and
mov
or
mov
xor

al,11001111b
al,00101011b
al,4Bh
al,6Ch
al,00111100b
al,82h
al,94h
al,37h

; a.
; b.
; c.
; d.

309.In the following instruction sequence, show the changed values of AL where indicated, in
hexadecimal:
mov
not
mov
and
mov
or
mov
xor

al,9Ch
al
al,4Bh
al,74h
al,86h
al,42h
al,72h
al,0A5h

; a.
; b.
; c.
; d.

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

34

310.In the following instruction sequence, show the values of the Carry, Zero, and Sign flags where
indicated:
mov al,00110011b
test al,2
mov al,6
cmp al,5
mov al,5
cmp al,7

; a. CF=

ZF=

SF=

; b. CF=

ZF=

SF=

; c. CF=

ZF=

SF=

311.Code a single instruction that clears bits 0, 3, and 4 in the AL register.


312.Code instructions that jump to the label L1 when either bit 2 or 3 is set in the DL register (do not
modify DL).
313.Code instructions that jump to the label L2 when the signed integer in BL is greater than 5.
314.Code a single instruction that complements all bits in AL, without using the XOR instruction.
315.Code instructions that jump to label L3 when the AX register has even parity.
316.Code a single instruction that inverts bits 5 and 6 in BL without changing any other bits.
317.Code instructions that jump to label L4 if bits 1, 2, and 3 are all set in the DL register.
318.Code a label named Here that can be the target of a jump instruction originating in a different
procedure.
319.Code instructions that jump to label L5 when the BL register has odd parity. Do not alter the value
in BL.
320.Code instructions that set the Overflow flag. Then code a jump instruction that jumps to label L6
when the Overflow flag has been set.
321.Code instructions that implement the following pseudocode using conditional jump instructions.
Do not use the .IF directive. Assume that integers are unsigned:
if( eax > ebx )
mov dl,5;
else
mov dl,6;

Multiple-Choice
322.What will be the hexadecimal value of AL after these instructions execute?
mov al,0CFh
and al,2Bh
a. 0Bh
b. EAh
c. 06h
d. none of the above
323.What will be the hexadecimal value of AL after these instructions execute?
mov al,3Ch
or al,82h
a. 3Eh
b. BCh
c. BEh

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

35

d. none of the above


324.What will be the hexadecimal value of AL after these instructions execute?
mov al,94h
xor al,37h
a. B7h
b. A3h
c. 3Fh
d. none of the above
325.Which answer choice shows the correct values of the Carry, Zero, and Sign flags after the
following instructions execute?
mov al,00110011b
test al,2
a. CF = 1, ZF = 0, SF = 1
b. CF = 0, ZF = 1, SF = 0
c. CF = 1, ZF = 0, SF = 1
d. CF = 0, ZF = 0, SF = 0
326.Which answer choice shows the correct values of the Carry, Zero, and Sign flags after the
following instructions execute?
mov al,6
cmp al,5
a. CF = 0, ZF = 0, SF = 0
b. CF = 1, ZF = 0, SF = 0
c. CF = 1, ZF = 1, SF = 0
d. CF = 1, ZF = 0, SF = 1
327.Which of the following selections contain instructions that jump to label L4 if bits 1, 2, and 3 are
all set in the DL register?
a.
and dl,0Eh
test dl,0Eh
jnz L4
b.
test dl,0Eh
jnz L4
c.
and dl,07h
cmp dl,07h
je L4
d.
and dl,0Eh
cmp dl,0Eh
je L4
328.Which choices contain correct implementations of the following pseudocode? (Assume that all
values are unsigned):

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

36

if( eax > ebx )


mov dl,5;
else
mov dl,6;
a.
cmp
ja
mov
jmp
L1: mov
L2:

eax,ebx
L1
dl,6
L2
dl,5

cmp
ja
mov
jmp
L1: mov
L2:

eax,ebx
L1
dl,5
L2
dl,6

cmp
jbe
mov
jmp
L1: mov
L2:

eax,ebx
L2
dl,5
L2
dl,6

cmp
jna
mov
jmp
L1: mov
L2:

eax,ebx
L1
dl,5
L2
dl,6

b.

c.

d.

Use the following data for the next two questions. All values are signed:
.data
val1 SDWORD ?
val2 SDWORD ?
329.Which selection is the correct implementation of the following pseudocode?
if( val1 > val2 || val2 > eax )
mov ebx,1;
else
mov ebx,2;
a.
mov val1,ebx
cmp ebx,val2
jng L1
cmp
jg
mov
jmp

val2,eax
L1
ebx,2
L2

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

37

L1: mov ebx,1


L2:
b.
mov
cmp
jg
cmp
jg
mov
jmp
L1: mov
L2:

val1,ebx
ebx,val2
L1
val2,eax
L1
ebx,2
L2
ebx,1

mov
cmp
jg
cmp
jg

val1,ebx
val2,ebx
L1
val2,eax
L2

c.

mov ebx,2
jmp L2
L1: mov ebx,1
L2:
d.
mov
cmp
jle
cmp
jle
mov
jmp
L1: mov
L2:

val1,ebx
ebx,val2
L1
val2,eax
L1
ebx,1
L2
ebx,2

330.Which selection correctly implements the following pseudocode?


while( int2 >= int1 )
{
add ebx,2
if( ebx > int2)
mov ebx,0
else
mov ebx,int1
}
a.
top:

mov eax,int2
cmp eax,int1
jnge L3
add ebx,2
cmp ebx,int2
jg L2
mov ebx,int1
jmp L3
L1: mov ebx,0

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

38

L2: jmp top


L3:
b.
top:
mov
cmp
jl
add
cmp
jg
mov
jmp
L1: mov
L2: jmp
L3:

eax,int1
eax,int2
L3
ebx,2
ebx,int2
L1
ebx,int1
L2
ebx,0
top

c.
top:

mov
cmp
jl
add
cmp
jg
mov
jmp
L1: mov
L2: jmp
L3:

eax,int2
eax,int1
L3
ebx,2
ebx,int2
L1
ebx,int1
L2
ebx,0
top

d.
top:

mov
cmp
jl
add
cmp
jg
mov
jmp
L1: mov
L2: jmp
L3:

eax,int2
eax,int1
L3
ebx,2
ebx,int2
L1
ebx,0
L2
ebx,int1
top

331.Suppose EAX, EBX, and ECX contained three unsigned integers. Which of the following code
excerpts would display the largest of the three integers?
a.
cmp eax,ebx
jb L1
mov eax,ebx
L1: cmp eax,ecx
jb L2
mov eax,ecx
L2: call WriteInt
b.
cmp eax,ebx

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

39

jae L1
mov eax,ebx
L1: cmp eax,ecx
jae L2
mov eax,ecx
L2: call WriteInt
c.
cmp eax,ebx
jnae L1
mov eax,ebx
L1: cmp ecx,eax
jnae L2
mov eax,ecx
L2: call WriteInt
d.
cmp
jae
mov
L1: cmp
jae
mov
L2:

eax,ecx
L1
eax,ebx
eax,ebx
L2
eax,ecx
call WriteInt

332.What will be the final value of ESI when the following code executes?
.data
array SWORD 8,2,3,5,-4,6,0,4
.code
mov esi,0
mov ecx,LENGTHOF array
L1: mov ax,array[esi]
cmp ax,0
pushf
add esi,TYPE array
popf
Loopne L1
a. 00000006h
b. 00000007h
c. 0000000Ch
d. 0000000Eh
333.What will be the final values of CX and DX when the following code executes?
.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

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

40

L1: mov cx,4


L2: mov dx,5
jmp L4
L3: mov dx,6
L4:
a. CX = 4, DX = 5
b. CX = 1, DX = 6
c. CX = 1, DX = 5
d. CX = 4, DX = 6
334.In Protected mode (flat model), which of the following CALL instructions executes an indirect call
to a procedure whose address is stored in a memory location pointed to by EBX?
a. call [ebx]
b. call DWORD PTR [ebx]
c. call FAR [ebx]
d. call NEAR PTR [ebx]

Chapter 7 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

True/False
1

The SHR instruction is suitable only for unsigned integers.

335.The SHL instruction is suitable only for unsigned integers.


336.The SAR and SHR instructions perform the same operation.
337.The MUL instruction sets the Overflow flag if the upper half of the product is equal to zero.
338.The MUL instruction sets the Carry flag if the upper half of the product is not equal to zero.
339.When the MUL CL instruction executes, the 16-bit product ends up in the AX register.
340.When the MUL BX instruction executes, the 32-bit product ends up in the EAX register.
341.The IMUL instruction performs signed integer multiplication.
342.The DIV instruction sets the Overflow flag when a program attempts to divide by zero.
343.The following code will cause a Divide Overflow exception:
mov ax,-12000000
cwd
mov bx,10
idiv bx

Fill in the Blanks and Short Answer


344.What is the binary value of AL after the following instructions have executed?
mov al,01101011b
shr al,2
345.What is the binary value of AL after the following instructions have executed?

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

41

mov al, 01101011b


rol al,2
346.What is the binary value of AL after the following instructions have executed?
mov al,11000101b
sar al,1
347.What is the binary value of AL after the following instructions have executed?
mov al,11000101b
sar al,4
348.What is the binary value of AL after the following instructions have executed?
mov al,10000101b
clc
rcr al,1
349.What is the binary value of AL after the following instructions have executed?
mov al,01101011b
stc
rcl al,2
350.What is the binary value of AX after the following instructions have executed?
mov ax,0000000010011101b
mov bx,1010101010000000b
shld ax,bx,1
351.What is the binary value of AX after the following instructions have executed?
mov ax,0000000010011101b
mov bx,1010101010001011b
shrd ax,bx,2
352.What will be the hexadecimal values of DX and AX after the following instructions have
executed?
mov dx,5000h
mov ax,10h
mul dx
353.What will be the value of the Overflow flag after the following instructions have executed?
mov dx,800h
mov ax,10h
imul dx
354.What will be the hexadecimal values of DX and AX after the following instructions have
executed?
mov dx,-16
mov ax,2
imul dx
355.What will be the hexadecimal values of DX and AX after the following instructions have
executed?
mov
mov
mov
div

dx,000Fh
ax,6342h
bx,100h
bx

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

42

Short Programming Problems


356.Write a series of instructions that will multiply EAX by 18, using a combination of shift, MOV,
and ADD instructions.
357.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.
358.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.
359.Write a sequence of instructions that divide 16 by 5, using the IDIV instruction. Use the EBX
register as the divisor.

Multiple-Choice
(Some of the following questions have more than one correct answer. Circle all correct answers.)
360.Suppose we want to copy the value of the Carry flag into bit 7 of AL, and shift all existing bits in
AL one position to the right. Which of the following instructions will work?
a. shr al,1
b. sar al,1
c. ror al,1
d. rcr al,1
361.Suppose we want to convert the value 6Fh in AL to the value F6h. Which of the following
instructions will do this?
a. ror al,3
b. rol al,4
c. ror al,4
d. rcr al,4
362.Which of the following instructions will divide the unsigned integer in EBX by 8?
a. shr ebx,8
b. shr ebx,3
c. sar ebx,8
d. shl ebx,3
363.Which of the following instructions will multiply the integer in EBX by 32?
a. shr ebx,5
b. rol ebx,32
c. shl ebx,5
d. ror ebx,32
364.What will be the hexadecimal values of DX and AX after the following instructions have
executed?
mov ax,6B49h
mov dx,0095h
shl ax,1
rcl dx,1

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

43

a. DX = 0148h, AX = C691h
b. DX = 012Ah, AX = C9A2h
c. DX = 012Ah, AX = D692h
d. DX = 024Bh, AX = D692h
365.Given the following two assignments to AX and DX, which block of instructions will cause DX to
equal 4025h and AX to equal 1AD2h?
mov ax,6B49h
mov dx,0095h
a.
shr
rcr
shr
rcr

ax,1
dx,1
ax,1
dx,1

b.
shr ax,2
rcr dx,1
shl ax,1
c.
shl ax,2
shr dx,1
rcl dx,1
d.
shr
rcl
rcr
shl

ax,1
dx,2
ax,1
dx,1

366.Which of the following blocks of instructions will multiply the contents of the EDX register by
36?
a.
mov
shl
shl
add

ebx,edx
edx,5
ebx,2
ebx,edx

mov
shl
shl
add

ebx,edx
edx,5
ebx,2
edx,ebx

mov
add
shl
shl
add

ebx,4
edx,ebx
edx,2
ebx,5
edx,ebx

mov
shl
shl
add

ebx,edx
ebx,5
edx,2
edx,ebx

b.

c.

d.

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

44

367.Given that EAX contains FFFF80C0h, which of the following would be true after executing the
CWD instruction?
a. AX=FFFFh, DX=80C0h
b. EDX=FFFFFFFFh, EAX=FFFF80C0h
c. DX=FFFFh, AX=80C0h
d. cannot be determined
368.What will be the hexadecimal values of DX and AX after the following instructions have
executed?
mov ax,123456h
mov dx,0
mov bx,10h
div bx
a. DX=0006h, AX=2345h
b. DX=1234h, AX=0056h
c. DX=0056h, AX=1234h
d. cannot be determined
369.What will be the hexadecimal values of DX and AX after the following instructions have
executed?
mov ax,123456h
mov dx,0
mov bx,10h
div bx

Chapter 8 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

Short Programming Problems


1

Write a procedure named UseThree that has three unsigned integer stack parameters: a byte, a
word, and a doubleword.

370.Add a local variable named var1 of type DWORD to the UseThree procedure from the previous
question.
371.Show the entry code generated by the assembler for the UseThree procedure (in the previous
question).
372.Suppose we define the following procedure:
Example2 PROC,
one:DWORD, two:DWORD
mov eax,one
mov ebx,[ebp+12]
call DumpRegs
ret
Example2 ENDP
If we called Example2 using the following statement, what values would be displayed in EAX
and EBX?
INVOKE Example2, 10h, 20h

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

45

Multiple-Choice
(Some of the following questions have more than one correct answer. Circle all correct answers.)
373.Which of the following are true regarding local variables?
a. They make efficient use of memory because their storage space can be released.
b. They can be accessed from anywhere inside the same source code module.
c. They are usually created in the data segment
d. The same variable name can appear in two different procedures
374.How are static variables distinguished from global variables?
a. Global variables are visible from all procedures in the source code file.
b. Static variables have a shorter lifetime than global variables.
c. The lifetime of a static variable is the same as the lifetime of its program.
d. Static variables are created on the stack, using the ESP and EBP registers.
375.The following is a valid LOCAL declaration:
LOCAL pArray:DWORD PTR
a. true
b. false
376.The following is a valid LOCAL declaration:
LOCAL SwapFlags:BYTE[5]
a. true
b. false
377.The following is a valid LOCAL declaration:
LOCAL count:DWORD
a. true
b. false
378.The following is a valid LOCAL declaration:
LOCAL DWORD:count
a. true
b. false
379.Which of the following shows the procedure entry code generated by MASM when the LOCAL
directive is used to declare a doubleword variable?
a.
mov ebp,esp
push ebp
sub esp,4
b.
push ebp
mov esp,ebp
add esp,4
c.

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

46

push ebp
mov ebp,esp
sub esp,4
d.
push ebp
mov ebp,esp
add esp,4
380.Which of the following defines an array local variable consisting of 50 signed words?
a. LOCAL wArray[50]:SWORD
b. LOCAL wArray:SWORD[50]
c. LOCAL SWORD[50]:wArray
d. LOCAL SWORD:wArray[50]
381.What advantages do stack parameters have over register parameters?
a. Stack parameters reduce code clutter because registers do not have to be saved and restored.
b. Programs using stack parameters execute more quickly.
c. Stack parameters are compatible with high-level languages.
d. Register parameters are optimized for speed.
382.What advantages does INVOKE offer over the CALL instruction?
a. None. INVOKE is just a synonym for CALL.
b. INVOKE permits you to pass arguments separated by commas.
c. CALL does not require the use of the PROTO directive.
d. INVOKE executes more quickly than CALL.
383.Which of the following INVOKE statements are invalid?
a. INVOKE mySub, [array+2]
b. INVOKE mySub, 30
c. INVOKE mySub, ADDR myList
d. INVOKE mySub, PTR myList
384.Which of the following are true regarding the ADDR operator?
a. ADDR makes it possible to pass arguments by reference.
b. ADDR passes a pointer on the stack.
c. ADDR always passes parameters by value.
d. ADDR is not permitted in Real-mode programs.
385.In programs that use the flat memory model, ADDR and OFFSET return the same value.
a. true
b. false
386.The CALL instruction can accept a maximum of two arguments.
a. true
b. false

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

47

387.An indirect operand such as [EBX] can be an argument passed to the INVOKE directive.
a. true
b. false
388.Which of the following PROC statements are invalid?
a.
MySub PROC val1:WORD, val2:DWORD
b.
MySub PROC, val1:WORD, val2:DWORD PTR
c.
MySub PROC, val1:BYTE,
val2:SDWORD
d.
MySub PROC, val1:PTR WORD,
val2:DWORD
389.Which of the following PROTO statements are invalid?
a.
MySub PROTO,
val1:WORD,
val2:DWORD
b.
MySub PROTO USES eax,
val1:WORD,
val2:DWORD
c.
MySub PROTO USES eax ebx,
val1:WORD,
val2:DWORD
d.
MySub PROTO,
val1:WORD,
val2:DWORD
LOCAL v1:BYTE
390.When saving and restoring registers with PUSH and POP, which of the following are common
mistakes?
a. The operand order is the same between PUSH and POP, as in:
push eax
push ebx
...(some other code)
pop eax
pop ebx
b. The operand order is reversed in POP, as in:
push eax
push ebx
...(some other code)
pop ebx
pop eax
c. PUSH is coded before a loop begins, but the corresponding POP is inside the loop.

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

48

d. Both PUSH and its corresponding POP occur within the same loop.
391.The assembler checks the pointer type used with the ADDR operator against the pointer type
declared in the PROC directive. For example, this prevents a pointer to DWORD from being
passed to a procedure expecting an pointer to BYTE.
a. true
b. false
392.An alternate term for stack frame is _______.
a. parameter frame
b. activation record
c. procedure execution frame
d. parameter save area
393.Assuming that a procedure contains no local variables, a stack frame is created by which sequence
of actions at runtime?
a. arguments pushed on stack; procedure called; EBP pushed on stack; EBP set to ESP
b. EBP pushed on stack; arguments pushed on stack; procedure called; EBP set to ESP
c. arguments pushed on stack; EBP pushed on stack; EBP set to ESP; procedure called
d. arguments pushed on stack; procedure called; EBP set to ESP; EBP pushed on stack
394.Which action must take place inside a procedure to reserve space on the stack for two doubleword
local variables?
a. after PUSH EBP, subtract 8 from the base pointer (EBP)
b. after PUSH EBP, add 8 to the base pointer (EBP)
c. after MOV EBP,ESP, add 8 to the stack pointer (ESP)
d. after MOV EBP,ESP, subtract 8 from the stack pointer (ESP)
395.Which memory model uses 32-bit offsets for code and data?
a. small
b. large
c. flat
d. huge
396.Which of the following are valid language specifiers in the .MODEL directive?
a. PASCAL, FORTRAN, C
b. C, SYSCALL, STDCALL
c. BASIC, JAVA, C
d. C, ADA, SYSCALL
397.Which language specifiers in the .MODEL directive dictate that procedure arguments be pushed
on the stack in reverse order?
a. C
b. PASCAL
c. STDCALL
d. none of the above

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

49

398.Which of the following are true about the C language specifier in the .MODEL directive?
a. The RET instruction removes parameters from the stack.
b. The calling program removes parameters from the stack.
c. Inside the procedure, the POP instruction removes parameters from the stack before RET
executes.
d. After the CALL instruction, a constant value is added to ESP to remove parameters from the
stack.
399.Which of the following are true about stack parameters?
a. All are expressed as positive offsets from EBP.
b. All are expressed as negative offsets from EBP.
c. They are located at higher addresses than local variables.
d. none of the above
400.How does using the LEA instruction differ from using the OFFSET operator with MOV?
a. LEA cannot have an indirect source operand, whereas MOV-OFFSET can.
b. MOV-OFFSET retrieves a 32-bit offset, whereas LEA retrieves a combined segment-offset
address.
c. LEA is effective for obtaining the address of a stack parameter.
d. The source operand used by LEA must be a constant value known at assembly time.
401.If a procedure recursively calls itself millions of times, what is the likely result?
a. The program will continue to run until interrupted by the user.
b. The number of recursive calls will be limited by the value placed in the RL (recursion limiter)
register.
c. The amount of memory usage will be constant, because the procedure is simply branching to its
own offset.
d. The stack will overflow.
Example 1: The MySub Procedure
MySub PROC, N:DWORD
cmp N,7
je L1
mov eax,N
inc eax
INVOKE MySub,eax
L1: ret
MySub ENDP
402.Consider the procedure named MySub in Example 1. Which of the following statements are true?
a. MySub uses 4 doublewords of stack space each time it is called.
b. MySub is recursive
c. MySub terminates when N is equal to 7.
d. the parameter N is equivalent to [EBP+4]
403.Consider the MySub procedure from the previous question. If it were called with N = 5, how
many times would the RET instruction execute?

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

50

a. 2 times
b. 3 times
c. 4 times
d. 5 times
404.If we were to expose the code generated by MASM for MySub in Example 1, which of the
following would match that code most closely?
a.
MySub PROC
push ebp
cmp DWORD PTR [ebp+4],7
je
L1
inc eax
mov eax,[ebp+4]
push eax
call MySub
L1:
pop ebp
ret
MySub ENDP
b.
MySub PROC
push ebp
mov ebp,esp
cmp DWORD PTR [ebp+8],7
je
L1
mov eax,[ebp+8]
inc eax
push eax
call MySub
L1:
pop ebp
ret 4
MySub ENDP
c.
MySub PROC
mov ebp,esp
cmp DWORD PTR [ebp+8],7
je
L1
mov eax,[ebp+8]
push eax
inc eax
call MySub
L1:
ret 4
MySub ENDP
d.
MySub PROC
cmp DWORD PTR [ebp+8],7
je
L1
mov eax,[ebp+8]
inc eax
push eax

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

51

call MySub

L1:

ret 4
MySub ENDP
Example 2: The Accum Procedure
main PROC
mov
push
call
call
exit
main ENDP
Accum PROC
push
mov
mov
cmp
je
add
sub
push
call
L1:
pop
ret
Accum ENDP

eax,0
8
Accum
DumpRegs

ebp
ebp,esp
ebx,[ebp+8]
ebx,2
L1
eax,ebx
ebx,2
ebx
Accum
ebp
4

405.Refer to Example 2. What will be the value of EAX when DumpRegs is called?
a. 8
b. 0Ah
c. 12h
d. 14h
406.Refer to Example 2. What will be the value of EBX when DumpRegs is called?
a. 2
b. 4
c. 6
d. 8
407.Refer to Example 2. How many stack bytes are used by each call to Accum?
a. 4 bytes
b. 8 bytes
c. 12 bytes
d. 16 bytes
408.Refer to Example 2. How many times will the ADD EAX,EBX statement execute?
a. 2
b. 3
c. 4

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

52

d. cannot be determined
409.Refer to Example 2. Suppose we changed the last statement in the Accum procedure to the
following:
ret

What would happen when running the program?


a. The program would run in the same manner.
b. The program would halt with a runtime error.
c. When DumpRegs was called, EAX would be smaller than before.
d. The PUSH EBX instruction would execute two times.

Chapter 9 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text.

Short Programming Problems


1

Using the following definition of a two-dimensional array, write a sequence of instructions that
use a base-index operand to move the element at row 2, column 3 to AX. (Row and column
numbers begin at 0):
.data
ROWSIZE = 5
NUMROWS = 4
twArray WORD NUMROWS DUP( ROWSIZE DUP(?) )

410.Using the following data definitions, write instructions that use MOVSB to copy all the bytes from
source to target:
.data
source BYTE 50 DUP(?)
target BYTE 100 DUP(?)
411.Write a sequence of instructions using MOVSB that append source to the end of target. The first
three instructions have been written for you:
.data
source BYTE "HIJKLMNOPQRS",0
target BYTE "ABCDEFG",50 DUP(0)
.code
INVOKE Str_length, ADDR target
mov edi,OFFSET target
add edi,eax
412.Write a sequence of instructions that use SCASD to search arrayD for the first value that is not
the same as the current contents of EAX. When the search is completed, move the value you have
found into EAX:
arrayD SDWORD 50 DUP(?)
413.Write a sequence of instructions that use STOSD to fill each position of arrayD with the largest
possible 32-bit positive integer:
arrayD SDWORD 20 DUP(?)
414.Write a sequence of instructions using CMPSD that compare arrayA to arrayB in reverse order.
After the comparison, move the first pair of non-matching array values to EAX and EBX.
COUNT = 5

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

53

arrayA DWORD COUNT DUP(?)


arrayB DWORD COUNT DUP(?)
415.Write a sequence of instructions using LODSB and STOSB that copy each character from arrayA
to arrayB, converting it to lowercase in the process. Note: setting bit 5 in an uppercase character
will convert it to lowercase:
arrayA BYTE "ABCDEFGHI"
arrayB BYTE LENGTHOF arrayA DUP(0)

Multiple-Choice
(Each of the following questions has just one correct answer)
416.A sequential search of an array of N elements requires, on average, N / 2 comparisons.
a. true
b. false
417.A binary search of an array of 64 elements requires a maximum of 8 comparisons.
a. true
b. false
418.The LODSB instruction loads from the memory location addressed by ESI.
a. true
b. false
419.The STOSB instruction loads from the memory location addressed by ESI.
a. true
b. false
420.On the first pass through an array of N items, how many times does the inner loop of a bubble sort
execute?
a. N 1
b. N
c. N + 1
d. N 2
421.If a bubble sort requires 0.2 seconds to sort an array of 1,000 elements, how many seconds will it
require to sort 10,000 elements? Hint: bubble sort is an O(n2) algorithm.
a. 2 seconds
b. 20 seconds
c. 200 seconds
d. 4 seconds
422.The instruction that copies doublewords from one memory location to another is
a. CMPSW
b. MOVSB
c. MOVSD
d. SCASD

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

54

423.The REPE prefix does which of the following?


a. repeats an instruction while the Zero flag is clear
b. repeats an instruction while the Zero flag is set
c. repeats an instruction while the Carry flag is clear
d. repeats an instruction while the Carry flag is set
424.Which instruction causes the ESI and EDI registers to be incremented by the MOVSB instruction?
a. CLC
b. REP
c. STD
d. CLD
425.The MOVSB instruction uses which register as the source operand?
a. ESI
b. EDI
c. EAX
d. ECX

Example 1
.data
var1 BYTE 10
var2 BYTE 20
var3 BYTE 30
.code
mov esi,OFFSET var2
mov edi,OFFSET var1
cmpsb
ja L1
jb L2
je L3
426.To which label will the program jump in Example 1?
a. L1
b. L2
c. L3
d. cannot be determined from the information given
427.In Example 1, where will ESI point after the CMPSB instruction executes?
a. at var1
b. at var2
c. at var3
d. cannot be determined from the information given
428.If var1 and var2 were changed to type SWORD in Example 1, what change(s) would have to be
made to the instructions in the code segment?
a. change CMPSB to CMPSW

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

55

b. change CMPSB to CMPSD


c. change JA to JG, and change JB to JL
d. none of the above

Example 2
1:
2:
3:
4:
5:
6:
7:
8:

.data
str1 BYTE "1324A2342424",0
.code
mov edi,OFFSET str1
mov al,'A'
cld
repne scasb
mov bl,[edi]

429.In Example 2, assume that str1 is located at offset 00040010h. What will be the value of EDI after
line 7 executes?
a. 00040010h
b. 00040013h
c. 00040014h
d. 00040015h
430.In Example 2, if we change line 6 to "std", what value will be moved to BL after line 8 executes?
a. ASCII code of "4"
b. ASCII code of "A"
c. ASCII code of "2"
d. cannot be determined
431.In Example 2, if we change line 7 to "repe scasb", what value will be moved to BL after line 8
executes?
a. ASCII code of "3"
b. ASCII code of "A"
c. ASCII code of "2"
d. cannot be determined
432.Which letter choice contains instructions that will fill all elements of arrayW with FFFFh?
arrayW WORD 50 DUP(?)
a.
mov
mov
mov
cld
rep

ax,0FFFFh
edi,OFFSET arrayW
ecx,SIZEOF arrayW

mov
mov
mov
cld
rep

ax,0FFFFh
edi,OFFSET arrayW
ecx,LENGTHOF arrayW

stosb

b.

stosw

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

56

c.
mov
mov
mov
std
rep

ax,0FFFFh
esi,OFFSET arrayW
ecx,SIZEOF arrayW
stosw

d.
mov ax,0FFFFh
mov esi,OFFSET arrayW
mov ecx,LENGTHOF arrayW
cld
repz stosw
433.Assume that pString is a doubleword that contains the offset of a string. Which of the following
letter choices contains code that will set EAX to the length of the string? (The length should not
count the string's null byte.)
a.
L1:

L2:

mov
mov
cmp
je
inc
inc
jmp

edi,pString
eax,0
BYTE PTR [edi],0
L2
edi
eax
L1

mov
mov
cmp
jne
inc
jmp

edi,pString
eax,0
BYTE PTR [edi],0
L2
edi
L1

mov
mov
cmp
jae
inc
inc
jne

edi,pString
eax,0
BYTE PTR [edi],0
L2
edi
eax
L1

mov
cmp
ja
inc
inc
jnz

edi,pString
BYTE PTR [edi],0
L2
edi
eax
L1

b.
L1:

L2:
c.
L1:

L2:
d.
L1:

L2:

434.Suppose we want to convert the letters in myString to uppercase (by clearing bit 5 of each
character). Lines 1 through 6 are the first part of the implmentation:
.data

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

57

myString
.code
1:
2: L1:
3:
4:
5:
6:

BYTE "abCDefg123hij",0
mov
mov
cmp
je
cmp
jb

esi,OFFSET myString
al,[esi]
al,0
L3
al,'a'
L2

Which letter choice contains the best alternative for the remaining instructions?
a.
7:
8:
9:
10: L2:
11:
12: L3:

cmp
jbe
and
inc
jmp
ret

al,'z'
L3
BYTE PTR [esi],11011111b
esi
L1

7:
8:
9:
10: L2:
11:
12: L3:

cmp
jna
and
inc
jmp
ret

al,'z'
L2
BYTE PTR [esi],11011111b
esi
L1

7:
8:
9:
10: L2:
11:
12: L3:

cmp
ja
and
inc
jmp
ret

al,'z'
L2
BYTE PTR [esi],11011111b
esi
L1

7:
8:
9:
10: L2:
11:
12:
13: L3:

cmp
ja
and
jnz
inc
jmp
ret

al,'z'
L2
BYTE PTR [esi],11011111b
L3
esi
L1

b.

c.

d.

435.Given the following declaration of a two-dimensional array, which letter choice contains
statements that correctly calculate the sum of column 0?
.data
ROWSIZE = 5
NUMROWS = 4
twArray WORD NUMROWS DUP( ROWSIZE DUP(?) )
a.

L1:

mov esi,OFFSET twArray


mov edi,0
mov ecx,NUMROWS
mov ax,0
add ax,twArray[esi+edi]
add esi,ROWSIZE
loop L1

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

58

b.

L1:

mov esi,0
mov edi,OFFSET twArray
mov ecx,NUMROWS
mov ax,0
add ax,twArray[esi+edi]
add esi,ROWSIZE
loop L1

c.

L1:

mov esi,0
mov edi,0
mov ecx,NUMROWS + ROWSIZE
mov ax,0
add ax,twArray[esi+edi]
add esi,ROWSIZE
loop L1

d.

L1:

mov esi,0
mov edi,0
mov ecx,NUMROWS
mov ax,0
add ax,twArray[esi+edi]
add esi,(ROWSIZE * TYPE twArray)
loop L1

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

.data
str1 BYTE "AAAX",0
str2 BYTE 10 DUP(0FFh)
.code
mov edi,0
L1: mov al,[str1+edi]
cmp al,0
je L2
mov [str2+edi],al
inc edi
jmp L1
L2:

436.After Example 3 executes, what value will be stored at offset [str2+4]?


a. 0FFh
b. ASCII code of "X"
c. 00h
d. cannot be determined
437.In Example 3, if we changed lines 7, 8, and 9 to the following, what value would be stored at
offset [str2+4] after the loop finished?
7:
8:
9:

mov [str2+edi],al
cmp al,0
je L2

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

59

b. ASCII code of "X"


c. 00h
d. cannot be determined

Chapter 10 Test Bank


Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.

Fill in the Blanks and Short Answer


1

Define a structure named ThreeInts containing three unsigned doublewords named field1, field2,
and field3. The fields should be uninitialized.

438.Using the ThreeInts structure from the previous question, declare a variable named first of type
ThreeInts:
439.Using the ThreeInts structure from the previous question, write a statement that assigns the value
10h to field1:
440.Using the ThreeInts structure from the previous question, write a statement that creates a variable
named pThree that contains the offset of ThreeInts.

Short Programming Problems


Example 1
POINT STRUCT
X WORD ?
Y WORD ?
POINT ENDS
POLY STRUCT
points POINT 10 DUP(<>)
numPoints WORD ?
POLY ENDS
441.Using Example 1, declare a variable named aPoint of type POINT that initializes X to 10 and Y to
20:
442.Using Example 1, declare a variable named aPoly of type POLY that uses default structure values.
443.Using Example 1, set the first element of the aPoly.points array to X=1, Y=2.
444.Using Example 1, set the second element of the aPoly.points array to X=3, Y=4.
445.Using Example 1, write a sequence of statements that initialize all X values in the aPoly.points
array to random integers between 0 and 99. Use an indexed operand to access the points array.
446.Write a sequence of statements that first set ESI to the offset of aPoly. Next, use ESI as an indirect
operand to set the numPoints field to 2.
447.Declare an array of two POLY structures named myArray. Use default initialization for both.

Example 2
RECT STRUCT
Left
WORD ?
Top
WORD ?
Right
WORD ?

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

60

Bottom
RECT ENDS

WORD ?

AnyData UNION
mTitle BYTE 10 DUP(?)
mRect RECT <>
AnyData ENDS
448.Using Example 2, declare a variable named myData of type AnyData.
449.Using Example 2, move the letter "A" to the first byte of the mTitle field.
450.Using Example 2, move 10 to the Left field within the mRect field of myData.
451.Using Example 2, use the SIZEOF operator to set ECX to the size of the mTitle field in the
AnyData union:

Example 3
POINT STRUCT
X WORD ?
Y WORD ?
POINT ENDS
Rectangle STRUCT
upperLeft POINT <>
lowerRight POINT <>
Rectangle ENDS
452.Using Example 3, declare a Rectangle variable named myRect. In the same delcaration, initialize
its upperLeft field to (10,20) and its lowerRight field to (50,60).
453.Using Example 3, declare an array of three Rectangles named myArray and initialize the
rectangles to the same coordinates as the variable in the previous question.
454.Using indirect addressing with ESI, assign a value of 80 to the X-coordinate of the upper left
corner of the third rectangle in myArray (from the previous question).
(The following questions are not related to Example 3.)
455.Create a macro named putChar that writes a single character, passed as a macro argument, to
standard output. Be sure to push and pop any registers modified by the macro.
456.Create a macro named mMove16 that moves any 16-bit memory operand to any other 16-bit
memory operand. Save and restore any registers modified by the macro. Syntax: mMove
destination,source
457.Create a macro named mMult16 that multiplies any two signed 16-bit memory operands and
produces a 16-bit product. Syntax: mMult16 product,op1,op2
458.Create a macro named mWriteHex that writes the value of a 32-bit memory operand to standard
output in hexadecimal format.
459.Using the mWriteHex macro from the previous question, write a statement that invokes the
macro, using ESI as an indirect operand.
460.Create a macro named mWriteHexConst that lets the caller pass an integer constant argument.
The integer is written to standard output in hexadecimal format. All labels must be local.
461.Create a macro named LongLoop that is not constrained by the LOOP instruction's limited 128
to +127 byte range. All labels must be local.

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

61

462.Write a macro named mShowValue that writes a literal string to standard output, followed by the
contents of an integer variable in unsigned decimal. Push and pop any registers modified by the
macro. All labels must be local. Following is a sample call:
.data
salary DWORD 52100
.code
mShowValue "Salary is equal to: ", salary
463.Write a sequence of statements that exits a macro if the count argument is blank.
464.Write a sequence of statements that displays an error message on the console during assembly if
the first macro argument named count is identical to "ECX". Make the comparison caseinsensitive.
465.Write a macro named myMac that has a single parameter named first, which is given a default
argument initializer of 0. The macro should move first to the EAX register.
466.The mWrite macro shown in Chapter 10 displays a string literal on the console. A sample call is:
mWrite "Hello there"
Show how to call mWrite and pass it a string that contains both ordinary characters and carriagereturn/linefeed bytes (0Dh, 0Ah).
467.Use the REPEAT directive to define an array named myArray that contains 50 16-bit unsigned
words, with initial values based on the following sequence: {5,7,9,...,103}
468.Use the FOR directive to create five uninitialized DWORD variables in which each variable name
is a member of the following list: monday,tuesday,wednesday,thursday,friday.
469.Write down the contents of the first five rows (in hexadecimal) of the table generated by the
following statements:
count = 0
FORC digit,<0123456789ABCDEF>
BYTE count,"&digit"
count = count + 1
ENDM

Multiple-Choice
(Each of the following questions has only one correct answer.)
470.The IFNB directive permits assembly if its argument is not blank.
a. true
b. false
471.The IFDIF directive permits assembly if two arguments are equal.
a. true
b. false
472.The IFDIFI directive performs a case-insensitive comparison between two arguments.
a. true
b. false
473.What data definitions will be created by the following directives?
FOR colorVal,<red,green,blue,turquoise,purple,orange>
BYTE "&colorVal",0

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

62

ENDM
a. six strings, each equal to "&colorVal", followed by a null byte.
b. six null-terminated strings, each containing the name of a different color
c. six variables, each having a label whose name is a color
d. this statement will cause a syntax error
474.Which of the following statements permits assembly if the symbol Win32 has been defined?
a. IF Win32 == 1
b. IF DEFINED Win32
c. IFDEF Win32
d. IFNDEF Win32
475.Which of the following statements permits assembly if arg1 is exactly the same as arg2? (Assume
that a case-senstitive comparison is used.)
a. IFEQUAL <arg1>,<arg2>
b. IFIDN <arg1>,<arg2>
c. IF arg1 EQ arg2
d. IFEQ arg1,arg2

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

63

You might also like