Professional Documents
Culture Documents
---------------------------
-------------
An assembler converts source-code programs from
1. How do assemblers
assembly language into machine language. A linker
and linkers work
combines individual files created by an assembler into a
together?
single executable program.
3. What is meant by a In a one-to-many relationship, a single statement expands
one-to-many into multiple assembly language or machine instructions.
relationship when
comparing a high-level
language to machine
language?
4. Explain the concept A language whose source programs can be compiled and
of portability as it run on a wide variety of com- puter systems is said to be
applies to programming portable.
languages.
5. Is the assembly No. Each assembly language is based on either a processor
language for x86 family or a specific computer.
processors the same as
those for computer
systems such as the Vax
or Motorola 68x00?
Some examples of embedded systems applications are
6. Give an example of automobile fuel and ignition sys- tems, air-conditioning
an embedded systems control systems, security systems, flight control systems,
application. hand-held computers, modems, printers, and other
intelligent computer peripherals.
Device drivers are programs that translate general
7. What is a device
operating system commands into specific references to
driver?
hardware details that only the manufacturer knows.
8. Do you suppose type No, C++ does not allow a pointer of one type to be
checking on pointer assigned to a pointer of another type. Assembly language
variables is stronger has no such restriction regarding pointers.
(stricter) in assembly
language, or in C and
C++?
9. Name two types of Applications suited to assembly language: hardware device
applications that would driver and embedded systems and computer games
be better suited to requiring direct hardware access.
assembly language than
a high-level language.
10. Why would a high- A high-level language may not provide for direct hardware
level language not be access. Even if it does, awk- ward coding techniques must
an ideal tool for writing often be used, resulting in possible maintenance problems.
a program that directly
accesses a printer port?
11. Why is assembly Assembly language has minimal formal structure, so
language not usually structure must be imposed by programmers who have
used when writing large varying levels of experience. This leads to difficulties
application programs? maintaining existing code.
12. Challenge: Translate mov eax,Y ; move Y to EAX
a. 11111000 b. 11001010 c.
11110000
3. What is the sum of 3. (a) 00010001 (b) 101000000 (c) 00011110
each pair of binary
integers?
a. 00001111 00000010 b.
11010101 01101011 c.
00001111 00001111
4. How many bytes are 4.(a)2 (b)4 (c)8 (d)16
contained in each of the
following data types?
a. word
b. doubleword
c. quadword
d. double quadword
5. What is the minimum 5. (a) decimal 65 requires 7 bits (b) decimal 409 requires 9
number of binary bits bits (c) decimal 16,385 requires 15 bits
needed to represent
each of the following
unsigned decimal
integers?
a. 65
b. 409
c. 16385
6. What is the 6. (a) 35DA (b) CEA3 (c) FEDB
hexadecimal
representation of each
of the following binary
numbers?
a. A4693FBC b.
B697C7A1 c. 2B3D9461
1.4
1. (NOT X) OR Y
---
1. In an 8-bit binary
number, which is the
most significant bit
(MSB)?
a. 00110101 b. 10010110 c.
11001100
a. 10101111 + 11011011
b. 10010111 + 11111111
c. 01110101 + 10101100
4. Calculate binary
00001101 minus 00000111.
a. word
b. doubleword
c. quadword
d. double quadword
a. 4095
b. 65534
c. 42319
7. What is the
hexadecimal
representation of each
of the following binary
numbers?
b. 6ACDFA95
c. F69BDC2A
a. 3A
b. 1BF c. 1001
d Exercises 29
...
--------
ationofeachofthefollowingsigneddecimalintegers?
ationofeachofthefollowingsigneddecimalintegers?
---------------------------
--
a. 7C4 3BE
b. B69 7AD
integer?
2.1
Control Unit, Arithmetic Logic Unit, and the clock. Data,
---
Address, and Control buses.
1. The central processor
unit (CPU) contains
registers and what other
basic elements?
2. The central processor Data, Address, and Control buses.
unit is connected to the
rest of the computer
system using what three
buses?
3. Why does memory Conventional memory is outside the CPU and it responds
access take more more slowly to access requests. Registers are hard-wired
machine cycles than inside the CPU.
register access?
4. What are the three Fetch, decode, execute.
basic steps in the
instruction execution
cycle?
5. Which two additional Fetch memory operands, store memory operands
steps are required in the
instruction execution
cycle when a memory
operand is used?
2.2
Real-address mode, Protected mode, and System
---
Management mode.
1. What are the x86
processor's three basic
modes of operation?
2. Name all eight 32-bit EAX, EBX, ECX, EDX, ESI, EDI, ESP, EBP.
general-purpose
registers.
3. Name all six segment CS, DS, SS, ES, FS, GS.
registers.
tus flags.
meticorlogicaloperationgeneratesanegativeresult?
uctionsetisbackward-
tionset.
ctionsetiscompletelydifferentfromthex86instructionset.
bit mode, you can use 16-bit real mode, but not the
onofMicrosoftWindowsdoesnotsupportvirtual-
otherboard.
endtheirsoundoutputdirectlytothesoundcard'shardware
3.1
1. 35d, DDh, 335o, 11011101b
---
and __________.
3.2
1. The INCLUDE directive copies necessary definitions and
---
setup information from the Irvine32.inc text file. The data
from this file are inserted into the data stream read by the
1. In the AddTwo assembler.
program, what is the
meaning of the
INCLUDE directive?
2. In the AddTwo 2. The .CODE directive marks the beginning of the code
program, what does the segment.
.CODE directive
identify?
3. What are the names 3. Code and data.
of the two segments in
the AddTwo program?
4. In the AddTwo 4. EAX.
program, which register
holds the sum?
5. In the AddTwo 5. INVOKE ExitProcess,0.
program, which
statement halts the
program?
3.3
1. Object (.OBJ) and listing (.LST) files
---
---
1. Create an uninitialized
data declaration for a
16-bit signed integer.
2. Create an uninitialized 2. var2 BYTE ?
data declaration for an
8-bit unsigned integer.
3. Create an uninitialized 3. var3 SBYTE ?
data declaration for an
8-bit signed integer.
4. Create an uninitialized 4. var4 QWORD ?
data declaration for a
64-bit integer.
5. Which data type can 5. SDWORD
hold a 32-bit signed
integer?
3.5
1. BACKSPACE 08h
---
1. Declare a symbolic
constant using the
equal-sign directive that
contains the ASCII code
(08h) for the Backspace
key.
2. Declare a symbolic 2. SecondsInDay 24 x 60 x 60
constant named
SecondsInDay using the
equal-sign directive and
assign it an arithmetic
expression that
calculates the number
of seconds in a 24-hour
period.
]
3. Write a statement that ...
causes the assembler to
calculate the number of
bytes in the follow- ing
array, and assign the
value to a symbolic
constant named
ArraySize:
myArray WORD 20
DUP(?)
3. ArraySize ($ myArray)
myArray DWORD 30
DUP(?)
-> 4. ArraySize ($
myArray) / 4
5. Use a TEXTEQU 5. PROCEDURE TEXTEQU <PROC>
expression to redefine
"proc" as "procedure."
6. Use TEXTEQU to 6. Code example:
mov esi,OFFSET
myArray
...
olicconstantratherthananintegerliteralinyourcode?
block comment.
numericaddresseswhenwritinginstructionsthataccess
procedure?
4.1
1. Register, immediate, and memory.
---
.data
3. Code:
SF = SF = SF = ; a. CF =
ZF = ZF = ZF = ; b. CF =
OF = OF = OF = ; c. CF =
4.3
1. False
----
1. (True/False): The
OFFSET operator always
returns a 16-bit value.
2. (True/False): The PTR 2. False
operator returns the 32-
bit address of a variable.
3. (True/False): The TYPE 3. True
operator returns a value
of 4 for doubleword
operands.
myBytes BYTE
10h,20h,30h,40h
myWords WORD
8Ah,3Bh,72h,44h,66h
myDoubles DWORD
1,2,3,4,5
myPointer DWORD
myDoubles
5. Fill in the requested 5.(a)10h (b)40h (c)003Bh (d)3 (e)3 (f)2
register values on the
right side of the
following instruction
sequence:
6. Fill in the requested 6. (a) 2010h (b) 003B008Ah (c) 0 (d) 0 (e) 0044h
register values on the
right side of the
following instruction
sequence:
1. (True/False): A JMP
instruction can only
jump to a label inside
the current procedure.
2. (True/False): JMP is a 2. False
conditional transfer
instruction.
3. If ECX is initialized to 3. 4,294,967,296 times
zero before beginning a
loop, how many times
will the LOOP
instruction repeat?
(Assume ECX is not
modified by any other
instructions inside the
loop.)
4. (True/False): The 4. False
LOOP instruction first
checks to see whether
ECX is not equal to
zero; then LOOP
decrements ECX and
jumps to the destination
label.
5. (True/False): The 5. True
LOOP instruction does
the following: It
decrements ECX; then, if
ECX is not equal to
zero, LOOP jumps to the
destination label.
6. In real-address mode, 6. CX
which register is used as
the counter by the
LOOP instruction?
7. In real-address mode, 7. ECX
which register is used as
the counter by the
LOOPD instruction?
8. (True/False): The 8. False ( 128 to 127 bytes from the current location)
target of a LOOP
instruction must be
within 256 bytes of the
current
location.
9. (Challenge): What will 9. This is a trick! The program does not stop, because the
be the final value of first LOOP instruction decrements ECX to zero. The second
EAX in this example?
LOOP instruction decrements ECX to FFFFFFFFh, causing
(see image pg. 128) the outer loop to repeat.
10. Revise the code from 10. Insert the following instruction at label L1: push ecx. Also
the preceding question insert the following instruc- tion before the second LOOP
so the outer loop instruction: pop ecx. (Once you have added these instruc-
counter is not erased tions, the final value of eax is 1Ch.)
when the inner loop
starts.
4.6
1. True (bits 8-63 are cleared)
---
1. (True/False): Moving a
constant value of 0FFh
to the RAX register
clears bits 8 through 63.
not permitted.
3. What value will RCX 3. RCX = 12345678FFFFFFFF hexadecimal
contain after executing
the following
instructions?
mov
rcx,1234567800000000h
sub ecx,1
4. What value will RCX 4. RCX = 12345678ABABABAB hexadecimal
contain after executing
the following
instructions?
mov
rcx,1234567800000000h
add rcx,0ABABABABh
5. What value will the 5. AL = 1F hexadecimal
AL register contain after
executing the following
instructions?
.data
bArray BYTE
10h,20h,30h,40h,50h
.code
inc rdi
mov al,[rdi]
6. What value will RCX 6. RCX = DF02 hexadecimal
contain after executing
the following
instructions?
mov rcx,0DFFFh
mov bx,3
add cx,bx
4.9
...
---
data
code
mov edx,21348041h
mov eax,30020000h
dec ax
mov al,1
add al,3
mov eax,5
sub eax,6
mov rax,44445555h
data
dwordVal DWORD
84326732h
code
mov
rax,0FFFFFFFF00000000h
mov rax,dwordVal
data
code
mov ax,3
mov eax,dVal
data
dVal DWORD ?
code
mov dVal,12345678h
add ax,3
mov eax,dVal
data
var2 WORD
1000h,2000h,3000h,4000h
a. mov ax,var1?
b. mov ax,var2
c. mov eax,var3
d. mov var2,var3
e. movzx ax,var2
f. movzx var2,al
g. mov ds,ax
h. mov ds,1000h
mov al,var1 ; a.
mov ah,[var1+3] ; b.
mov ax,var2 ; a.
mov ax,[var2+4] ; b.
mov ax,var3 ; c.
mov ax,[var3-2] ; d.
mov edx,var4
movzx edx,var2
mov edx,[var4+4]
movsx edx,var1