ECE351 PreMidterm
ECE351 PreMidterm
Faculty of Engineering
Sphinx University
MICROPROCESSORS
Introduction
A Historical Background & Basic Concepts
The Mechanical Age The Analytical Engine required more than 50,000
machined parts, which could not be made with enough
The idea of a computing system is not new—it has been precision to allow his engine to function reliably.
around long before modem electrical and electronic
devices were developed. The idea of calculating The Electrical Age
with a machine dates to 500 BC when
the Babylonians, the ancestors of the The 1800s saw the advent of the electric motor
present-day Iraqis, invented the abacus, (conceived by Michael Faraday). These
the first mechanical calculator. electrically driven mechanical
calculators were common pieces of
The abacus was not improved until 1642, when office equipment.
mathematician Blaise Pascal invented a calculator that
was constructed of gears and wheels. In 1889, Herman Hollerith developed a mechanical
The PASCAL programming language machine—driven by one of the new electric motors—that
is named in honor of Blaise Pascal for counted, sorted information. Mechanical
his pioneering work with the machines driven by electric motors
mechanical calculator. The arrival of continued to dominate the information
the first practical geared mechanical machines used to processing world until the construction of
automatically compute information dates to the early the first electronic calculating machine
1800s. in 1941.
Charles Babbage was commissioned in A German inventor named Konrad Zuse invented the first
1823 by the Royal Astronomical Society modern electromechanical computer.
of Great Britain to produce a
calculating machine.
His Z3 calculating computer was probably invented for The first general-purpose, programmable electronic
use in aircraft and missile design during World War II for computer system was developed in 1946 at the University
the German war effort. The Z3 was a of Pennsylvania. This first modem computer was called
relay logic machine that was the ENIAC (Electronic Numerical Integrator and
clocked at 5.33 Hz (far slower than Calculator). The ENIAC was a huge machine, containing
the latest multiple GHz over 17,000 vacuum tubes and over 500 miles of wires.
microprocessors). This massive machine weighed over 30 tons, yet
performed only about 100,000 operations per second.
The ENIAC was programmed by
Later in 1939, Zuse constructed his first electromechanical rewiring its circuits—a process
computer system, called the Z2. that took many workers several
days to accomplish. The
workers changed the electrical
connections on plug-boards
that looked like early telephone
switchboards.
This first electronic computing system, which used
vacuum tubes, was invented by Alan Turing. Turing called Breakthroughs that followed were the development of
his machine Colossus, probably because of its size. the transistor on December 23,
Colossus was not programmable— 1947 at Bell Labs by John
it was a fixed-program computer Bardeen, William Shockley,
system, which today is often called and Walter Brattain.
a special purpose computer.
This was followed by the 1958 invention of the integrated One such early video game, a shuffleboard game, was
circuit by Jack Kilby of Texas Instruments. produced by Bailey. The main problems with this early
microprocessor were its speed, word width, and memory
size.
The Microprocessor Age Later in 1971, realizing that the microprocessor was a
commercially viable product, Intel Corporation released
The world’s first microprocessor, the Intel 4004, was a 4-bit the 8008—an extended 8-bit version of the 4004
microprocessor–programmable controller on a chip. It microprocessor which could address a 16KB memory.
addressed a mere 4096 bytes (4 KB), 4-bit-wide memory Intel recognized some limitations, so they introduced the
locations. The 4004 instruction set contained only 45 8080 microprocessor in 1973—the first of the modem 8-bit
instructions. The 4-bit microprocessor debuted in early microprocessors.
video game systems and small microprocessor-based
control systems.
In 1977, Intel Corporation introduced an updated version Improvements to the instruction set included multiply and
of the 8080—the 8085. The 8085 was to be the last 8-bit, divide instructions, which were missing on earlier
general-purpose microprocessor developed by Intel. microprocessors.
Although only slightly more advanced than an 8080
microprocessor, the 8085 executed software at an even
higher speed. The main advantages of the 8085 were its In addition, the number of instructions increased from 45
internal clock generator, internal system controller, and on the 4004, to 246 on the 8085, to well over 20,000
higher clock frequency. This higher level of component variations on the 8086 and 8088 microprocessors. Note
integration reduced the 8085’s cost and increased its that these microprocessors are called CISC (complex
usefulness. instruction set computers) because of the number and
complexity of instructions.
The Modern Microprocessor
The 16-bit microprocessor evolved mainly because of the
In 1978, Intel released the 8086 microprocessor; a year or need for larger memory systems. The popularity of the
so later, it released the 8088. Both devices are 16-bit Intel family was ensured in 1981, when IBM Corporation
microprocessors, which executed instructions in as little as decided to use the 8088 microprocessor in its personal
400 ns (2.5 MIPs, or 2.5 millions of instructions per second).
computer. Applications such as spreadsheets, word
This represented a major improvement over the
execution speed of the 8085. In addition, the 8086 and processors, spelling checkers, and computer-based
8088 addressed 1M byte of memory, which was 16 times thesauruses were memory-intensive and required more
more memory than the 8085 (A 1M-byte memory than the 64K bytes of memory found in 8-bit
contains 1024KB sized memory locations or 1,048,576 microprocessors to execute efficiently. The 16-bit 8086
bytes) and a 4-byte instruction cache. The featured and 8088 provided 1M byte of memory for these
instruction cache sped the operation of many sequences applications. Soon, even the 1M-byte memory system
of instructions and proved to be the basis for the much proved limiting for large databases and other
larger instruction caches found in modem applications. This led Intel to introduce the 80286
microprocessors.
microprocessor, an updated 8086, in 1983.
The 80286 microprocessor was almost identical to the The Pentium contained a 16K-byte cache, which contains an
8086 and 8088, except it addressed a 16M-byte memory 8K-byte instruction cache and an 8K-byte data cache.
system instead of a 1M-byte system. The instruction set of
the 80286 was almost identical to the 8086 and 8088, A 1995-entry from Intel is the Pentium Pro processor, formerly
except for a few additional instructions. named the P6 microprocessor. In addition to the internal 16K
level-one (L1) cache (8K for data and 8K for instructions) the
Pentium Pro processor also contains a 256K level-two (L2)
Applications began to demand faster microprocessor
cache. One other significant change is that the Pentium Pro
speeds, more memory, and wider data paths. This led to
processor uses three execution engines, so it can execute up
the arrival of the 80386 in 1986 by Intel Corporation. The to three instructions at a time. This represents a change from
80386 represented a major overhaul of the 16-bit 8086 the Pentium, which executes two instructions simultaneously.
architecture. The 80386 was Intel’s first practical 32-bit
microprocessor that contained a 32-bit data bus and a The Pentium II microprocessor (released in 1997) represents a
32-bit memory address. new direction for Intel. The microprocessor on the Pentium II
module is, actually, Pentium Pro with MMX extensions.
In 1989, Intel released the 80486 microprocessor, which
incorporated an 80386-like microprocessor. Although the The Pentium III (released in 1999) microprocessor uses a faster
80486 microprocessor was not radically different from the core than the Pentium II.
80386, it did include one substantial change — 8K byte
cache memory. The internal structure of the 80486 was The Pentium 4 microprocessor was first made available in late
modified from the 80386 to support instruction pipelining. 2000 and had enhancements for multimedia and graphics.
SS (stack)
The stack segment defines the area of memory used for
the stack. The stack entry point is determined by the
stack segment and stack pointer registers.
Lecture 1
The 80x86 Microprocessor and Its Architecture
14
Inside The 8086 Intel implemented the concept of pipelining in the
8088/86 by splitting the internal structure of the
There are two ways to make the CPU process information microprocessor into two sections: the execution unit (EU)
faster. and the bus interface unit (BIU). These two sections work
simultaneously.
The first option is to increase the working frequency,
where the designer must use the required technology
and materials in making ICs (integrated circuits)
determine the working frequency, power consumption,
and the number of transistors packed into a single-chip
microprocessor. A detailed discussion of IC technology is
beyond the scope of this course.
This works only if the BIU keeps ahead of the EU; thus, the While the CPU can work only in binary, it can do so at
BIU of the 8086 has a buffer, or queue. very high speeds. However, it is quite tedious and slow for
humans to deal with 0s and 1 s in order to program the
The buffer is 6 bytes in the 8086. If any instruction takes computer. A program that consists of 0s and 1 s is called
too long to execute, the queue is filled to its maximum machine language, and in the early days of the
capacity and the buses will sit idle. computer, programmers actually coded programs in
machine language.
The BIU fetches a new instruction whenever the queue
has room for 2 bytes in the 6-byte 8086 queue.
Although the hexadecimal system was used as a more
In some circumstances, the microprocessor must flush out efficient way to represent binary numbers, the process of
the queue. For example, when a jump instruction is working in machine code was still cumbersome for
executed, the BIU starts to fetch information from the new humans, so, eventually, Assembly languages were
location in memory and information in the queue that developed.
was fetched previously is discarded. In this situation the
EU must wait until the BIU fetches the new instruction. This Assembly language programs must be translated into
is referred to in computer science terminology as a machine code by a program called an assembler.
branch penalty. In a pipelined CPU, this means that too
much jumping around reduces the efficiency of a
Assembly language is referred to as a low-level language
program.
because it deals directly with the internals of the CPU.
Pipelining in the 8086 has two stages: fetch and execute,
but in more powerful computers pipelining can have To program in Assembly language, the programmer must
many stages. know the number of registers and their size, as well as
other details of the CPU.
Today, one can use many different programming For example, the instruction "MOV DX,CX" copies the
languages, such as C, Python and numerous others. contents of register CX to register DX.
These languages are called high-level languages
because the programmer does not have to be After this instruction is executed, register DX will have the
concerned with the internal details of the CPU. same value as register CX.
High-level languages are translated into machine code The MOV instruction does not affect the source operand.
by a program called a compiler. For instance, to write a
program in C, one must use a C compiler to translate the The following program first loads CL with value 55H, then
program into machine language. moves this value around to various registers inside the
CPU.
There are numerous assemblers available for translating
80x86 Assembly language programs into machine code.
One of the most commonly used assemblers is MASM by
Microsoft.
MOV Instruction
Simply stated, the MOV instruction copies data from one The use of l6-bit registers is demonstrated below.
location to another. It has the following format:
ADD instruction
The ADD instruction tells the CPU to add the source and
To load a value into a segment register, first load it to a the destination operands and put the result in the
nonsegment register and then move it to the segment destination.
register, as shown next.
To add two numbers such as 25H and 34H, each can be
moved to a register and then added together:
Executing the program results in AL = 59H (25H + 34H = 2. The largest number that an 8-bit register can hold is
59H) and BL = 34H. Notice that the contents of BL do not FFH. To use numbers larger than FFH (255 decimal), 16-bit
change. registers such as AX, BX, CX, or DX must be used. For
example, to add two numbers such as 34EH and 6A5H,
The program can be written in many ways, depending on the following program can be used:
the registers used. Another way might be:
Rules of ADD instruction 3. Again, any 16-bit nonsegment registers could have
been used to perform the action above:
1. It is not necessary to move both data items into
registers before adding them together. The source
operand can be either a register or immediate operand.
Look at the following variation of the same program: The general-purpose registers are typically used in
arithmetic operations. Register AX is sometimes referred
to as the accumulator.
Program Segments Logical Address and Physical Address
A segment is an area of memory that includes up to 64K In Intel literature concerning the 8086, there are three
bytes and begins on an address evenly divisible by 16 (such
types of addresses mentioned frequently: the physical
an address ends in 0H). A typical Assembly language
program consists of at least three segments: a code address, the offset address, and the logical address.
segment, a data segment, and a stack segment.
The physical address is the 20-bit address that is actually
The code segment contains the Assembly language put on the address pins of the 8086 microprocessor. This
instructions that perform the tasks that the program was address can have a range of 00000H to FFFFFH for the
designed to accomplish.
8086. This is an actual physical location in RAM or ROM
The data segment is used to store information (data) that within the 1-megabyte memory range.
needs to be processed by the instructions in the code
segment. The offset address is a location within a 64K-byte segment
range. Therefore, an offset address can range from 0000H
The stack segment is used to store information temporarily.
to FFFFH.
The extra segment is a segment register used as an extra
data segment. Although in many normal programs this The logical address consists of a segment value and an
segment is not used, its use is absolutely essential for string offset address.
operations.
The differences among these addresses and the process
In the 80x86 there can be up to 64KB of memory assigned to of converting from one to another is best understood in
each category. The 8086 can only handle a maximum of the context of some examples, as shown next.
64KB of code and 64KB of data and 64KB of stack at any
given time, although it has a range of 1MB of memory.
Code Segment
The physical address for the location of the instruction is Since IP can have a minimum value of 0000H and a
generated by shifting the CS left one hex digit and then maximum of FFFFH, the logical address range in this example
is 2500:0000 to 2500:FFFF. This means that the lowest memory
adding it to the IP, which contains the offset address.
location of the code segment will be 25000H (25000 + 0000)
and the highest memory location will be 34FFFH (25000 +
The resulting 20-bit address is called the physical address FFFF).
since it is put on the external physical address bus pins to
be decoded by the memory decoding circuitry. Example 1-1
Solution:
(a) 24F6:634A (b) 634A
(c) 2B2AA (24F60 + 634A) (d) 24F60 (24F60 + 0000)
(e) 34F5F (24F60 + FFFF)
Logical & physical addresses in the code segment The physical address is an actual location within RAM (or
even ROM).
In the code segment, CS and IP hold the logical address
of the instructions to be executed. The following are the physical addresses and the
The following Assembly language instructions have been contents of each location for the program above.
assembled (translated into machine code) and stored in Remember that it is the physical address that is put on the
memory. address bus by the 8086 CPU to be decoded by the
memory circuitry:
If the data had to be stored at a different offset address, For the program, if the offset address where data is
say 450H, the program would have to be rewritten. located is changed, only one instruction will need to be
modified, and the rest of the program will be unaffected.
One way to solve this problem would be to use a register
to hold the offset address, and before each ADD, to Examining the program above shows that there is a
increment the register to access the next byte. Next a pattern of two instructions being repeated. This leads to
decision must be made as to which register to use. the idea of using a loop to repeat certain instructions.
The term pointer is often used for a register holding an The physical address for data is calculated using the
offset address. In the following example, BX is used as a same rules as for the code segment.
pointer:
The physical address of data is calculated by shifting DS
left one hex digit and adding the offset value, as shown
in following examples.
Example 1-2 Example 1-3
Assume that DS is 5000 and the offset is 1950. Calculate If DS = 7FA2H and the offset is 438EH,
the physical address of the byte. (a) Calculate the physical address.
(b) Calculate the lower range.
(c) Calculate the upper range of the data segment.
(d) Show the logical address.
Solution:
Solution: (a) 830AE (7FA20 + 438E) (b) 7FA20 (7FA20 + 0000)
(c) 8FA1F (7FA20 + FFFF) (d) 7FA2:438E
The physical address will be 50000 + 1950 = 51950.
Example 1-4
Solution:
No, since the range is 578C0 to 678BF, location 67F66 is
not included in this range. To access that byte, DS must
be changed so that its range will include that byte.
Little Endian Convention Example 1-5
Previous examples used 8-bit or 1-byte data. In this case Assume memory locations with the following contents:
the bytes are stored one after another in memory. What DS:6826 = 48 and DS:6827 = 22.
happens when 16-bit data is used? For example: Show the contents of register BX in the instruction "MOV
BX,[6826]".
Solution:
In cases like this, the low byte goes to the low memory According to the little-endian convention used in all
location and the high byte goes to the high memory 80x86 microprocessors, register BL should contain the
address. value from the low offset address 6826 and register BH the
value from offset address 6827, giving BL = 48H and BH =
22H.
In the example above, memory location DS: 1500
contains F3H and memory location DS: 1501 contains 35H. DS:6826 = 48
DS:6827 = 22
In the big-endian method, the high byte goes to the low
address, whereas in the little-endian method, the high
byte goes to the high address and the low byte to the
low address.
Memory map of the IBM PC Memory Stack
For a program to be executed on the PC, DOS must first
load it into RAM. Where in RAM will it be loaded? The stack is a section of read/write memory (RAM) used
by the CPU to store information temporarily.
The 20-bit address of the 8088/86 allows a total of 1
megabyte (1024K bytes) of memory space with the The CPU needs this storage area since there are only a
address range 00000 - FFFFF. limited number of registers. There must be some place for
the CPU to store information safely and temporarily.
During the design phase of the first IBM PC, engineers had
to decide on the allocation of the 1-megabyte memory Now one might ask why not design a CPU with more
space to various sections. This memory allocation is called
registers? The reason is that in the design of the CPU,
a memory map.
every transistor is precious and not enough of them are
available to build hundreds of registers. In addition, how
Of this 1 megabyte, 640K
bytes from addresses 00000 many registers should a CPU have to satisfy every possible
to 9FFFFH were set aside for program and application?
RAM.
The main disadvantage of the stack is its access time.
The 128K bytes from A0000H Since the stack is in RAM, it takes much longer to access
to BFFFFH were allocated compared to the access time of registers. After all, the
for video memory. registers are inside the CPU and RAM is outside.
The remaining 256K bytes
Some very powerful (and consequently, expensive)
from C0000H to FFFFFH were
set aside for ROM. computers do not have a stack; the CPU has a large
number of registers to work with.
How stacks are accessed As data is popped off the stack into the CPU, the TOS
location is incremented.
There must be registers inside the CPU to point to the
stack section of RAM. The two main registers used to When an instruction pushes or pops a general-purpose
access the stack are the SS (stack segment) register and register, it must be the entire 16-bit register. In other
the SP (stack pointer) register. These registers must be words, one must code "PUSH AX"; there are no instructions
loaded before any instructions accessing the stack are such as "PUSH AL" or "PUSH AH".
used.
The reason that the SP is decremented after the push is to
Every register inside the 80x86 (except segment registers make sure, that the stack is growing downward from
and SP) can be stored in the stack and brought back into upper addresses to lower addresses.
the CPU from the stack memory.
This is the opposite of the IP (instruction pointer). As was
The storing of a CPU register in the stack is called a push seen in the preceding section, the IP points to the next
while loading the contents of the stack into the CPU instruction to be executed and is incremented as each
register is called a pop. In other words, a register is instruction is executed.
pushed onto the stack to store it and popped of the
stack to retrieve it. To ensure that the code section and stack section of the
program never write over each other, they are located
The stack pointer register (SP) points at the current at opposite ends of the RAM memory set aside for the
memory location used for the top of the stack (TOS). program, and they grow toward each other but must not
meet. If they meet, the program will crash.
As data is pushed onto the stack, the TOS location is
decremented. The following examples show how the stack grows.
Pushing onto the stack Solution
Example 1-6
Popping the stack
Assuming that SP = 1236, AX = 24B6, DI = 85C2, and DX =
5F93, show the contents of the stack as each of the With every pop, the top 2 bytes of the stack are copied
following instructions is executed: to the register specified by the instruction and the stack
pointer is incremented twice.
Example 1-8
Solution:
(a) 44FFE (35000 + FFFE) (b) 35000 (35000 + 0000)
(c) 44FFF (35000 + FFFF) (d) 3500:FFFE
More About Segments in The 80x86 Example 1-9
Can a single physical address belong to many different What is the range of physical addresses if CS = FF59?
logical addresses? Yes, look at the case of a physical
address value of 15020H. There are many possible logical Solution:
addresses that represent this single physical address:
The low range is FF590 (FF590 + 0000).
In calculating the physical address, it is possible that two The flag register is a 16-bit register sometimes referred to
segments can overlap as shown below, which is desirable as the status register.
in some circumstances. For example, overlapping is used
in COM files. Only some of the bits are used. The rest are either
undefined or reserved by Intel.
CF, the Carry Flag. This flag is set whenever there is a carry The flag bits affected by the ADD instruction are CF (carry
out, either from d7 after an 8-bit operation, or from d15 after flag), PF (parity flag), AF (auxiliary carry flag), ZF (zero
a 16-bit data operation. flag), SF (sign flag), and OF (overflow flag).
PF, the Parity Flag. After certain operations, the parity of the
Example 1-10
result's low-order byte is checked. If the byte has an even
number of 1s, the parity flag is set to 1; otherwise, it is cleared.
Show how the flag register is affected by the addition of
AF, Auxiliary Carry Flag. If there is a carry from d3 to d4 of an 38H and 2FH.
operation, this bit is set; otherwise, it is cleared (set equal to
zero). This flag is used by the instructions that perform BCD Solution:
(binary coded decimal) arithmetic.
ZF, the Zero Flag. The zero flag is set to 1 if the result of an
arithmetic or logical operation is zero; otherwise, it is cleared.
Solution:
Solution:
CF = 0 since there is no carry beyond d15
PF = 0 since there is an odd number of 1s in the lower byte
AF = 1 since there is a carry from d3 to d4
ZF = 0 since the result is not zero
CF=1 since there is a carry beyond d7 SF = 1 since d15 of the result is one
PF =1 since there is an even number of 1s in the result
AF=1 since there is a carry from d3 to d4 Example 1-13
ZF =1 since the result is zero
SF =0 since d7 of the result is zero Show how the flag register is affected by
The parity bit only counts the lower 8-bits of the result and
is set accordingly. Also notice the CF bit.
CF = 1 since there is a carry beyond d15
PF = 1 since there is an even number of 1s in the lower byte
The carry flag is set if there is a carry beyond bit d15 AF = 1 since there is a carry from d3 to d4
instead of bit d7. ZF = 1 since the result is zero
SF = 0 since d15 of the result is zero
Notice the zero flag (ZF) status after the execution of the Use of the zero flag for looping
ADD instruction.
Since the result of the entire 16-bit operation is zero One of the most widely used applications of the flag
(meaning the contents of BX), ZF is set to high. register is the use of the zero flag to implement program
Do all instructions affect the flag bits? The answer is no; loops. The term loop refers to a set of instructions that is
some instructions such as data transfers (MOV) affect no repeated a number of times.
flags.
For example, to add 5 bytes of data, a counter can be
Example 1-14 used to keep track of how many times the loop needs to
be repeated. Each time the addition is performed the
Show how the flag register is affected by counter is decremented and the zero flag is checked.
2. Immediate addressing mode In the direct addressing mode, the data is in some
memory location(s) and the address of the data in
In the immediate addressing mode, the source operand memory comes immediately after the instruction. This
is a constant. For this reason, this addressing mode address is the offset address, and one can calculate the
executes quickly. However, in programming it has limited physical address by shifting left the DS register and
use. Immediate addressing mode can be used to load adding it to the offset as follows:
information into any of the registers except the segment
registers and flag registers.
In this case the physical address is calculated by 4. Register indirect addressing mode
combining the contents of offset location 2400 with DS,
the data segment register. In the register indirect addressing mode, the address of
the memory location where the operand resides is held
In the absence of the bracket around the address, it will by a register. The registers used for this purpose are SI, DI,
give an error since it is interpreted to move the value 2400 and BX. If these three registers are used as pointers, that
(l6-bit data) into register DL, an 8-bit register. is, if they hold the offset of the memory location, they
must be combined with DS in order to generate the 20-bit
Example 1-15 physical address. For example:
First AL is initialized to 99H, then in line two, the contents of The physical address is calculated by shifting DS left one
AL are moved to logical address DS:3518 which is hex position and adding BX to it. The same rules apply
1512:3518. Shifting DS left and adding it to the offset gives when using register SI or DI.
the physical address of 18638H (15120H + 3518H =
18638H). That means after the execution of the second
instruction, the memory location with address 18638H will
contain the value 99H.
Example 1-16 6. Indexed relative addressing mode
Assume that DS = 1120, SI = 2498, and AX = 17FE. Show the The indexed relative addressing mode works the same as
contents of memory locations after the execution of the based relative addressing mode, except that registers
DI and SI hold the offset address. Examples:
Solution:
Segment Overrides
The coding of the instructions above can vary; for
example, the last example could have been written The table below provides a summary of the offset
registers that can be used with the four segment registers
of the 80x86.
or
Note that "MOV AX,[SI][DI]+displacement" is illegal. The 80x86 CPU allows the program to override the default
segment and use any segment register. To do that,
specify the segment in the code.
For example, in "MOV AL,[BX]", the physical address of the The last table below summarizes all addressing modes.
operand to be moved into AL is DS:BX, as was shown
earlier since DS is the default segment for pointer BX.
41
Directives and A Sample Program Directives give directions to the assembler about how it
should translate the Assembly language instructions into
machine code.
The given Assembly language program below is a series
of statements, or lines, which are either Assembly An Assembly language instruction consists of four fields:
language instructions such as ADD and MOV, or
statements called directives or pseudo-instructions.
The ORG directive can be used to set the offset addresses for
data items. Although the programmer cannot assign exact
First, notice that the 16-bit data (a word) is stored with the physical addresses, one is allowed to assign offset addresses.
low-order byte first.
Program-3 Notice that C4 was coded in the data
segments as 0C4. This is required by the
Write and run a program that transfers 6 bytes of data from assembler to indicate that C is a hex number
memory locations with offset of 0010H to memory locations with and not a letter. This is required if the first digit is
offset of 0028H. a hex digit A through F.
In the sequence of instructions to be executed, it is often In the conditional jump, control is transferred to a new
necessary to transfer program control to a different location if a certain condition is met.
location. There are many instructions in the 80x86 to
achieve this. The flag register is the one that indicates the current
condition.
FAR and NEAR
Short jumps
CALLs to procedures are used to perform tasks that need As an example, assume that SP = FFFEH and the following
to be performed frequently. This makes a program more code is a portion of the unassembled program:
structured. The target address could be in the current
segment.
Since the CALL instruction is a NEAR call, meaning that it is The main program is the entry point from DOS and is FAR,
in the same code segment (same CS, different IP), only IP as explained earlier, but the subroutines called within the
is saved on the stack. main program can be FAR or NEAR. If there is no specific
In this case, the IP address of mention of FAR after the directive PROC, it defaults to
the instruction after the call is NEAR, as shown below.
saved on the stack as
indicated.
Subroutines
ORG is used to indicate the beginning of the offset DW is used to allocate memory 2 bytes (one word) at a
address. The number that comes after ORG can be either time. The following are some examples of DW:
in hex or in decimal. If the number is not followed by H, it
is decimal and the assembler will convert it to hex.
DB (define byte)
For decimal, the D after the number is optional, but using The DD directive is used to allocate memory locations
B (binary) and H (hexadecimal) for the others is required. that are 4 bytes (two words) in size. Again, the data can
To indicate ASCII, simply place the string in single or be in decimal, binary, or hex. In any case the data is
double quotations ("like this"). DB is the only directive that converted to hex and placed in memory locations
should be used for all ASCII data definitions. For example: according to the rule of low byte to low address and high
byte to high address. DD examples are:
DQ (define quadword) EQU (equate)
DQ is used to allocate memory 8 bytes (four words) in
This is used to define a constant without occupying a
size. This can be used to represent any variable up to 64 memory location. EQU does not set aside storage for a data
bits wide: item but associates a constant value with a data label so
that when the label appears in the program, its constant
value will be substituted for the label.