All Answers
All Answers
All Answers
Note to instructors: To view the answers, select Tools | Options | View | Hidden Text in MS-Word.
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.
4.
5.
6.
7.
8.
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
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.
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
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
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
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 ?
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
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?
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
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
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
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
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
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.
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.
14
15
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
16
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
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
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
20
179.Which utility program reads an assembly language source file and produces an object file?
a. compiler
b. linker
c. assembler
d. loader
181.Which file(s) contain a human-readable listing of segment (and segment group) names?
a. listing
b. source
c. map
d. executable
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
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.
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)?
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]
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
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
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
26
sub ebx,ecx
add eax,ebx
inc eax
Some of the following questions have more than one correct answer. Circle all correct answers:
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(?)
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
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
eax,[edi]
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
b.
c.
d.
True/False
1
A link library contains procedures that have already been assembled into object code.
30
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
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.
True/False
1
33
digit
C
digit
start
+,-
digit
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.
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=
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
35
36
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
37
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
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
38
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
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
40
True/False
1
41
dx,000Fh
ax,6342h
bx,100h
bx
42
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
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.
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
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
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.
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
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.
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
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?
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
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
52
d. cannot be determined
409.Refer to Example 2. Suppose we changed the last statement in the Accum procedure to the
following:
ret
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
53
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
54
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
55
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
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
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:
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:
mov [str2+edi],al
cmp al,0
je L2
a. 0FFh,
Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition
59
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.
Example 2
RECT STRUCT
Left
WORD ?
Top
WORD ?
Right
WORD ?
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.
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
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
63