Asm
Asm
Asm
Page - 2 -
Laboratory Notes: Computer Architecture Course
Page - 3 -
Laboratory Notes: Computer Architecture Course
II Introduction
A personal computer is a general purpose system designed to accommodate different operating systems. The
link between the hardware and the OS is a set of software routines known as BIOS (Basic Input and Output
System). This program routines are permanently stored in ROM or PROM memory chip. Because of their
permanent nature, BIOS routines are referred to as firmware (Figure).
Application programs
Operating System
BIOS
Hardware
Page - 4 -
Laboratory Notes: Computer Architecture Course
CMOS and NMOS processors require 3.3 V and 3.45 V circuitry. Additional circuitry should be included in the
motherboard to transform the 5V into 3.3V or 3.45 V.
The power supply has also some protection features to minimize damage that could be caused by a permanent
or intermittent fault. For example, good quality supply shuts the power supply down if the current is exceeds a
safe level. However, it is always important to have a power protection system such as a UPS and a stabilizer
outside the computer in order to protect the computer’s components from damage.
There are two types of connectors from the output of the power supply. The first is a
V Memory
It is very important the computer has enough memory that it can access at a speed comparable to that of the
processor. The PC has a hierarchy of memory devices that serve various purposes.
Two main properties determine the use of particular types of memory: these are the storage capacity (size) and
access time (speed). There are chips of various sizes. In practice a number of chips are usually connected in
parallel to form what is known as memory bank. Access time is the speed at which a location within a memory
chip can be made available to the data bus. Access time is specified in nanoseconds and varies between 20 ns to
200ns.
Memory chip marking indicates its size and speed. A typical configuration is XXXYZZZ-S where XXX is the
manufacturer's identity, Y is the data width in bits, ZZZ is the number of locations in K and S is the speed in 10
ns. For example, TMS841128-7 indicates a chip with 128 K 1 bit locations and an access time of 70 ns.
Page - 5 -
Laboratory Notes: Computer Architecture Course
1 RAM
There are two types of RAM: dynamic (DRAM) and static (SRAM). DRAM stores information in the form of a
charge capacitor which value should be restored (refreshed) at frequent interval (2-4ms) due to leakage. DRAM
has a high storage capacity and low power consumption but they are relative slower (access time of around 60
ns). SRAM use flip-flops. They are very fast (access time 20 ns or less) but they are more expensive.
2 ROMs
ROM devices are considerably slower than RAM (access time of around 200 ns). There are several types of
ROM. Mask ROM is a non-volatile memory that can only be read. PROM fulfils the same basic functions as a
ROM but can also be programmed once by the user. EPROM fulfils the same basic functions as a ROM but can
also be programmed any number of times by erasing the previous content by exposing the memory cells to
ultra-violet light. The EEPROM can be programmed and erased while still in circuitry by application of suitable
electrical signals.
The Flash RAM is an advance on EEPROM. It can be erased and reprogrammed using normal voltages that are
available in the PC. However, flash RAM suffers from a short life span, and has a long access time of 60 to 150
ns.
3 Cache memory
When the speed of the processor is faster than the memory, it will have to wait after until it receives data from
memory. The ideal would be to use SRAM as main memory unit so that the speed of the memory is similar to
the speed of the processor. However, this is costly. Cache memory technique involves the use of a block of a
few KB (8-512 KB) of fast SRAM to store the contents of the most frequently accessed RAM locations. The
processor will first attempt to obtain instructions or data from the fast cache memory. If they are not available it
will turn to the slower DRAM.
4 Memory packaging
earlier computers used discrete memory chips. Nowadays memory chips are mounted in on a PCB in 16 or 32
bit format. The two commonly used versions are the SIMM (single line memory module) and the DIMM (dual-
line memory module).
VI Video Cards
Video cards create video images that the computer wants to send to the monitor. There are six main standards
of video cards. Technological advances have contributed considerably in the improvement of the video
standards. Today the video cards have complex processors that perform complex image processing tasks that
were formerly performed by the main processor of the computer. The following standards are the in use.
Page - 6 -
Laboratory Notes: Computer Architecture Course
5 VGA
VGA standard introduced in 1987 have become highly predominant for the decade that has followed. It is
compatible to EGA, CGA and MDA. The maximum resolution is 640*480 for 2, 4 or 16 colors. It can
display 256 colors for a resolution of 320*200. Since many hardware producers started to produce this card,
the users could buy high standard video cards for a reasonable price. Because of the competition, the producers
started to design new non standard enhanced VGA cards.
6 Super VGA
Electronically Super VGA cards resemble a lot VGA cards; however they are faster. They are also compatible
all the VGA modes and can produce more colors. They can display 256 colors in all the modes, not only in the
320*200 resolution mode.
Page - 7 -
Laboratory Notes: Computer Architecture Course
Page - 8 -
Laboratory Notes: Computer Architecture Course
error. If the screen fills with an indescribable mess of random characters or if the keyboard seems to become
inoperative, you have probably a system error. To recover from a system error try to return to DOS, find the
error and assemble, link and execute the program again. Very often, it is not easy to return to the DOS. The
following are some ways that will enable you to return to DOS:
1- Pressing Enter a few times
2- Pressing CTRL-Break
3- Pressing ALT-CTRL-Break
4- Resetting the computer
Of course, it is always better to start with the first option and execute the second only if the first doesn't work
and execute the third if the second doesn't work, etc. Resetting the computer should be the last option.
IV Exercise
1) Find the prog0201.asm program delivered with the elass environment, look at its content in an editor,
assemble it, link it and execute it.
Page - 9 -
Laboratory Notes: Computer Architecture Course
I The clock
A clock is a device inside the computer that send a steady, regular drumbeat of pulses. First, it sends out a high,
then a low, then a high etc. A clock high followed by a clock low is called a clock cycle.
Clock cycle
II Memory
The memory stores bits. Bits are organized into sets of eight bits to form a byte. The eight bits are number from
0 through 7.
Bit number 7 6 5 4 3 2 1 0
Bits' values 0 0 0 0 0 0 0 0
The memory is homogeneous and ordered. Bytes can be accessed sequentially. When a computer is designed to
process two or more bytes as a unit, that unit of memory is known as a words. For the 8086/8088 a word is two
bytes large. However it is also possible to address a single byte. For example, the byte at address 0 of the
memory is composed of the 8 bits at the address 0 while the word at the address 0 is composed of the 16 bits
found at the address 0 and 1.
Page - 10 -
Laboratory Notes: Computer Architecture Course
and puts a control signal on the control bus. Memory responds by putting the content at the given address in
memory onto the data bus. However, this takes half a dozen or more cycles.
The 8086 and the 8088 are two processor of Intel. They are identical from the programmer's perspective. The
only technical difference is that the 8088 has 8 lines data bus while the 8086 has 16 line data bus. This makes
the 8086 faster since it can get more data from memory in the same time.
1 CPU Registers
Registers serve two purposes. First, operations on registers are very fast compared to memory. Second, some
operations require the use of a register. The 8086/8088 contains eight general-purpose registers, four segment
registers, an instruction pointer, and a flag register. Each register is 16 bits wide.
AX AL AX
BH BL BX
CH CL CX
DH DL BX General Purpose
Registers
SI
Index Registers
DI
BP
Pointer Registers
SP
CS
SS
DS
ES
IP
AX
Page - 11 -
Laboratory Notes: Computer Architecture Course
The general purpose registers can all be used for arithmetic operations. The first four general purpose registers
(AX, BX, CX and DX) are separable and each of them can be treated as two 8 bit registers. For example, AX
can be separate into AH and AL. The programmer can use them for arithmetic operation.
The other four registers are index registers and pointer registers. They can also be used for arithmetic
operations. They can also be used to address data in memory. The SP is used specifically for the stack.
The other registers are used for purposes that will be indicated later.
Physical segment
A block of segment that begins on a paragraph boundary and extends for 65,536 Bytes ($10000) is called a
physical segment. There are 65,536 physical segments in the MAS. The physical segments overlap.
Page - 12 -
Laboratory Notes: Computer Architecture Course
Every Physical segment has a segment number, a base and a range. The segment number is the number of the
paragraph at which it begins. The base is the absolute address of the first byte in that paragraph. The range
extends from the base to the highest absolute address within it.
Exercise:
Complete the following table.
All physical segments have the same size. They logically wrap around at the top of the address space and
continue at the bottom.
Segment relative address
There is no 20 bit address in an 8086/8088 processor. Therefore there is no register that can hold the whole
address to be transmitted through the 20-lines address bus. In fact, segment relative addressing is used to
accessed the whole 1 MB address bus even though the registers are only 16 bit large.
Segment relative addressing is similar to the technique used by word-processor software to access a big file
using a small screen. With word-processors, since the screen is generally not large enough to show the whole
content of the file only a portion of that file will be shown at one given time. When the user needs to see or
modify a content in that file at a given position, he or she should scroll the file so that the screen shows that
position of the file. With segment relative addresses, at one given time, the programmer specifies the segment
of memory he/she wants to access and only that portion of the memory of size 216 Bytes can be accessed. If the
programmer needs to access a memory location that does not belong to that segment, he/she should first choose
another segment that contains the memory location he/she wishes.
To access a given memory location the programmer should provide a segment relative address composed of a
physical segment number and an offset. The physical segment number should identify a segment of the memory
that contains the specific location you want to access and the offset is the address of the specific location
relative to the beginning of the segment. Note that since the physical segments overlap, any given byte belong
to 4,096 segments. Also note that both the segment number and the offset can be stored in the 16 bit registers
available in the processor.
The 8086/8088 has four segment registers (CS, SS, DS and ES). The first three registers are respectively used
to store the segment number of the Code Segment, the Stack Segment and the Data Segment. ES is an extra
segment register that can be used by the programmer for its own purposes. These segment registers are used
independently from one another.
By convention segment relative addresses are expressed as follows:
<segment_number> : <offset>
Page - 13 -
Laboratory Notes: Computer Architecture Course
generally the segment_number is either a number in hexadecimal or a segment register. The offset can also be
either an hexadecimal number or a general purpose register. The CPU would find the absolute address by
summing the base of the segment and the offset. For example, the address 1234:5678 refers to the byte at the
offset $5678 in the segment $1234. The CPU will calculate the absolute address by adding $5678 (offset) to
$12340 base of the segment. The resultant absolute address would be $179B8.
Exercise:
Complete the following tables.
Logical segments
A logical segment is a part of a program designed to be loaded into memory beginning on a paragraph
boundary. An 8086/8088 program generally three segments: it always has a code segment that store instructions
of the program, and very often, it has a data segment that stores the data of the program and a stack segment
that is used for the purpose of the CPU. When the program is loaded, the paragraph number of the paragraph
starting from where it is loaded will be stored in the corresponding segment register. For example, if the code
segment is loaded at the paragraph that starts at the absolute address $1230, the segment register CS will be
assigned the value $123.
Physical and logical segments are related but they are not identical. Logical segments, like physical segments,
start at a paragraph boundary, but logical segments can have any length between 1 and 216 bytes unlike physical
segments that have exactly 216 bytes size. Logical segments are defined only in the context of a program, not by
the CPU and there can be any number of segments; there are always 216 physical segments. Logical segments
do not overlap while physical segments do.
The same address specification conventions can be used to reference a location in logical segment as a location
in physical segment.
IV Summary
This chapter has introduced the main components of the 8086/8088 processor. First, it explains how the clock
that drives the processor works. It then introduces how the physical memory is organizes into a sequence of
bytes. The CPU registers are introduced and their functions are briefly described. Finally, the memory address
space's organization has been explained in length by defining the paragraph, the physical segment and the
logical segment. This chapter also explains how segment relative addresses are used to access the whole
memory address space of 1 Megabyte.
Page - 14 -
Laboratory Notes: Computer Architecture Course
Page - 15 -
Laboratory Notes: Computer Architecture Course
An identifier is much like a variable name in a higher level language; it can be composed of alphabetical letters,
digits and special characters _, @, ?, ! and $ and the first character shouldn't be a digit.
A parameter extends and refines the meaning that the assembler attributes to the keyword in a statement. The
number of parameters that can be included in a given statement depends on the keyword.
There are three basic type of statements:
assembly language instruction: that specifies a instruction of the program that should be translated
into an machine language instruction
Ex:
ADD AX, BX
; Is an instruction that will add the content of AX and BX and will put the result in AX at
; execution time
data allocation statements that reserve memory area in the data segment for variable and assign their
initial values
Ex:
MESSAGE DB "Have a nice day!$"
; Is a data allocation statement that will reserve 17 bytes in the data segment and copy the value
; "Have a nice day!$" at loading time.
directives: that tell the assembler to work in a certain manner.
Ex:
LIST SCR
; Requests the assembler to display an annotated listing on the screen while assembling
2 Comments
It is equally or even more important to put comments in assembly language programs as in high level programs.
For ELASS, anything that follows semicolon in a given line is considered as a comment and will not be
processed by the assembler.
3 Directives
Assembly language directives are statements that describe the context in which the instructions in a program are
to be assembled into machine language and in which order the data allocation statements are to be processed
into data space. ELASS supports 28 different directives. Below are described some of the most important ones.
HEX directive
The HEX directive specifies the character that is used to indicate that a number is in hexadecimal notation. For
example, in the below program
HEX $
...
ADD AX, 10
ADD BX, $10
The first addition takes the value 10 in base 10 while the second takes it in base 16 (Hexadecimal). If the HEX
directive was not added, the assembler would take $10 as an identifier.
Page - 16 -
Laboratory Notes: Computer Architecture Course
SEGMENT directive
The SEGMENT directive defines the logical segment in which the subsequent instructions and data allocation
statements belong. It also gives a name for the base of that segment. This is very important since the address of
any element in an 8086/8088 program must be represented in a segment relative format. A segment ends where
another segment ends or where the ENDS directive is found.
Example:
ALPHA SEGMENT
.
.
.
ALPHA ENDS
BETA SEGMENT
.
.
.
BETA ENDS
An 8086/8088 program should of course specify a code segment and put all the instructions there. By default,
the linker takes the first segment as the CODE segment. The loader will put the paragraph number of the
paragraph where this segment is loaded into CS. Therefore, the programmer need not assign the value of CS.
When the program starts executing, IP will have the value 0. Thus the first instruction that will be executed will
be the one at the location CS:0000.
Hence, in the above example, ALPHA is the code segment and only assembly language instructions and
directives should be put there. There should be no data allocation statement in that segment.
As indicated earlier the programmer does not directly manipulate the stack. Therefore there is no statement
defined in the stack segment. However, the programmer should define the size of stack segment. For example:
TETA SEGMENT STACK $0400
defines a stack segment named TETA of size $400. The STACK that follows SEGMENT keyword indicates to
the linker that this directive defines the stack statement. The name of the segment is found at the beginning of
the statement and is arbitrary; it can even be STACK. The last value given at the end of the statement indicates
the size that the programmer wished to allocate for the stack. The author of DOS recommends that every
program should define at least $200 bytes of stack area. However, some applications that make heavy use of the
stack might need much more stack area. The loader automatically updates the SS segment register. Thus, there
is no need
While there is a way of specifying that a segment is code segment or a stack segment, there is no means for
specifying that a segment is a data segment. In fact there is no way for telling the linker where the data segment
is. Thus, when the program starts executing, the DS register is not assigned with the appropriate value. The
programmer himself/herself should write code that copies the paragraph number of the data segment into DS.
END Directive
This directive simply indicates that the end of the program is reached.
Page - 17 -
Laboratory Notes: Computer Architecture Course
5 Instruction statements
Instruction statements have the form:
{label:} mnemonic {operand {, operand}} {; comment}
An instruction can have one or more operands depending on the type of operation. When a mnemonic takes two
operands, the first is called the destination operand and the second is called the source operand. Below are
given some of the most common instructions:
The MOV instruction
Syntax:
MOV destination, source
MOV copies the content of the source into the destination. The source can be an immediate value (a value that
remains constant once the program is loaded), a register or a memory location. The destination can be a register
or a memory location.
There are some restrictions that apply on MOV and the programmer should see the detailed semantics of MOV
in a reference manual of the Assembly Language, in order to use it appropriately. For example, while it is
possible to copy an immediate value to a general purpose register using the MOV instruction, it is not possible
to copy an immediate value directly to the segment register DS; i.e. MOV AX, 0 is legal but MOV DS, 0 is
illegal.
Note:
There are a number of operators that can be used to request some tasks that can be performed by the assembler
or the linker. They have the following syntax:
OPERATOR OPERAND
This expression can replace an immediate value operand in an instruction. For example, in the following
instruction:
MOV AX, OFFSET MESSAGE
The expression OFFSET MESSAGE calculates the offset of the variable MESSAGE within the data segment
and puts the result as an operand. This is done before the program is loaded to be executed.
The INT instruction
Syntax:
INT interrupt_number
Page - 18 -
Laboratory Notes: Computer Architecture Course
The INT instruction calls software interrupts. These are a number of subroutines defined for the 8086/8088.
These subroutines are used by the operating system and other assembly level applications.
Some of the interrupts are used very frequently while others are rarely used. Interrupt number $21 is
particularly important since it has more than 100 functions supplied by DOS for I/O and other functions.
Interupt $21 should be used as follows:
MOV AH, function_number ; This puts the function number in AH
INT $21 ; This calls the specific function of the Interrupt
For example, to call function $09 of interrupt $21, we should write:
MOV AH, $09 ; This puts the function number ($9) in AH
INT $21 ; This calls the function $09 of Interrupt $21
In addition to the above, whenever a function of an interrupt is called, the parameters should be put in the
appropriate registers prior to calling the interrupt (INT $21 in the above case). For example, the function $09 of
INT $21 is a function that displays on the screen a string of characters stored in memory. Therefore, the
location of the string should be given as a parameter to the function prior to calling the interrupt. In this
particular case, the function expects the address of string to be displayed in DS:DX. For example, if the string is
found in the variable MESSAGE declared in the DATA segment, we should call the interrupt as follows
(assuming that DS already contains the paragraph number of the data segment):
MOV DX, OFFSET MESSAGE ; This puts the offset of MESSAGE in DX
MOV AH, $09 ; This puts the function number ($9) in AH
INT $21 ; This calls the function $09 of Interrupt $21
Another important function of INT $21 is function $4C. This function enables an assembler program that
terminates to transfer the control back to DOS operating system. Unless this function is called at the end of the
code segment the program will stop without transferring the control to the operating system, which will require
the user of the program to restart the computer at the end of each execution of the program. Function $4C
should be called as follows:
MOV AX, $4C00 ; This puts the function number ($4C) in AH
; and argument 00 in AL (which means no error)
INT $21 ; This calls the function $4C of Interrupt $21
Page - 19 -
Laboratory Notes: Computer Architecture Course
16-bit multiplication
AX
X
operand
DX AX
The multiplier is found in AX (default operand) and the multiplicand is the explicit operand found in the
instruction. The result of the operation will be found in DX (for the most significant word) and AX (for the
least significant word).
Page - 20 -
Laboratory Notes: Computer Architecture Course
8-bit multiplication
AL
X
operand
AH AL
The multiplier is found in AL (default operand) and the multiplicand is the explicit operand found in the
instruction. The result of the operation will be found in AH (for the most significant byte) and AL (for the least
significant byte).
In either 16-bit and 8-bit multiplication, the carry and Overflow flags will be set if the higher order register of
the product is non zero and cleared if it is zero.
The DIV instruction
Syntax:
DIV operand
Where operand is a general-purpose register or a memory location. DIV works differently whether the operand
is a 16-bit or 8-bit location.
16-bit division
DX AX
÷ operand
DX AX
The dividend is found in DX:AX and the divisor is the explicit operand found in the instruction. The result of
the operation will be found in AX (for the quotient) and DX (for the remainder).
Page - 21 -
Laboratory Notes: Computer Architecture Course
8-bit division
AH AL
÷ operand
AH AL
The dividend is found in AX and the divisor is the explicit operand found in the instruction. The result of the
operation will be found in AL (for the quotient) and AH (for the remainder).
Example of a program
; This program displays “HAVE A NICE DAY”
LIST SCR
HEX $
CODE SEGMENT
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET MESSAGE
MOV AH, $09
INT $21
MOV AX, $4C00
INT $21
STACK SEGMENT STACK $0400
DATA SEGMENT
MESSAGE DB "HAVE A NICE DAY.$"
END
Page - 22 -
Laboratory Notes: Computer Architecture Course
Command Action
R Displays the content of all registers
R register_name Displays the content of register register_name
U {address {l length}} Disassembles the code found at the address address and having the
length of length bytes. If length is not specified the default length is
120.
D {address {l length}} Dumps (displays) the content of the memory at the address address
and having the length of length bytes. If length is not specified the
default length is 180.
G {=address}{{breakpoint}} Go command: executes the program starting at the address address
and specifies breakpoints where the program stops.
Note: it is dangerous to execute G after the whole program has
executed.
T Trace command: displays the value of the registers after the
execution of the current instruction.
Note: Don’t use T command when the next instruction is an INT
P Process command: similar to T but also works with an INT
Q Quit the debugger and go to DOS
The following tips are useful to detect run time errors using your debugger:
- If your program may behave abnormally when executed, you should first run your program in the
debugger with a breakpoint set about halfway through it
- There are two kinds of breakpoints:
Page - 23 -
Laboratory Notes: Computer Architecture Course
Page - 24 -
Laboratory Notes: Computer Architecture Course
Update IP to
address at next instruction
Execute this
instruction
The control transfer instructions are special class of instructions that, when executed adjust the content of the IP
register and sometimes the CS register.
I Subroutines
A subroutine is a sequence of code designed to be invoked at one or several points in a program. It is invoked
with a CALL instruction and it returns to the point from which it was called with a RET instruction.
Subroutines are usually organized into procedures. A procedure starts with a PROC directive:
Syntax of PROC
procname PROC
Syntax of CALL
CALL procname
When CALL is executed, the CPU puts in IP the address of the instruction after the CALL without executing it.
Then it copies IP into the stack. Finally it adjusts IP so that it points to the first instruction of the called
procedure. After that the instructions will be executed one after the other until RET is executed.
When RET is executed the address in the stack is copied into IP. This will enable the control to return to the
calling program, just after the CALL statement.
Page - 25 -
Laboratory Notes: Computer Architecture Course
The order of procedures in the program is irrelevant for the program flow. However, the first procedure will be
the first to be executed.
II Jumps
Jumps enable to the programmer to unconditionally move the control to a designated instruction. This is
equivalent to GOTO command in higher level languages.
Syntax:
JMP label
Note:
Labels can be given to any line of a program (instruction, comment, blank, etc.)
III Branches
The branch instructions of the 8086/8088 assembly language are equivalent to the “if then else” instruction of
high level instructions. In the 8086/8088 assembly language there are a number of instruction that perform
branch operations.
A program branch is implemented as a two-step process:
- First, a compare instruction should be used to verify the condition
- Second, a conditional jump instruction should be used to jump or not to a given code according to
the result of the first instruction
The information obtained by the first instruction is passed to the second instruction using the flag register.
F E D C B A 9 8 7 6 5 4 3 2 1 0
O D I T S Z A P C
The following table gives the letter representing each flag, its name, the two-letter code used to indicate
whether the flag is set (1) or cleared (0) and the purpose of the flag.
Page - 26 -
Laboratory Notes: Computer Architecture Course
Note: You should see the reference manual of the language for the details as to which instructions affect which
flags.
2 Comparison
The CMP (CoMPare) instruction is used to compare two values and to adjust the status flags accordingly.
Syntax:
CMP destination, source
CMP subtracts the value of source from the value in destination. It does not store the result of the subtraction. It
sets the zero flad if the result is zero (the operands are equal). Otherwise it will clear the flag.
If the contents of the destination is below the content of the source, the carry flag is set; otherwise it is cleared.
The below table summarizes the actions of the CMP instruction
Page - 27 -
Laboratory Notes: Computer Architecture Course
3 Conditional Jumps
The conditional jump instructions enable the programmer to specify jumps that are conditional to the value of
one or several flags.
Syntax
JXXX label
XXX describes the condition for which you are testing. There are 31 conditional jumps that test a flag or a
combination of flags and jump to the label if the flag is set. Among the 31 jumps 15 of them are the converse of
the other 15. The 31st does not use a flag but tests the CX register.
Note: A number of jumps are equivalent.
There is one major caveat with conditional jumps: they have limited range. The opcode to which a conditional
jump directs a program flow must be at an offset in the range (XXXX-$007E) through (XXXX + $0081) where
XXXX is the offset of the jump instruction itself.
This restriction does not apply on the JMP command. We can therefore use a trick such as the following to
overcome this problem:
JNZ NEAR_AT_HAND
JMP LONG_WAY_OFF
NEAR_AT_HAND:
•••••
LONG_WAY_OFF
Page - 28 -
Laboratory Notes: Computer Architecture Course
4 Loops
A program loop can be implemented either with an explicit counter or an implicit counter. Explicit counter
usually use the fact that the DEC instruction not only subtracts 1 from the content of its operand but also sets
the Zero flag if the result of the subtraction is Zero.
LOOP_LABEL:
•••
DEC CX
JNZ LOOP_LABEL
The LOOP instruction can also be used to implicitly count the iterations of a loop. The below code is equivalent
to the above code, but uses an implicit count rather than an explicit.
LOOP_LABEL:
•••
LOOP LABEL
There are some variations on the LOOP instruction:
- LOOPZ Label will continue the loop while the zero flag is set and CX does not contain a value of
zero
- LOOPNZ will continue the loop while the zero flag is cleared and CX does not contain a
value of zero
Page - 29 -