0% found this document useful (0 votes)
9 views47 pages

Assembly Manual

This document consists of a series of questions and answers related to assembly language, virtual machines, data representation, boolean operations, and x86 processor architecture. Key topics include the roles of assemblers and linkers, the concept of portability in programming languages, and the structure of the instruction execution cycle. It also covers details about binary and hexadecimal representations, device drivers, and the significance of boolean expressions.

Uploaded by

18-QADEER AHMAD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views47 pages

Assembly Manual

This document consists of a series of questions and answers related to assembly language, virtual machines, data representation, boolean operations, and x86 processor architecture. Key topics include the roles of assemblers and linkers, the concept of portability in programming languages, and the structure of the instruction execution cycle. It also covers details about binary and hexadecimal representations, device drivers, and the significance of boolean expressions.

Uploaded by

18-QADEER AHMAD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

NAME

QADEER AHMAD
ROLL NO.
19-CS-18
MANUAL SUBMITTED TO
SIR ASIM MUBARAK
DEPARTMENT OF COMPUTER SCIENCE
1.1Section Review
(Basic Concepts of Assembly Language)
Question#1:

How do assemblers and linkers work together?


An assembler converts source-code programs from assembly language into machine
language. A linker combines individual files created by an assembler into a single
executable program.
Question#2:

How will studying assembly language enhance your understanding of


operating systems?
Assembly language is a good tool for learning how application programs communicate with
the computer’s operating system via interrupt handlers, system calls, and common memory
areas. Assembly language programming also helps when learning how the operating
system loads and executes application programs.
Question#3:

What is meant by a one-to-many relationship when comparing a high-level


language to machine language?
In a one-to-many relationship, a single statement expands into multiple assembly language
or machine instructions.
Question#4:

Explain the concept of portability as it applies to programming languages.


A language whose source programs can be compiled and run on a wide variety of computer
systems is said to be portable.

Question#5:
Is the assembly language for x86 processors the same as
those for computer systems such as the Vax or Motorola 68x00?
No. Each assembly language is based on either a processor family or a specific computer.
Question#6:

Give an example of an embedded systems application.


Some examples of embedded systems applications are automobile fuel and ignition
systems, air-conditioning control systems, security systems, flight control systems, hand-
held computers, modems, printers, and other intelligent computer peripherals.
Question#7:

What is a device driver?


Device drivers are programs that translate general operating system commands into
specific references to hardware details that only the manufacturer knows.
Question#8:

Do you suppose type checking on pointer variables is


stronger (stricter) in assembly language or in C and C++?
C++ does not allow a pointer of one type to be assigned to a pointer of another type.
Assembly language has no such restriction regarding pointers.
Question#9:

Name two types of applications that would be better suited to


assembly language than a high-level language.
Applications suited to assembly language: hardware device driver and embedded systems
and computer games requiring direct hardware access.
Question#10:

Why would a high-level language not be an ideal tool for


writing a program that directly accesses a particular brand of printer?
A high-level language may not provide for direct hardware access. Even if it does, awkward
coding techniques must often be used, resulting in possible maintenance problems.
Question#11:

Why is assembly language not usually used when writing


large application programs?
Assembly language has minimal formal structure, so structure must be imposed by
programmers who have varying levels of experience. This leads to difficulties maintaining
existing code.
Question#12:

Challenge: Translate the following C++ expression to


assembly language, using the example presented earlier in this chapter as
a guide: X (Y * 4) 3.
Code for the expression X (Y * 4) 3:
moveax,Y ; move Y to EAX
mov ebx,4 ; move 4 to EBX
imulebx ; EAX = EAX * EBX
add eax,3 ; add 3 to EAX
movX,eax ; move EAX to X

1.2 Section Review


(Virtual Machine Concept)
Question#1:

In your own words, describe the virtual machine concept.


Virtual machine concept: Computers are constructed in layers, so that each layer represents
a translation layer from a higher-level instruction set to a lower-level instruction set.
Question#2:

Why don’t programmers write application programs in


machine language?
Machine language: It is enormously detailed and consists purely of numbers. Hard for
humans to understand.
Question#3:

(True/False): When an interpreted program written in


language L1 runs, each of its instructions is decoded and executed by a
program written in language L0.
True.
Question#4:

Explain the technique of translation when dealing with


languages at different virtual machine levels.

An entire L1 program is converted into an L0 program by an L0 program specifically


designed for this purpose. Then the resulting L0 program is executed directly on the
computer hardware.

Question#5:

At which level does assembly language appear in the virtual


machine example shown in this section?
Assembly language appears at Level 3.
Question#6:
What software permits compiled Java programs to run on
almost any computer?
The Java virtual machine (JVM) allows compiled Java programs to run on almost any
computer.
Question#7:

Name the four virtual machine levels named in this section,


from lowest to highest.
Digital logic, instruction set architecture, assembly language, high-level language.
Question#8:

Why don’t programmers write applications in machine


language?
Machine language is difficult for humans to understand, since it provides no visual clues
relating to the instruction syntax.
Question#9:

Machine language is used at which level of the virtual machine shown in


Figure 1–1?
Instruction set architecture.

Question#10:

Statements at the assembly language level of a virtual


machine are translated into statements at which other level?
Level 2 (Instruction Set Architecture).

1.3 Section Review


(Data Representation)
Question#1:

Explain the term Least Significant Bit (LSB).


Answer: Least significant bit (bit 0).
Question#2:

Explain the term Most Significant Bit (MSB).


Answer: Most significant bit (the highest numbered bit).
Question#3:

What is the decimal representation of each of the following


unsigned binary integers?
a. 11111000
b. 11001010
c. 11110000
Answer:
(a) 248 (b) 202 (c) 240

Question#4:

What is the decimal representation of each of the following unsigned


binary integers?
a. 00110101 b. 10010110 c. 11001100
Answer:
(a) 53 (b) 150 (c) 204
Question#5:

What is the sum of each pair of binary integers?


a. 00001111 + 00000010
b. 11010101 +01101011
c. 00001111 + 00001111
Answer:
(a) 00010001 (b) 101000000 (c) 00011110
Question#6:

What is the sum of each pair of binary integers?


a. 10101111 + 11011011
b. 10010111 + 11111111
c. 01110101 + 10101100

(a) 110001010 (b) 110010110 (c) 100100001

Question#7:

How many bytes are contained in each of the following data


types?
a. word b. doubleword c. quadword
(a) 2
(b) 4
(c) 8
Question#8:
How many bits are contained in each of the following data
types?
a. word b. doubleword c. quadword
(a) 16
(b) 32
(c) 6
Question#9:

What is the minimum number of binary bits needed to


represent each of the following unsigned decimal integers?
a. 65 b. 256 c. 32768
(a) 7
(b) 9
(c) 16

Question#10:

What is the minimum number of binary bits needed to


represent each of the following unsigned decimal integers?
a. 4095 b. 65534 c. 2134657
(a) 12 (b) 16 (c) 22
Question#11:

What is the hexadecimal representation of each of the


following binary numbers?
a. 1100 1111 0101 0111 b. 0101 1100 1010 1101
c. 1001 0011 1110 1011
(a) CF57
(b) 5CAD
(c) 93EB
Question#12:

What is the hexadecimal representation of each of the


following binary numbers?
a. 0011 0101 1101 1010
b. 1100 1110 1010 0011
c. 1111 1110 1101 1011

(a) 35DA (b) CEA3 (c) FEDB

Question#13:

What is the binary representation of the following hexadecimal numbers?


a. E5B6AED7 b. B697C7A1 c. 234B6D92
(a) 1110 0101 1011 0110 1010 1110 1101 0111
(b) 1011 0110 1001 0111 1100 0111 1010 0001
(c) 0010 0011 0100 1011 0110 1101 1001 0010

Question#14:
What is the binary representation of the following
hexadecimal numbers?
a. 0126F9D4 b. 6ACDFA95 c. F69BDC2A
(a) 0000 0001 0010 0110 1111 1001 1101 0100
(b) 0110 1010 1100 1101 1111 1010 1001 0101
(c) 1111 0110 1001 1011 1101 1100 0010 1010

Question#15:

What is the unsigned decimal representation of each


hexadecimal integer?
a. 3A b. 1BF c. 4096
(a) 58
(b) 447
(c) 16534

Question#16:

What is the unsigned decimal representation of each


hexadecimal integer? a. 62 b. 1C9 c. 6A5B
(a) 98
(b) 457
(c) 27227
Question#17:

What is the 16-bit hexadecimal representation of each


signed decimal integer? a. 26 b. 452
(a) FFE6
(b) FE3C
Question#18:

What is the 16-bit hexadecimal representation of each


signed decimal integer? a. 32 b. 62
(a) FFE0
(b) FFC2
Question#19:

The following 16-bit hexadecimal numbers represent signed


integers. Convert to decimal. a. 7CAB b. C123
(a) +31915
(b) -16093

Question#20:

The following 16-bit hexadecimal numbers represent signed


integers. Convert to decimal. a. 7F9B b. 8230
(a) +32667
(b) −32208
Question#21:

What is the decimal representation of the following signed


binary numbers?
a. 10110101 b. 00101010 c. 11110000
(a) −75
(b) +42
(c) −16
Question#22:

What is the decimal representation of the following signed


binary numbers?
a. 10000000 b. 11001100 c. 10110111
(a) −128
(b) −52
(c) −73

Question#23:

What is the 8-bit binary (two’s-complement) representation


of each of the following signed decimal integers?
a. 5 b. 36 c. 16
(a) 11111011
(b) 11011100
(c) 11110000
Question#24:

What is the 8-bit binary (two’s-complement) representation


of each of the following signed decimal integers?
a.72 b.98 c. 26
(a) 10111000
(b) 10011110
(c) 11100110
Question#25:

What are the hexadecimal and decimal representations of


the ASCII character capital X?
58h and 88d.

Question#26:

What are the hexadecimal and decimal representations of


the ASCII character capital M?
4Dh and 77d.
Question#27:

Why was Unicode invented?


To handle international character sets that require more than 256 codes.
Question#28:

What is the largest value you can represent using a 256-bit


unsigned integer?
 2^256 - 1.
Question#29:

Challenge: What is the largest positive value you can represent using a
256-bit signed integer?
 +2^255 - 1.
1.4 Section Review
(Boolean Operations)
Question#1:

Describe the following boolean expression: ¬X ∨ Y.


(NOT X) OR Y.
Question#2:

Describe the following boolean expression: (X ∧ Y).


X AND Y.
Question#3:

What is the value of the boolean expression (T ∧ F) ∨T ?


(T ∧ F)=F

F∨ T=T

SO (T ∧ F) ∨ T will be T((T ∧ F) ∨ T=T).


Question#4:

What is the value of the boolean expression ¬(F ∨ T) ?


(F ∨ T)= T
¬T=F
Answer will be F.
Question#5:

What is the value of the boolean expression ¬F ∨ ¬T ?


¬F=T
¬T=F

¬F ∨ ¬T=T
Answer will be T.
Question#6:

boolean function described by ¬(A ∨ Β).


Create a truth table to show all possible inputs and outputs for the

A B (A ∨ Β) ¬(A ∨ Β)
0 0 0 1
0 1 1 0
1 0 1 0
1 1 1 0

Question#7:

for the boolean function described by (¬A ∧ ¬B).


Create a truth table to show all possible inputs and outputs

A B ¬A ¬B (¬A ∧ ¬B)
0 0 1 1 1
0 1 1 0 0
1 0 0 1 0
1 1 0 0 0

Question#8:

If a boolean function has four inputs, how many rows are


required for its truth table?
16, or (24).

Question#9:

How many selector bits are required for a four-input multiplexer?


1 bits, producing the following values: 00, 01, 10, 11.

CHAPTER # 2
(x86 Processor Architecture)
2.1 section review
Question#1:

The central processor unit (CPU) contains registers and what other basic
elements?
Control Unit, Arithmetic Logic Unit, and the clock.
Question#2:

The central processor unit is connected to the rest of the


computer system using what three buses?
Data Bus, Control Bus, Address Bus.
Question#3:
Why does memory access take more machine cycles than
register access?
Conventional memory is outside the CPU, and it responds more slowly to access requests.
Registers are hard-wired inside the CPU.
Question#4:

What are the three basic steps in the instruction execution


cycle?
Fetch, Decode, Execute

Question#5:

Which two additional steps are required in the instruction


execution cycle when a memory operand is used?
Fetch memory operands, store memory operands.

Question#6:

During which stage of the instruction execution cycle is the


program counter incremented?
During the fetch step.
Question#7:

After a program has been loaded into memory, how does it


begin execution?
The OS executes a branch (like a GOTO) to the first machine instruction in the program.
Question#8:

Define multitasking?
The CPU executes multiple tasks (programs) by rapidly switching from one program to the
next. This gives the impression that all programs are executing at the same time.

Question#9:
What is the function of the OS scheduler?
The OS scheduler determines how much time to allot to each task, and it switches between
tasks.

Question#10:

When the processor switches from one task to another, what


values in the first task’s state must be preserved?
The program counter, the task’s variables, and the CPU registers (including the status
flags).
Question#11:
When the processor switches from one task to another,
what values in the first task’s state must be preserved?
. The program counter, the task’s variables, and the CPU registers (including the status
flags). . The program counter, the task’s variables, and the CPU registers (including the
status flags).

(x86 Architecture Details)


2.2 section review

Question#1:

What are the x86 processor’s three basic modes of


operation?
 Protected Mode.
 Real-address mode.
 System management mode.

Question#2:

Name all eight 32-bit general-purpose registers.


EAX, EBX, ECX, EDX, ESI, EDI, ESP, EBP
Question#3:

Name all six segment registers.


CS, DS, SS, ES, FS, GS
Question#4:

What special purpose does the ECX register serve?


Loop counter

Question#5:

Besides the stack pointer (ESP), what other register points to


variables on the stack?
EBP.

Question#6:

Name at least four CPU status flags.


Most common: Carry, Sign, Zero, Overflow. Less common: Auxiliary Carry, Parity.
Question#7:

Which flag is set when the result of an unsigned arithmetic operation is


too large to fit into the destination?
Carry.
Question#8:

Which flag is set when the result of a signed arithmetic operation is either
too large or too small to fit into the destination?
Overflow.
Question#9:

Which flag is set when an arithmetic or logical operation generates a


negative result?
Sign flag will be set whenarithmetic or logical operation generates a negative result.
Question#10:

Which part of the CPU performs floating-point arithmetic?


Floating-Point Unit perform the Floating-Point arithmetic.
Question#11:
How many bits long are the FPU data registers?
80 bits long FPU data register.

Question#12:

Which Intel processor was the first member of the IA-32 family?
The Intel 80386.

Question#13:

Which Intel processor first introduced superscalar execution?


The Pentium Intel processor first introduced superscalar execution.
Question#14:

Which Intel processor first used MMX technology?


The Pentium II.
Question#13:

Describe the CISC design approach.


CISC means complex instruction set. it a large collection of instructions, some of which
perform sophisticated operations that might be typical of a high-level language.

(x86 Memory Management)


2.3 section review
Question#1:

What is the range of addressable memory in protected mode?


4 GByte( 0 to FFFFFFFFh)is the range of a addressable memory in protected mode.
Question#2:

What is the range of addressable memory in real-address


mode?
1 MByte (0 to FFFFFh) is the range of the addressable memory in real-address mode.
Question# 3:
The two ways of describing an address in real-address mode are segment-
offset and ______________.
Linear (absolute).
Question#4:

In real-address mode, convert the following hexadecimal


segment-offset address to a linear address: 0950:0100.
09600h.

Question#5:
In real-address mode, convert the following hexadecimal segment-
offset address to a linear address: 0CD1:02E0.
0CFF0h linear address.

Question#6:

In MASM’s flat segmentation model, how many bits hold the address of an
instruction or variable?
32 bits hold the address of an instruction in MASM’s.
Question#7:

In protected mode, which register references the descriptor


for the stack segment?
SS register reference the descriptor for the stack segment.
Question#8:

In protected mode, which table contains pointers to memory


segments used by a single program?
Local descriptor table.
Question# 9:
In the flat segmentation model, which table contains
pointers to at least two segments?
Global descriptor table contains pointers to at least two segments.
Question#10:

What is the main advantage to using the paging feature of


x86 processors?
The total size of all programs loaded into memory can exceed the amount of physical
memory installed in the computer.
Question#11:

Challenge: Can you think of a reason why MS-DOS was not


designed to support protectedmode programming?
This is an open-ended question, of course. It is a fact that MS-DOS first had to run on the
8086/8088 processors, which only supported Real-address mode. When later processors
came out that supported Protected mode, my guess is that Microsoft wanted MS-DOS to
continue to run on the older processors. Otherwise, customers with older computers would
refuse to upgrade to new versions of MS-DOS.
Question#12:

Challenge: In real-address mode, demonstrate two segment-offset


addresses that point to the same linear address.
The following segment-offset addresses point to the same linear address: 0640:0100 and
0630:0200.

(Input-Output System)
2.4 Section Review
Question#1:

Describe SRAM and its most common use.


SRAM is an acronym for Static RAM, used in CPU cache memory.
Question#2:

Describe VRAM.
VRAM (video ram) holds displayable video data. When CRT monitors are used, VRAM is
dual ported, allowing one port to continuously refresh the display while another port writes
data to the display.
Question#3:

List at least two features found in the Intel P965 Express


chipset.
Select any two features from the following list:
(1) Intel Fast Memory Access uses an updated Memory Controller Hub (MCH).
(2) I/O Controller Hub (Intel ICH8/R/DH) that supports serial ATA devices (disk drives).
(3) Support for 10 USB ports, 6 PCI express slots, networking, and Intel Quiet System
technology.

(4) High definition audio chip.


Question#4:

Name four types of RAM mentioned in this chapter.


Dynamic RAM, Static RAM, Video RAM, and CMOS RAM.
Question#5:

Which type of RAM is used for Level 2 cache memory?


Static RAM is used for level 2 cache memory.

Question#6:

What advantages does a USB device offer over a standard


serial or parallel device?
The computer can query a device connected via USB to find out its name and device type
and the type of driver it supports. The computer can also suspend power to individual
devices. None of these capabilities is possible with serial and parallel ports.

Question#7:
What is the purpose of the 8259A PIC controller?
The 8259 is the interrupt controller chip, sometimes called PIC, that schedules hardware
interrupts and interrupts the CPU.

Question#8:

What are the main differences between Wi-Fi and Bluetooth?


Bluetooth is a wireless communication protocol for exchanging small amounts of data over
short distances. It is commonly used with mobile devices such as cell phones and PDAs.
Wi-Fi devices operate at a greater speed and capacity than Bluetooth. Wi-Fi devices often
communicate with each other when in the range of a wireless network.

(Input-Output System)
2.5 section review
Question#1:

Of the four levels of input/output in a computer system, which


is the most universal and portable?
The application program level.

Question#2:

What characteristics distinguish BIOS-level input/output?


BIOS functions communicate directly with the system hardware. They are independent of
the operating system.

Question#3:

Why are device drivers necessary, given that the BIOS


already has code that communicates with the computer’s hardware?
New devices are invented all the time with capabilities that were often not anticipated when
the BIOS was written.

Question#4:

In the example regarding displaying a string of characters, which level


exists between the operating system and the video controller card?
The BIOS level.

Question#5:

At which level(s) can an assembly language program manipulate


input/output?
The operating system, BIOS, and hardware levels.

Question#6:

Why do game programs often send their sound output


directly to the sound card’s hardware
ports?
Game programs often try to take advantage of the latest features in specialized sound
cards.
It should be noted that MS-DOS game applications were more prone to do this than games
running under MS-Windows. In fact, Windows-NT, 2000, and XP all prevent applications
from directly accessing system hardwar

Chapter#3:
(Basic Elements of Assembly Language)
Section 3.1
Question#1:

Identify valid suffix characters used in integer constants.


h,q,o,d,b,r,t,y
Question#2:

(Yes/No): Is A5h a valid hexadecimal constant?


No(a loading zero is required)
Question#3:

(Yes/No): Does the multiplication operator (*) have a higher


precedence than the division operator (/) in integer expressions?
No(they have sme precedence)
Question#4:

Write a constant expression that divides 10 by 3 and returns


the integer remainder.
Expression: 10 MOD 3.
Question#5:

Show an example of a valid real number constant with an


exponent.
Real number constant:+3.5E-02
Question#6:

(Yes/No): Must string constants be enclosed in single quotes?


No , they can also be enclosed in double quotes.
Question#7:

Reserved words can be instruction mnemonics, attributes,


operators, predefined symbols, and __________.
Directives.
Question#8:

What is the maximum length of an identifier?


247 characters.
Question#9:

(True/False): An identifier cannot begin with a numericdigit.


True
Question#10:

(True/False): Assembly language identifiers are (by default)


case insensitive.
True
Question#11:

(True/False): Assembler directives execute at runtime.


False
Question#12:

(True/False): Assembler directives can be written in any


combination of uppercase and lowercase letters.
True
Question#13:

Name the four basic parts of an assembly language


instruction. 14. (True/False): MOV is an example of an instruction
mnemonic.
Label,mnemonic,operand(s),comments
Question#14:

(True/False): A code label is followed by a colon (:), but a data label does
not have a colon.
True
Question#15:

Show an example of a block comment.


Code exa
Comment !
This is a comment
This is also a comment
Question#16:

Why would it not be a good idea to use numeric addresses


when writing instructions that access variables?
Because the address code in the instructions wouls have to be updated whenever new
variable were inserted before existing ones.

(Assembling, Linking, and Running Programs)


3.2.Section Review
Question#1:

What types of files are produced by the assembler?


Object (.OBJ) and listing (.LST) files.
Question#2:

(True/False): The linker extracts assembled procedures from the link


library and inserts them in the executable program.
True.
Question#3:

(True/False): When a program’s source code is modified, it must be


assembled and linked again before it can be executed with the changes.
True.
Question#4:

Which operating system component reads and executes


programs?
Loader.
Question#5:

What types of files is produced by the linker?


Executable (.EXE).

3.3.Section Review
Question#1:

What types of files are produced by the assembler?


Object (.OBJ) and listing (.LST) files.
Question#2:

(True/False): The linker extracts assembled procedures from the link


library and inserts them in the executable program.
True.
Question#3:

(True/False): When a program’s source code is modified, it must be


assembled and linked again before it can be executed with the changes.
True.
Question#4:

Which operating system component reads and executes


programs?
Loader.
Question#5:

What types of files is produced by the linker?


Executable (.EXE).

(Defining Data)
3.4 Section Review
Question#1:

Create an uninitialized data declaration for a 16-bit signed integer.


var1 SWORD
Question#2:

Create an uninitialized data declaration for an 8-bit unsigned integer.


var2 BYTE
Question#3:

Create an uninitialized data declaration for an 8-bit signed


integer.
Var3 SBYTE
Question#4:

Create an uninitialized data declaration for a 64-bit integer.


var4 QWORD
Question#5:

Which data type can hold a 32-bit signed integer?


SDWORD
Question#6:

Declare a 32-bit signed integer variable and initialize it with


the smallest possible negative decimal value.
var5 SDWORD 2147483648
Question#7:

Declare an unsigned 16-bit integer variable named wArray


that uses three initializers.
W Array WORD 10, 20, 30
Question#8:

Declare a string variable containing the name of your favorite color.


Initialize it as a null terminated string.
My Color BYTE “blue”, 0
Question#9:

Declare an uninitialized array of 50 unsigned doublewords


named d Array.
D Array DWORD 50 DUP(?)
Question#10:

Declare a string variable containing the word “TEST”


repeated 500 times.
My test String BYTE 500 DUP(“TEST”)
Question#11:

Declare an array of 20 unsigned bytes named bArray and initialize all


elements to zero.
B Array BYTE 20 DUP(0)
Question#12:

Show the order of individual bytes in memory (lowest to


highest) for the following doubleword variable:
21h, 43h, 65h, 87h

(Symbolic Constants)
Section Review 3.5
Question#1:

Declare a symbolic constant using the equal-sign directive


that contains the ASCII code (08h) for the Backspace key.
BACKSPACE 08h
Question#2:

Declare a symbolic 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.
SecondsInDay 24 * 60 * 60

Question#3:
Write a statement that causes the assembler to calculate the number of
bytes in the following array, and assign the value to a symbolic constant
named ArraySize:
myArray WORD 20 DUP(?)
ArraySize ($ - myArray)

Question#4:

Show how to calculate the number of elements in the


following array, and assign the value
to a symbolic constant named ArraySize:
myArray DWORD 30 DUP(?)
ArraySize ($ - myArray) / TYPE DWORD

Question#5:

Use a TEXTEQU expression to redefine “PROC” as


“PROCEDURE.”
PROCEDURE TEXTEQU <PROC>

Question#6:
Use TEXTEQU to create a symbol named Sample for a
string constant, and then use the
symbol when defining a string variable named MyString.
Code example:
Sample TEXTEQU <"This is a string">
MyString BYTE Sample

Question#7:
Use TEXTEQU to assign the symbol SetupESI to the
following line of code:
movesi,OFFSETmyArray
SetupESI TEXTEQU <movesi, OFFSET myArray>

Section Review 4.1

Q# 1:
What are the three basic types of operands?
 Register
 Immediate
 Memory
Q# 2:
The destination operand of a MOV instruction cannot be a segment
register.
False

Q# 3:
In a MOV instruction, the second operand is known as the destination
operand.
False

Q# 4:
The EIP register cannot be the destination operand of a MOV instruction.
True

Q# 5:
In the operand notation used by Intel, what does reg/mem32 indicate?
A 32-bit register or memory operand

Q# 6:
In the operand notation used by Intel, what does imm16 indicate?
A 16-bit immediate (constant) operand

Q# 7:
For each of the following statements, state whether or not the instruction
is valid:
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. movds,ax
h. mov ds,1000h
(a) not valid
(b) valid
(c) not valid
(d) not valid
(e) not valid
(f) not valid
(g) valid
(h) not valid

Q# 8:
What will be the hexadecimal value of the destination operand after each
of the following instructions execute in sequence?
mov al,var1 ; a.
mov ah,[var1+3] ; b.
(a) FCh
(b) 01h

Q# 9:
What will be the value of the destination operand after each of the
following instructions
execute in sequence?
mov ax,var2 ; a.
mov ax,[var2+4] ; b.
mov ax,var3 ; c.
mov ax,[var3-2] ; d.
(a) 1000h
(b) 3000h
(c) FFF0h
(d) 4000h

Q# 10:
What will be the value of the destination operand after each of the
following instructions
execute in sequence?
mov edx,var4 ; a.
movzx edx,var2 ; b.
movedx,[var4+4] ; c.
movsx edx,var1 ; d.
(a) 00000001h
(b) 00001000h
(c) 00000002h
(d) FFFFFFFCh

Review 4.2
Q# 1:
Write an instruction that increments val2.
inc val2
Q# 2:
Write an instruction that subtracts val3 from EAX.
sub eax,val3
Q# 3:
Write instructions that subtract val4 from val2.
Code:
mov ax,val4
sub val2,ax
Q# 4:
If val2 is incremented by 1 using the ADD instruction, what will be the
values of the Carryand Sign flags?
C= 0, SF=1.

Q# 5:
If val4 is incremented by 1 using the ADD instruction, what will be the
values of the Overflow and Sign flags?
OF=1, SF=1.
Q# 6:
Where indicated, write down the values of the Carry, Sign, Zero, and
Overflow flags after each instruction has executed:
mov ax,7FF0h
add al,10h ; a. CF = SF = ZF = OF =
add ah,1 ; b. CF = SF = ZF = OF =
add ax,2 ; c. CF = SF = ZF = OF =
Write down the following flag values:
(a) CF=1, SF=0, ZF=1, OF=0
(b) CF=0, SF=1, ZF=0, OF=1
(c) CF=0, SF=1, ZF=0, OF=0
Q# 7:
Implement the following expression in assembly language: AX _ (_val2 _
BX) _ val4.
Code example:
mov ax,val2
neg ax
addax,bx
sub ax,val4
Q# 8:
Is it possible to set the Overflow flag if you add a positive integer to a
negative integer?
No.
Q# 9:
Will the Overflow flag be set if you add a negative integer to a negative
integer and produce a positive result?
Yes.
Q# 10:
Is it possible for the NEG instruction to set the Overflow flag?
Yes (for example, mov al,−128 . . . followed by . . . neg al).

Q# 11:
Is it possible for both the Sign and Zero flags to be set at the same time?
No.
Q# 12:
Write a sequence of two instructions that set both the Carry and Overflow
flags at the same time.
Setting the Carry and Overflow flags at the same time:
mov al,80h
add al,80h
Q# 13:
Write a sequence of instructions showing how the Zero flag could be used
to indicate unsigned overflow after executing INC and DEC instructions.
Setting the Zero flag after INC and DEC to indicate unsigned overflow:
mov al,0FFh
inc al
jzoverflow_occurred
mov bl,1
decbl
jzoverflow_occurred

Q# 14:
In our discussion of the Carry flag we subtracted unsigned 2 from 1 by
negating the 2 and adding it to 1. The Carry flag was the inversion of the
carry out of the MSB of the sum. Demonstrate
this process by subtracting 3 from 4 and show how the Carry flag value is
produced.
Subtracting 3 from 4 (unsigned). Carry out of MSB is inverted and placed in the Carry flag

mov al,4
sub al,3 ; CF = 0

Review 4.3
Q# 1:
The OFFSET operator always returns a 16-bit value.
False.
Q# 2:
The PTR operator returns the 32-bit address of a variable.
False.
Q# 3:
The TYPE operator returns a value of 4 for doubleword operands.
True
Q# 4:
The LENGTHOF operator returns the number of bytes in an operand.
False.
Q# 5:
The SIZEOF operator returns the number of bytes in an operand.
True
Q# 6:
Insert a directive in the given data that aligns myBytesto an even-
numbered address.
Data directive:
.data ALIGN 2
myBytes BYTE 10h, 20h, 30h, 40h
etc.
Q# 7:
What will be the value of EAX after each of the following instructions
execute?
moveax,TYPEmyBytes ; a.
moveax,LENGTHOFmyBytes ; b.
moveax,SIZEOFmyBytes ; c.
moveax,TYPEmyWords ; d.
moveax,LENGTHOFmyWords ; e.
moveax,SIZEOFmyWords ; f.
moveax,SIZEOFmyString ; g.
(a) 1
(b) 4
(c) 4
(d) 2
(e) 4
(f) 8
(g) 5
Q# 8:
Write a single instruction that moves the first two bytes in myBytesto the
DX register. The resulting value will be 2010h.
mov dx, WORD PTR myBytes
Q# 9:
Write an instruction that moves the second byte in myWordsto the AL
register.
mov al, BYTE PTR myWords1
Q# 10:
Write an instruction that moves all four bytes in myBytesto the EAX
register.
moveax, DWORD PTR myBytes
Q# 11:
Insert a LABEL directive in the given data that permits myWordsto be
moved directly to a 32-bit register.
Data directive:
myWordsD LABEL DWORD
myWords WORD 3 DUP(?),2000h
.code
moveax,myWordsD
Q# 12:
Insert a LABEL directive in the given data that permits myBytesto be
moved directly to a 16-bit register.
Data directive:
myBytesW LABEL WORD
myBytes BYTE 10h,20h,30h,40h
.code
movax,myBytesW

Indirect Addressing
Section Review 4.4
Question#1:

(True/False): Any 16-bit general-purpose register can be used


as an indirect operand.
False.
Question#2:

(True/False): Any 32-bit general-purpose register can be used


as an indirect operand.
True
Question#3:

(True/False): The BX register is usually reserved for


addressing the stack.
False.
Question#4:

(True/False): A general protection fault occurs in real-address mode when


an array subscript is out of range.
False.
Question#5:

(True/False): The following instruction is invalid: inc [esi]


True (the PTR operator is required).
Question#6:
(True/False): The following is an indexed operand:
array[esi]
Use the following data definitions for the remaining questions in this
section:
myBytes BYTE 10h,20h,30h,40h
myWords WORD 8Ah,3Bh,72h,44h,66h
myDoubles DWORD 1,2,3,4,5
myPointer DWORD myDoubles
True

Question#7:

Fill in the requested register values on the right side of the


following instruction sequence:
Movesi,OFFSETmyBytesmov al,[esi] ; a. AL =
Mov al,[esi+3] ; b. AL =
Movesi,OFFSETmyWords + 2 mov ax,[esi] ; c. AX =
Mov edi,8movedx,[myDoubles + edi] ; d. EDX =
movedx,myDoubles[edi] ; e. EDX =
movebx,myPointermoveax,[ebx+4] ; f. EAX =
(a) 10h
(b) 40h
(c) 003Bh
(d) 3
(e) 3
(f) 2
Question#8:

Fill in the requested register values on the right side of the following
instruction sequence:
Movesi,OFFSETmyBytes
mov ax,[esi] ; a. AX =
moveax,DWORD PTR myWords ; b. EAX =
movesi,myPointermov ax,[esi+2] ; c. AX =
mov ax,[esi+6] ; d. AX =
mov ax,[esi-4] ; e. AX =
(a) 2010h

(b) 003B008Ah
(c) 0
(d) 0
(e) 0044h

JMP and LOOP Instructions


Section Review 4.5
Question#1:

What are the three basic types of operands?


True.
Question#2:
(True/False): The destination operand of a MOV instruction
cannot be a segment register.
False.
Question#3:

(True/False): In a MOV instruction, the second operand is


known as the destination operand.
4,294,967,296 times.
Question#4:

(True/False): The EIP register cannot be the destination


operand of a MOV instruction.
False.
Question#5:

In the operand notation used by Intel, what does reg/mem32


indicate?
True.

Question#6:

In the operand notation used by Intel, what does imm16 indicate?


Use the following variable definitions for the remaining questions in this
section:
.data
var1 SBYTE -4,-2,3,1
var2 WORD 1000h,2000h,3000h,4000h
var3 SWORD -16,-42
var4 DWORD 1,2,3,4,5
CX.

Question#7: For each of the following statements, state whether or not the
instruction is valid:
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. movds,ax
h. mov ds,1000h
ECX.

Question#8:

What will be the hexadecimal value of the destination


operand after each of the following instructions execute in sequence?
mov al,var1 ; a.
mov ah,[var1+3] ; b.
False (-128 to 127 bytes from the current location).
Question#9:
What will be the value of the destination operand after each of the
following instructions execute in sequence?
mov ax,var2 ; a.
mov ax,[var2+4] ; b.
mov ax,var3 ; c.
mov ax,[var3-2] ;d
This is a trick! The program does not stop, because the first LOOP instruction decrements
ECX to zero. The second LOOP instruction decrements ECX to FFFFFFFFh, causing the
outer loop to repeat.
Question#10 :

What will be the value of the destination operand after


each of the following instructions execute in sequence?
Mov edx,var4 ; a.
Movzx edx,var2 ; b.
Movedx,[var4+4] ; c.
movsx edx,var1 ; d.
Insert the following instruction at label L1: push ecx. Also insert the following instruction
before the second LOOP instruction: pop ecx. (Once you have added these instructions, the
final value of eax is 1Ch.)

You might also like