The inforrm.tion in this document is subje<;t to without notK:e.

Intel Corpor<ltion rm.kes no wuunty of <lny kind with reprd to this rm.teri.lJ, includi,., but not limited to, the implMld
varnnttes of merch<lnubility <lnd fitness for <l .... purpose. Intel Corpor<ltion HSUrnes no responsibWity for <lny
errors that ma.y <lppur in this doc::ument. Intel Corpor<ltion rNkes no c.ornmitment to upd<t.te nor to keep current the
inforrm.tion conuined in this document.
The softwMe described in this document is furnished under <l Ik.ense ';lOd rNy be or copied only in iGCOrcRnu with
the terms of such lK:enst.
Intel Cofporiltion <lSsurnes no responsibility for the use or reli<lbility of its softw<lre on equipment tNt is not suppUed by
Intel.
No p<lrt of this doc::ument rm.y be copied or reproduud in any form or by ilny muns without the prklr written consent
of Intel Corpoutt<m.
The <lre trademMks of Intel Corpoution <lnd rm.y be used only to desc.ribe Intel products:
ICE-30
ICE-48
ICE-SO
ICE-8S
INSITE
INTEL
INTEllEC
LIBRARY MANAGER
MCS
MEGACHASSIS
MICROMAP
MUlTIBUS
PROMPT
UPI
Ir-I---------------,1
8080/8085 ASSEMBLY LANGUAGE
PROGRAMMING MANUAL
Copyright © 1977,1978 Intel Corporation
Intel Corporation, 3065 Bowers Avenue, Santa Clara, California 95051
PREFACE
This manual describes programming with Intel's assembly language. It will not teach you how to program a computer.
Although this manual is designed primarily for reference, It also contains some instructional matenal to help the beginning
programmer. The manual is organized as follows:
Chapter 1.
Chapter 2.
Chapter 3.
Chapter 4.
Chapter 5.
Chapter 6.
Chapter 7,
ASSEMBLY LANGUAGE AND PROCESSORS
Description of the assembler
Overview of 8080 hardware and instruction set
Description of 8080(8085 differences
ASSEMBLY LANGUAGE CONCEPTS
General assembly language coding rules
INSTRUCTION SET
Descriptions of each instruction (these are listed alphabetically
for quick reference)
ASSEMBLER DIRECTIVES
Data definition
Conditional assembly
Relocation
MACROS
Macro directives
Macro examples
PROGRAMMING TECHNIQUES
Programming examples
INTERRUPTS
Description of the Interrupt system.
Chapters 3 and 4 will fill most of the experienced programmer's reference requirements. Use the table of contents or the
index to locate information quickly,
The beginning programmer should read Chapters 1 and 2 and then skip to the examples in Chapter 6. As these examples
raise questions, refer to the appropriate information in Chapter 3 or 4. Before writing a program, you will need to read
Chapter 4. The 'Programming Tips' in Chapter 4 are intended especially for the beginning programmer.
iii
RELATED PUBLICATIONS
To use your Intellec development system effectively, you should be familiar with the following Intel
publications:
ISIS-II 8080/8085 IAACRO ASSEMBLER OPERATOR'S MANUAL, 9800292
When you activate the assembler, you have the option of specifying a number of controls. The operator's
manual descriJes the activation sequence for the assembler. The manual also describes the debugging tools
and the error messages supplied by the assembler.
ISIS-II SYSTEM GUIDE, 9800306
User program; are commonly stored on diskette files. The ISIS-II User's GUide describes the use of the text
editor for entering and maintaining programs. The manual also describes the procedures for linking and
locating reloc Itable program modules.
Hardware
For addition21 information about processors and their related components, refer to the appropriate User's
Manual:
8080 MICROCOMPUTER SYSTEMS USER'S MANU,A,L, 9800153
8085 MICROCOMPUTER SYSTEMS USER'S MANUAL, 9800366
iv
TABLE OF CONTENTS
Chapter 1. ASSEMBLY LANGUAGE AND PROCESSORS
Introduction
What Is An Assembler?
What the Assembler Does
Oblect Code
Program Listing
Symbol-Cross-Reference Listing
Do You Need the Assembler?
Overview of 8080/8085 Hardware
Memory
ROM
RAM
Program Counter
Work Registers
Internal Work Registers
Condition Flags
Carry Flag
Sign Flag
Zero Flag
Parity Flag
Auxiliary Carry Flag
Stack and Stack Pointer
Stack Operations
Saving Program Status
Input/Output Ports .
Instruction Set
Addressing Modes
Implied Addressing
Register Addressll1g
Immediate Addressll1g
Direct Addressll1g
Register Indirect Addressing
Combined Addressing Modes
Ti mll1g Effects of Addressll1g Modes
Instruction Namll1g Conventions
Data Transfer Group
Arithmetic Group
Logical Group
Branch Group
Stack, I/O, and Machine Control Instructions
Hardware/Instruction Summary
Accumulator Instructions
Register Pair (Word) Instructions
Branching Instructions
Instruction Set Guide
1-1
1-1
1-1
1-1
1-2
1-2
1-3
1-3
1-5
1-5
1-5
1-5
1-6
1-7
1-9
1-9
1-10
1-10
1-11
1-11
1-11
1-12
1-13
1-13
1-14
1-15
1-15
1-15
1-15
1-15
1-15
1-16
1-16
1-16
1-16
1-16
1-17
1-17
1-18
1-19
1-19
1-19
1-21
1-22
1-23
v
8085 Proc Differences
Pr )gramming for the 8085
Cc nditional Instructions
Chapter 2. ASSEMIILY LANGUAGE CONCEPTS
Introdu( tion
Source Line Format
Garacter Set
Delimiters
Label/Name Field
Ol'code Field
Or'erand Field
Cc mment Field
Coding Operand Field Information
He xadecimal Data
Decimal Data
O( tal Data
Bilary Data
Lc cation Counter
Constant
Labels Assigned Values
Labels of Instruction or Data
E> pressions
In ;tructions as Operands
R( gister-Type Operands
Two's Complement Representation of Data
and Symbol Tables
Sy mbol ic Addressing
Sy mbolic Characteristics
Reserved, User-Defined, and Assembler-Generated Symbols
Global and Limited Symbols
Permanent and Redefinable Symbols
Absolute and Relocatable Symbols
Assembl I-Time Expression Evaluation
Or erators
Arithmetic Operators
Shift Operators
Logical Operators
Compare Operators
Byte Isolation Operators
Pe 'missible Range of Values
Pr"cedence of Operators
Rdocatable Expressions .
Cllaining of Symbol Definitions
1-24
1-24
1-25
2-1
2-1
2-1
2-1
2-2
2-3
2-4
2-4
2-4
2-4
2-5
2-5
2-5
2-5
2-6
2-6
2-6
2-6
2-6
2-7
2-7
2-7
2-9
2-9
2-9
2-9
2-10
2-11
2-11
2-11
2-11
2-12
2-12
2-13
2-13
2-14
2-15
2-15
2-16
2-18
Chapter 3.
vi
INSTRlCTION SET
How tc Use this Chapter
Timing Information
In ;tructions are listed in alphabetical order
3-1
3-1
3-1
Oupter 4. ASSEMBLER DIRECTIVES
Symbol Definition
EQU Directive
SET Directive
Data Definition
DB Directive
OW Directive
Memory Reservuion
OS Directive
Programming Til»; D.Ha Description and Access
R.mdom Acee..s Versus ReAd Only Memory
Dua Desuiption
O.. ta Access
Add Symbols for DaLli Access
Conditional Assembly
IF, ELSE, ENDIF Directives
Assembler Termination
END Directive
Location Counter Control and Relocation
location Counter Control (Non·Rcloc.aubic Mode)
ORG Directive
Introduction to Rdocatability
Memory Management
Modular ProgrOlm Development
Directives Used for Relocation
location Counter Conlrol (Reloc<l.table Programs)
ASEG Directive
CSEG Directive
OSEG Directi"e
ORG Directive (Relocatable Mode)
Program linkage Directives
PUBLIC Directive
EXTRN Directive
NAME Directive
STKLN Directive
STACK and MEMORY Reserved Words
Programming Tips: Testing Relocatable Modules
Routines
Input/Output
Remove Coding Used for Testing
Chapter S. MACROS
Introduction to Macros
Why Us.e Macros?
Wha t Is A Macro!
Macros Vs. Subroutines
4-1
4-2
4-2
4·3
4-3
4·3
44
4-5
4-5
4-6
4-6
4-6
4-6
4-7
4-8
4-8
4-10
4-10
4-11
4-11
4-11
4-12
4-12
4-12
4-14
4-14
4-14
4-15
4-15
4-16
4-16
4-17
4-17
4-18
4-18
4-19
4-19
4-19
4-20
4-20
5·1
5·1
5-1
5-1
5-3
vii
Lking M.cros
MUfo Definition
M.cro Ddinition
MACRO
ENOM Oirectiw:
LOCAL Oirel.livc
REPT Dircllive
IRP Directive
IRPC Directive
EXITM Directive
(Jpft.ators
Nested "bero Definitions
DU\
Muro DII fOflTWt
Nested ulls
M.u..ru E).p4n,iun
Null M.cros
s.ample Macros
Ch.tptt'r 6. PRCXiRAMMING TECHNIQUES
Brlinch T.. oles
lr.. mlt'rrinl DOll. [0 Subroutine
Soflw.;ue Multiply lind
Multibyte Addition .nd SublrliCiion
DecirTldl Addition
Oecimal SubU,t..:tlon
Ch.. pter 7.INTERRUPTS
Interrupt ConcepH
Writing Interrupt Subroutint's
5-3
S·)
S4
S4
S-5
S·S

S·8
S-8
S·9
S·IO
S·12
5·12
S·12
S·I'
S·IS
S·16
.1·16
6·\
6-\
. 6·)
.6·7
6-11
6·\2
6-14
7·\
7·\
7·4
A
Appcndi). 8
Appendix C
Appendi). 0
viii
INSTRUCTIO SUMMARY
ASSEMBLER DIRECTIVE SUMMARY
ASCII CHARACTE R SET
BINARY·DECIMAL·HEXADECIMAL CONVERSION TABLES·
A·\
B·I
C.I
0·1
Figure
1-1
1-2
1-3
1-4
1-5
LIST OF ILLUSTRATIONS
ASSEMBLER OUTPUTS
COMPARISON OF ASSEMBLY LANGUAGE WITH PL/M
8080{8085 INTERNAL REGISTERS
INSTRUCTION FETCH
EXECUTION OF MOV M,C INSTRUCTION
1-2
1-4
1-6
1-8
1-9
ix
1. ASSEMBLY LANGUAGE AND PROCESSORS
INTRODUCTION
Almost every line of source coding in an assembly language source program translates directly into a machine
instruction for a particular processor. Therefore, the assembly language programmer must be familiar with both
the assembly language and the processor for which he is programming. '
The first part of this chapter describes the assembler. The second part describes the features of the 8080 micro-
processor from a programmer's point of view. Programming diffel'ences between the 8080 and the 8085 micro-
processors are relatively minor. These differences are described in a short section at the end of this chapter.
WHAT IS AN ASSEMBLER?
An assembler IS a software tool - a program - deSigned to simplify the task of Writing computer programs. If
you have ever written a computer program directly in a machine-recognizable form such as binary or hexadecimal
code, you will appreciate the advantages of programming in a symbolic assembly language,
Assembly language operation codes (opcodes) are easily remembered (MOY for move instructions, JMP for jump).
You can also symbolically express addresses and values referenced in the operand field of instructions. Since you
assign these names, you can make them as meaningful as the mnemonics for the instructions. For example, if your
program nust manipulate a date as data, you can assign it the symbolic name DATE. If your program contains a
set of instructions used as a timing loop (a set of instructions executed repeatedly until a specific amount of time
has passed), you can name the instruction group TIMER.
What the Assembler Does
To use the assembler, you first need a source program. The source program consists of programmer-written
assembly language instructions. These instructions are written using mnemonic opcodes and labels as described
previously.
Assembly language source programs must be in a machine-readable form when passed to the assembler. The
Intellec development system includes a text editor that will help you maintain source programs as paper tape
files or diskette files. You can then pass the resulting source program fife to the assembler. (The text editor is
described in the ISIS-II System User's GUide.)
The assembler program performs the clerical task of translating symbolic code into ob/ect code which can be
executed by the 8080 and 8085 microprocessors. Assembler output consists of three possible files: the object
fife containing your program translated into object code; the list file printout of your source code, the assembler-
generated object code, and the symbol table; and the symbol-crass-reference file, a listing of the symbol-cross-
reference records.
1-1
Chapter 1. Assembly L a n ) ~ u a g e and Processors
OBJECT
FILE
SOU<.CE ASSEMBLER PROGRAM
PROGRAM
FIl.E
PROGRAM ~
LISTING
~ CROSS
REFERENCE
LISTING
Figure 1-1. Assembler Outputs
Oblect Code
For most mlcrxomputer applications, you probably will eventually load the oblect program into some form of
read only men ory, However, do not forget that the Intellec development system IS an 8080 microcomputer
system with raldom access memory, In most cases you can load and execute your oblCct program on the
development s"stem for teSlJng and debugging, TIllS allows you to test your program before your prototype
application sys:em IS fully developed,
A special featu,'e of this assembler IS that it allows you to request oblect code In a relocatable format. This frees
the programm( r from worrYing about the eventual mix of read only and random access memory In the application
system; indivicual porlJons of the program can be relocated as needed when the application design is final. Also,
a lal'ge progranl can be broken Into a number of separately assembled modules, Such modules are both easier to
code and to te;t, See Chapter 4 of this manual for a more thorough description of the advantages of the relocation
feature,
Program Listing
The program liitlng prOVides a permanent record of both the source program and the object code, The assembler
also provides diagnostic messages for common programming errors in the program listing. For example, if you
specify al6-bl value for an InstruclJon that can use only an 8-blt value, the assembler tells you that the value
exceeds the pe'missible range.
1-2
Chapter 1. Assembly Language and Processors
Symbol-Crass-Reference Listing
The symbol-crass-reference listing is another of the diagnostic tools provided by the assembler. Assume, for
example, that your program manipulates a data field named DATE, and that testing reveals a program logic
error In the handling of this data. The symbol-crass-reference listing simplifies debugging this error because it
POints you to each instruction that I"eferences the symbol DATE.
Do You Need the Assembler?
The assembler IS but one of several tools available for developing microprocessor programs. Typically, choosing
the most suitable tool IS based on cost restraints versus the required level of performance. You or your company
must determine cost restraints; the reqUired level of performance depends on a number of variables:
• The number of programs to be written: The greater the number of programs to be written, the more
you need development support. Also, It must be pOinted out that there can be penalties for not
wl"lting programs. When your application has access to the power of a microprocessor, you may be
able to provide customers with custom features through program changes. Also, you may be able to
add features through programming.
o The time allowed for programming: As the time allowed for programmll1g decreases, the need for
programmll1g support II1creases.
• The level of support for eXisting programs: Sometimes programming errors are not discovered until
the program has been 111 use for quite a while. Your need for programming support II1creases if you
agree to correct such errors for YOUI" customers. The number of supported programs In use can
multiply this requirement. Also, program support 15 frequently subrect to stringent time constraints.
If none of the factors described above apply to your Situation, you may be able to get along without the
assembler. Intel's PROMPT-80, for example, allows you to enter programs directly Into programmable read only
memory. You enter the program manually as a string of hexadeCimal digits. Such manual programming IS relatively
slow and more prone to human error than computer-assisted programmll1g. However, manual systems are one of
the least expensive tools available for mlcmprocessor programming. Manual systems may be SUitable for limited
applications, hobbyists, and those who want to explol"e possible applications for microprocessors.
If most of the factors listed preViously apply to you, you should explore the advantages of PL(M. PL/M IS
Intel's high-level language for program development. A high-level language is directed more to problem solVing
than to a particular microprocessor. TIllS allows you to write programs much more qUickly than a hardware·
oriented language such as assembly language. As an example, assume that a program must move five characters
from one location 111 memory to anothcr. Thc following cxample illustratcs the coding differences between
assembly language and PL/M. Since II1structions have not yet been described, the asscmbly language instructions
arc rcprescn ted by a flowchart.
1-3
Chapter 1. Assembly Lan 5uage and Processors
ASSEI Y LANGUAGE CODING
ILOAD ,<EGISTER WITH NUMBER
OF CHARACTERS TO BE MOVED
I
ILOAD ,<EGISTER PAIR B WITH
ADDRE SS OF SOURCE (FLD1)
I
LOAD PAIR D WITH
ADDRESS OF DESTINATION
(FLD2)
I
LOAD ,\CCUMULATOR WITH 1
BYTE FROM SOURCE FIELD
I
MOVE :HARACTER FROM
ACCUIV ULATOR TO DESTINA-
TION FIELD
I
IINCREMENT SOURCE ADDRESS
I
INCRHIENT DESTINATION
ADDRESS
I
IDECRE .ENT CHARACTER COUNT
NO
IS
CHARACTER
COUNT
=O?
YES
( CONTINUE
PL/MCODING
CALL MOVE(S,FLD2,FLD1);

Figure 1-2. Comparison of Assembly Language with PL/M
1-4
Chapter 1. Assembly Language and Processors
OVERVIEW OF 8080/8085 HARDWARE
To the programmer, the computer comprises the following parts:
• Memory
• The program cou nter
• Work registers
• Condition flags
• The stack and stack pointer
• Input/output ports
• The instruction set
Of the components listed above, memory is not part of the processor, but is of interest to the programmer.
Memory
Since the program required to drive a microprocessor resides'in memory, all microprocessor applications require
some memory. There are two general types of memory: read only memory (ROM) and random access memory
(RAM).
ROM
As the name Implies, the processor can only read instructions and data from ROM; it cannot alter the contents
of ROM. By contrast, the processor can both read from and write to RAM. Instructions and unchanging data
are permanently fixed into ROM and remain intact whether or not power is applied to the system. For this
reason, ROM is typically used for program storage in single-purpose microprocessor applications. With ROM you
can be certain that the program is ready for execution when power is applied to the system. With RAM a program
must be loaded into memory each time power is applied to the processor. Notice, however. that storing programs
in RAM allows a multi-purpose system since different programs can be loaded to serve different needs.
Two special types of ROM PROM (Programmable Read Only Memory) and EPROM (Eraseable Programmable
Read Only Memory) are frequently used during program development. These memories are useful during
program development since they can be altered by a special PROM programmer. In high-volume commercial
applications. these special memories are usually replaced by less expensive ROM's.
RAM
Even if your program resides entirely in ROM. your application is likely to require some random access memory.
Any time your program attempts to write any data to memory, that memory must be RAM. Also, if your pro-
gram uses the stack. you need RAM. If your program modifies any of its own instructions (this procedure is
discouraged), those instructions must reside in RAM.
The mix of ROM and RAM In an application IS important to both the system designer and the programmer.
Normally, the programmer must know the physical addresses of the RAM in the system so that data variables
1-5
Chapter 1. Assembly Lang Jage and Processors
can be assignee within those addresses. However, the relocation feature of this assembler allows you to code a
program witho!lt concern for the ultimate placement of data and instructions; these program elements can be
repositioned aLer the program has been tested and after the system's memory layout IS final. The relocation
feature is fully explained in Chapter 4 of this manual.
Program Counter
With the progr 1m counter, we reach the first of the 8080's Internal registers illustrated in Figure 1-3.
NOTE
Except for the differences listed at the end of this chapter,
the Information in this chapter applies equally to the 8080
and the 8085.
The program CJunter keeps track of the next instruction byte to be fetched from memory (which may be either
ROM or RAM:. Each time It fetches an instruction byte from memory, the processor increments the program
counter by on". Therefore, the program counter always indicates the next byte to be fetched. This process
continues as Ie ng as program instructions are executed sequentially. To alter the flow of program execution as
with a iump irstruction or a call to a subroutine, the processor overwrites the current contents of the program
counter with t le address of the new Instruction. The next instruction fetch occurs from the new address.
u
IACCUMULATORI FLAGS
I N S T R U C ~
B C
DECOD::R
D E
IDATA BUS_ATCH I H L
o
HIGH
STACK
PROGRAM
ADDRESS
LOW
POINTER
COUNTER
BUS LATCH
8080
8085
8-bit
bidirecti, Inal
data b JS
.--------,
16-bit
address bus
ROM
INSTRUCTIONS
CONSTANT
DATA
RAM
INSTRUCTIONS
VARIABLE
DATA
STACK
INPUT
PORTS
OUTPUT
PORTS
1-6
Figure 1-3. 8080/8085 Internal Registers
Chapter 1. Assembly Language and Processors
Work Registers
The 8080 provides an 8-bit accumulator and six other general purpose work registers, as shown in Figure 1-3.
Programs reference these registers by the letters A (for the accumulator), B, C, D, E, H, and L. Thus, the
Instruction ADD B may be interpreted as 'add the contents of the B register to the contents of the accumu-
lator.
Some instructions reference a pair of registers as shown in the following:
Symbolic Reference
B
D
H
M
PSW
Registers Referenced
Band C
D and E
Hand L
Hand L (as a memory reference)
A and condition flags (explained
later In this section)
The symbolic reference for a single register IS often the same as for a register pair. The Instruction to be executed
determines how the processor interprets the reference. For example, ADD B is an 8-blt operation. By contrast
PUSH B (which pushes the contents of the Band C registers onto the stack) is a 16-blt operation.
Notice that the letters Hand M both refer to the Hand L register pair. The choice of which to use depends on
the instruction. Use H when an instruction acts upon the Hand L register pair as In INX H (increment the
contents of Hand L by one). Use M when an instruction addresses memory via the Hand L registers as in ADD
M (add the contents of the memory location specified by the Hand L registers to the contents of the accumu-
lator).
The general purpose registers B, C, D, E, H. and L can proVide a wide variety of functions such as storing 8-bit
data values, storing intermediate results In arithmetic operations, and storing 16-bit address pointers. Because of
the 8080's extensive instruction set, it is usually possible to achieve a common result with any of several
different instructions. A Simple add to the accumulator. for example, can be accomplished by more than half a
dozen different Instructions. When possible, it is generally desirable to select a register-to-register instruction
such as ADD B. These instructions tYPically I'equire only one byte of program storage. Also, using data already
present in a register eliminates a memory access and thus reduces the time required for the operation.
The accumulator also acts as a general-purpose register, but It has some special capabilities not shared with the
other registers. For example, the Input/output instructions IN and OUT transfer data only between the accumu-
lator and external I/O deVices. Also, many operations involving the accumulator affect the condition flags as ex-
plained In the next section.
Example:
The following figures illustrate the execution of a move instruction. The MOV M.e moves a copy of the contents
of register C to the memory location specified by the Hand L registers. Notice that tillS location must be in
RAM since data is to be written to memory,
1-7
Chapter 1. Assembly Lanl uage and Processors
I
8080
IACCUMULATORI FLAGS
8085
+
HIGH LOW
I I I I ! I
B e STACK POINTER
I N S T R U ( ~
DECOUER
I
D
I
E
I I
PROGRAM
i
COUNTER
Y DATA BUS LATCH
I I
H
I
L
I I
ADDRESS
I
BUS LATCH
f
L
l

ROM RAM
Figure 1-4. Instruction Fetch
The processor initiates the instruction fetch by latching the contents of the program counter on the address bus,
and then incrEments the program counter by one to Indicate the address of the next Instruction byte. When the
memory respc nds, the Instruction is decoded into the series of actions shown in Figure 1-5.
NOTE
The following description of the execution of the
MOV M,e instruction is conceptually correct, but
does not account for normal bus control. For details
concerning memory interface, refer to the User's
Manual for your processor.
1-8
Chapter 1. Assembly Language and Processors
8080
8085
IACCUMULATORI FLAGS
I
I
B
I
C
I
HIGH LOW
INSTRUCTION
I
STACK
!
POINTER
I
DECODER
I
I I
I ! I
D E PROGRAM COUNTER
DATA BUS LATCH f.-
I
H
I
L ADDRESS
I
BUS LATCH I
+
+ +
ROM RAM
Figure 1-5. Execution of MOY M.C Instruction
To execute the MOY M.C instruction. the processor latches the contents of the C register on the data bus and
the contents of the Hand L registers on the address bus. When the memory accepts the data, the processor
terminates execution of this instruction and initiates the next instruction fetch.
Internal Work Registers
Certain operations are destructive. For example, a compare is actually a subtract operation; a zero result indicates
that the opreands are equal. Since it is unacceptable to destroy either of the operands, the processor includes
several work registers reserved for its own use. The programmer cannot access these registers. These registers are
used for internal data transfers and for preserving operands in destructive operations.
Condition Flags
The 8080 provides five flip flops used as condition flags. Certain arithmetic and logical instructions alter one or
more of these flags to indicate the result of an operation. Your program can test the setting of four of these
flags (carry, sign. zero. and parity) using one of the conditional iump. call. or return Instructions. This allows you
to alter the flow of program execution based on the outcome of a previous operation. The fifth flag. auxiliary
carry. is reserved for the use of the DAA instruction. as will be explained later in this section.
It is important for the programmer to know which flags are set by a particular instruction. Assume, for example.
that your program is to test the parity of an input byte and then execute one instruction sequence if parity is
even. a different instruction set if parity is odd. Coding a JPE (jump if parity is even) or JPO (jump if parity is
1-9
Chapter 1. Assembly Lanfuage and Processors
odd) instructl,m Immediately foiiowing the IN (input) Instruction produces false results since the IN instruction
does not affect the condition flags. The jump executed by your program reflects the outcome of some previous
operation unrdated to the IN instruction. For the operation to work correctly, you must include some instruc-
tion that alter; the parity flag after the IN instruction, but before the lump Instruction. For example, you can
add zero to tl e accumulator. ThiS sets the parity flag without altering the data In the accumulator.
In other cases you wiii want to set a flag With one instruction, but then have a number of intervel1lng instruc-
tions before yJU use It. In these cases, you must be certain that the Intervening instructions do not affect the
desired flag.
The flags set I,y each Instruction are detailed in the IndiVidual Instruction descriptions In Chapter 3 of this
manual.
NOTE
When a flag is 'set' It IS set ON (has the value one);
when a flag IS 'reset' it IS reset OFF (has the value
zero).
Carry Flag
As ItS name it Wlies, the carry flag IS commonly used to Indicate whether an addition causes a 'carry' into the
next higher 01 del' digit. The carry flag IS also used as a 'borrow' flag In subtractions, as explallled under 'Two's
Complement of Data' In Chapter 2 of thiS manual. The carry flag is also affected by the logical
AND, OR, ani exclUSive OR Instructions. These instructions set ON or OFF particular bits of the accumulator.
See the descrJJtlons of the ANA, ANI, ORA, ORI, XRA, and XRI instructions in Chapter 3.
The rotate In'truCtions, which move the contents of the accumulator one position to the left or right, treat the
carry bit as trough it were a III nth bit of the accumulatol' See the deSCrIptions of the RAL, RAR, RLC, and RRC
instructions II' Chapter 3 of thiS manual.
Example:
Addition of ['vo one-byte numbers can produce a carry out of the high-order bit:
Bit Number:
AE=
+74=
7654 3210
1010 1110
0111 01 00
0010 001 0 = 22 carry flag = 1
An addition t lat causes a carry out of the high order bit sets the carry flag to 1, an addition that does not cause
a carry resets the flag to zero.
Sign Flag
As explained mder 'Two's Complement Representation of Data' In Chapter 2, bit 7 of a result in the accumulator
can be Interpletcd as a sign. Instructlolls that affect the sign flag set the flag equal to bit 7. A zero In bit 7
1·10
Chapter 1. Assembly Language and Processors
indicates a positive value; a one indicates a negative value. This value is duplicated in the sign flag so that
conditional iump, call, and return instructions can test for positive and negative values.
Zero Flag
Certain Instructions set the zero flag to one to indicate that the result in the accumulator contains all zeros.
These instructions reset the flag to zero if the result in the accumulator is other than zero. A result that has a
carry and a zero result also sets the zero bit as shown below:
1010 0111
+0101 1001
0000 0000 Carry Flag = 1
Zero Flag = 1
Parity Flag
Parity IS determined by counting the number of one bits set in the result in the accumulator. Instructions that
affect the parity flag set the flag to one for even parity and reset the flag to zero to indicate odd parity.
Auxiliary Carry Flag
The auxiliary carry flag indicates a carry out of bit 3 of the accumulator. You cannot test this flag directly in
your program; it is present to enable the DAA (Decimal Adiust Accumulator) to perform its function.
The auxiliary carry flag and the DAA instruction allow you to treat the value in the accumulator as two 4-bit
binary coded decimal numbers. Thus, the value 0001 1001 is equivalent to 19. (If this value is interpreted as a
binary number, it has the value 25.) Notice, however, that adding one to this value produces a non-decimal
result:
0001 1001
+00000001
0001 1010 = lA
The DAA instruction converts hexadecimal values such as the A in the preceding example back into binary coded
decimal (BCD) format. The DAA instruction requires the auxiliary carry flag since the BCD format makes it
possible for arithmetic operations to generate a carry from the low-order 4-bit digit Into the high-order 4-bit
digit. The DAA performs the following addition to correct the preceding example:
0001 1010
+00000110
0001 0000
+0001 0000 (auxiliary carry)
0010 0000 = 20
1-11
Chapter 1. AssemblY Lan5uage and Processors
The auxiliary carry flag is affected by all add, subtract, increment, decrement, compare, and all logical AND,
OR, and excl Jsive OR instructions. (See the descriptions of these Instructions In Chapter 3.) There is some
difference in the handling of the auxiliary carry flag by the logical AND instructions In the 8080 processor and
the 8085 pro ;essor. The 8085 logical AND instructions always set the auxiliary flag ON. The 8080 logical AND
instructions s,t the flag to reflect the logical OR of bit 3 of the values involved in the AND operation.
Stack and Stack Po inter
To understan j the purpose and effectiveness of the stack, it is useful to understand the concept of a subroutine.
Assume that !our program requires a multiplication routine. (Sinoe the 8080 has no multiply instruotions, this
oan be performed through repetitive addition. For example, 3x4 is equivalent to 3+3+3+3.) Assume further that
your progralT needs this multiply routine several times. You can recode this routine inline each time it is needed,
but this can lise a great deal of memory. Or, you can code a subroutine:
nline Coding Subroutine
1 1
nline routine CALL
I I
nline routine CALL ..
subroutine
I I
nline routine CALL
I I
The 8080 provides instruotions that call and return from a subroutine. When the call instruction is executed, the
address of th, next instruction (the contents of the program counter) IS pushed onto the stack. The contents of
the program :ounter are replaced by the address of the desired subroutine. At the end of the subroutine, a
return instruction pops that previously-stored address off the stack and puts it back into the program counter.
Program exe( ution then continues as though the subroutine had been coded inline.
The mechani;m that makes this possible IS, of course, the staok. The stack is simply an area of random access
memory addi essed by the stack pointer. The stack pointer IS a hardware register maintained by the processor.
However, YOiJr program must initialize the stack pointer. This means that your program must load the base
address of the stack into the stack pointer. The base address of the stack is commonly assigned to the highest
available add'ess in RAM. This is because the stack expands by decrementing the stack pointer. As items are
1-12
Chapter 1. Assembly Language and Processors
added to the stack. it expands into memory locations with lower addresses. As Items are removed from the
stack. the stack pointer is incremented back toward Its base address. Nonetheless. the most recent item on the
stack is known as the 'top of the stack.' Stack is still a most descriptive term because you can always put
something else on top of the stack. In terms of programming, a subroutine can call a subroutine, and so on.
The only limitation to the number of items that can be added to the stack is the amount of RAM available for
the stack.
The amount of RAM allocated to the stack is important to the programmer. As you write your program. you
must be certain that the stack will not expand into areas reserved for other data. For most applications. this
means that you must assign data that requires RAM to the lowest RAM addresses available. To be more precise.
you must count up all instructions that add data to the stack. Ultimately, your program should remove from
the stack any data it places on the stack. Therefore. for any IIlstruction that adds to the stack. you can sub-
tract any intervening instruction that removes an Item from the stack. The most critical factor is the maximum
size of the stack. Notice that you must be sure to remove data your program adds to the stack. Otherwise, any
left-over items on the stack may cause the stack to grow into portions of RAM you intend for other data.
Stack Operations
Stack operations transfer sixteen bits of data between memory and a pair of processor registers. The two basIc
operations are PUSH. which adds data to the stack. and POP, which removes data from the stack.
A call Instruction pushes the contents of the program counter (which contains the address of the next instruction)
onto the stack and then transfers control to the desired subroutine by placing its address in the program counter.
A return instruction pops sixteen bits off the stack and places them in the program counter. This requires the
programmer to keep track of what is in the stack. For example. if you call a subroutine and the subroutine
pushes data onto the stack, the subroutine must remove that data before executing a return instruction. Other-
wise, the return IIlstructlon pops data from the stack and places It in the program counter. The results are
unpredictable, of course. but probably not what you want.
Savll7g Program Status
It is likely that a subroutine requires the use of one or more of the working registers. However, it IS equally
likely that the main program has data stored in the registers that it needs when control returns to the main
program. As general rule, a subroutine should save the contents of a register before using it and then restore
the contents of that register before returning control to the main program. The subroutine can do this by
pushing the contents of the registers onto the stack and then popping the data back into the registers before
executing a return. The following instruction sequence saves and restores all the working registers. Notice that
the POP instructions must be in the opposite order of the PUSH instructions if the data is to be restored to its
original location.
1-13
Chapter 1. Assembly langJage and Processors
SUBRTN: PUSH
PUSH
PUSH
PUSH
PSW
B
o
H
subroutine coding
POP H
POP 0
POP B
POP PSW
RETURN
The letters B, 0, and H refer to the Band C, 0 and E, and Hand L register pairs, respectively, PSW refers to
the program s atus word. The program status wOl'd IS a 16-blt word comprising the contents of the accumulator
and the five c,jnpitlon flags. (PUSH PSW adds three bits of filler to expand the condition flags into a full
byte; POP PSII strrps out these filler bits.)
Input/Output Ports
The 256 rnpul/output ports provide communication with the outside world of perrpheral devices. The IN and
OUT instructl<lns initiate data transfers.
The IN rnstrw tion latches the number of the desired port onto the address bus. As 500n as a byte of data 15
returned to the data bus latch, it is transferred into the accumulator.
The OUT inst: uetion latches the number of the desired port onto the address bus and latches the data in the
accumulator onto the data bus.
The specified )ort number 15 duplicated on the address bus. Thus, the instruction IN 5 latches the bit configura-
tion 0000 01 (1 0000 0101 onto the address bus.
Notice that the IN and OUT instructions Simply Initiate a data transfer It is the responsibility of the peripheral
device to d e t e ~ t that It has been addressed. Notice also that it is possible to dedicate any number of ports to
the same perr, heraI device. You might use a number of ports as control signals, for example.
Because input and output are almost totally application dependent, a discussion of design techniques IS beyond
the scope of t liS manual.
For additional hardware Information. refer to the 8080 or 8085 Microcomputer Systems User's Manual.
For related prJgrammlng rnformation, see the descriptions of the IN, OUT, 01, EI, RST, and RIM and SIM
Instructions In Chapter 3 of this manual. (The RIM and SIM instructions apply only to the 8085.)
1-14
Chapter 1. Assembly Language and Processors
Instruction Set
The 8080 incorporates a powerful array of Instructions. This section provides a general overview of the Instruc-
tion set. The detailed operation of each instruction is described In Chapter 3 of tillS manual.
Addressing Modes
Instructions can be categorized according to their method of addressing the hardware registers and/or memory.
Implied AddresslI1g. The addressing mode of certain Instructions is implied by the instruction's function. For
example, the STC (set carry flag) instruction deals only with the carry flag; the DAA (decimal adjust accumu-
lator) instruction deals with the accumulator.
Register AddresslI1g. QUite a large set of instructions call for register addressing. With these instructions, you
must specify one of the registers A through E, H or L as well as the operation code. With these instructions,
the accumulator IS implied as a second operand. For example, the instruction CMP E may be Interpreted as
'compare the contents of the E register with the contents of the accumulator.'
Most of the Instructions that use register addressing deal with 8-bit values. However, a few of these Instructions
deal with 16-bit register pairs. For example, the PCHL Instruction exchanges the contents of the program counter
with the contents of the Hand L registers.
Immediate AddresslI1g. Instructions that use Immediate addressing have data assembled as a part of the instruction
Itself. For example, the Instruction CPI 'C' may be Interpreted as 'compare the contents of the accumulator with
the letter c.' When assembled, this instruction has the hexadecimal value FE43. Hexadecimal 43 IS the Internal
representation for the letter C. When this instruction IS executed, the processor fetches the first instruction byte
and determines that it must fetch one more byte. The processor fetches the next byte Into one of its internal
registers and then performs the compare operation.
Notice that the names of the Immediate instructions indicate that they use immediate data. Thus, the name of an
add instruction is ADD; the name of an add Immediate Instruction is AD!.
All but two of the Immediate instructions use the accumulator as an Implied operand, as in the CPI instruction
shown previously The MV! (move Immediate) Instruction can move its immediate data to any of the working
registers, including the accumulator, or to memory. Thus, the Instruction MVI D,OFFH moves the hexadecimal
value FF to the D register.
The LXI Instruction (load register pair immediate) is even more unusual in that ItS Immediate data IS a 16-bit
value. This instruction is commonly used to load addresses Into a register pair. As mentioned previously, YOUl'
program must initialize the stack pointer; LXI IS the instruction most commonly used for this purpose. For ex-
ample, the instruction LXI SP,30FFH loads the stack pointer with the hexadecimal value 30FF
Direct AddresslI1g. Jump Instructions include al6-bit address as part of the instruction. For example, the
Instruction JMP 1000H causes a jump to the hexadecimal address 1000 by replacing the current contents of the
program counter with the new value 1000.
1-15
Chapter 1. Assemblv Lang Jage and Processors
Instructions that include a direct address require three bytes of storage: one for the Instruction code. and two
for the 16-bit lddress.
Register IndirEct Addressing. Register indirect instructions reference memory via a register pair. Thus, the
Instruction MC>V M,C moves the contents of the C register into the memory address stored in the Hand L
register pair. 1 he instruction LDAX B loads the accumulator with the byte of data specified by the address
In the Band C register pair.
Combmed Ad,lressmg Modes. Some instructions use a combination of addressing modes. A CALL instruction,
for example, combines direct addressing and register Indirect addressing. The direct address in a CALL instruction
specifies the address of the deSIred subroutine; the register indirect address IS the stack pointer. The CALL
instruction pu,hes the current contents of the program counter into the memory location specified by the stack
pointer
Timmg E f f e c t ~ of Addressmg Modes. Addressing modes affect both the amount of time required for executing
an Instruction and the amount of memory reqUired for ItS storage. For example, instructions that use implied or
register addres;ing execute very qUickly since they deal directly with the processor hardware or with data already
present in hardware I·egisters. More important, however, is that the entire instruction can be fetched with a
single memory access. The number of memory accesses required is the single greatest factor in determining
execution timing. More memory accesses require more execution time. A CALL instruction, for example, requires
five memory accesses: three to access the entire Instruction, and two more to push the contents of the program
counter onto ',he stack.
The processor can access memory once during each processor cycle. Each cycle comprises a variable number of
states. (The Injividual instruction descriptions in Chapter 3 specify the number of cycles and states required for
each Instructic n.) The length of a state depends on the clock frequency specified for your system, and may
range from 48) nanoseconds to 2 microseconds. Thus, the timing of a four state instruction may range from
1.920 microse:onds through 8 microseconds. (The 8085 has a maximum clock frequency of 320 nanoseconds
and therefore :an execute instructions about 50% faster than the 8080.)
Instruction Nam/ilg Conventions
The mnemonl<s assigned to the instructions are designed to indicate the function of the instruction. The Instruc·
tions fall into the following functional categories:
Data Tral1Sfer Group. The data transfer instructions move data between registers or between memory and
registers.
MOV
MVI
LDA
STA
LHLD
SHLD
Move
Move Immediate
Load Accumulator Directly from Memory
Store Accumulator Directly in Memory
Load Hand L Registers Directly from Memory
Store Hand L Registers Directly in Memory
ALL MNEMONICS © 7974. 7975. 7976, 7977 INTEL CORPORA nON
1-16
Chapter 1. Assembly Language and Processors
An 'X' In the name of a data transfer instruction implies that it deals with a register pair:
LXI
LDAX
STAX
XCHG
XTHL
Load Register Pair with Immediate data
Load Accumulator from Address in Register Pair
Store Accumulator in Address in Register Pair
Exchange Hand L with D and E
Exchange Top of Stack with Hand L
Arithmetic Group. The arithmetic instructions add, subtract, increment, or decrement data in registers or
memory.
ADD
ADI
ADC
ACI
SUB
SUI
SBB
SBI
INR
DCR
INX
DCX
DAD
Add to Accumulator
Add Immediate Data to Accumulator
Add to Accumulator Using Carry Flag
Add Immediate Data to Accumulator Using Carry Flag
Subtract from Accumulator
Subtract Immediate Data from Accumulator
Subtract from Accumulator Using Borrow (Carry) Flag
Subtract Immediate from Accumulator Using Borrow
Increment Specified Byte by One
Decrement Specified Byte by One
Increment Register Pair by One
Decrement Register Pair by One
Double Register Add: Add Contents of Register
Pair to Hand L Register Pair
Logical Group. This group performs logical (Boolean) operations on data in registers and memory and on
condition flags.
The logical, AND, OR, and Exclusive OR instructions enable you to set specific bits in the accumulator ON or
OFF.
ANA
ANI
ORA
ORI
XRA
XRI
Logical AND with Accumulator
Logical AND with Accumulator Using Immediate Data
Logical OR with Accumulator
Logical OR with Accumulator Using Immediate Data
Exclusive Logical OR with Accumulator
Exclusive OR Using Immediate Data
The compare instructions compare the contents of an 8·blt value with the contents of the accumulator:
CMP
CPI
Compare
Compare Using Immediate Data
ALL MNEMONICS © 7974, 7975, 7976, 7977 INTEL CORPORA nON
'-17
Chapter 1. Assembly Lang1lage and Processors
The rotate instructions shift the contents of the accumulator one bit position to the left or right:
RLC
RRC
RAL
RAR
Rotate Accumulator Left
Rotate Accumulator Right
Rotate Left Through Carry
Rotate Right Through Carry
Complement ald carry flag instructions:
CMA
CMC
STC
Complement Accumulator
Complement Carry Flag
Set Carry Flag
Branch Group. The branching instructions alter normal sequential program flow. either unconditionally or
conditionallY. fhe unconditional branching instructions are as follows:
jMP
CALL
RET
Jump
Call
Return
Conditional bnnching Instructions examine the status of one of four condition flags to determine whether the
specified brant h IS to be executed. The conditions that may be specified are as follows:
NZ
Z
NC
C
PO
PE
P
M
Not Zero (Z = 0)
Zero (Z = 1)
No Carry (C = 0)
Carry (C = 1)
Parity Odd (P =0)
Parity Even (P = 1)
Plus (5 = 0)
Minus (5 1)
Thus. the conditional branching Instructions are specified as follows:
Jumps
jC
jNC
jZ
jNZ
jP
jM
jPE
jPO
Calls
CC
CNC
CZ
CNZ
CP
CM
CPE
CPO
Returns
RC
RNC
RZ
RNZ
RP
RM
RPE
RPO
(Carry)
(No Carry)
(Zero)
(Not Zero)
(Plus)
(Minus)
(Parity Even)
(Parity Odd)
Two other instructions can effect a branch by replacing the contents of the program counter:
PCHL Move Hand L to Program Counter
RST Special Restart Instruction Used with Interrupts
ALL MNEMONICS © 1974, 7975. 7976, 1977 INTEL CORPORA TlON
1-18
Chapter 1. Assembly Language and Processors
Stack, //0, and Machine Contra/Instructions. The following instructions affect the stack and/or stack pOinter'
PUSH
POP
XTHL
SPHL
Push Two Bytes of Data onto the Stack
Pop Two Bytes of Data off the Stack
Exchange Top of Stack with Hand L
Move contents of Hand L to Stack Pointer
The I/O instructions are as follows:
IN
OUT
Initiate Input Operation
Initiate Output Operation
The machine control Instructions are as follows:
EI
DI
HLT
NOP
Enable Interrupt System
Disable Interrupt System
Halt
No Opel'ation
HARDWARE/INSTRUCTION SUMMARY
The following illustrations graphically summarize the instruction set by showing the hardware acted upon by
specific instructions, The type of operand allowed for each Instruction IS Indicated through the use of a code,
When no code is given. the Instruction does not allow operands.
Code
REGM
S
Accumulator Instructions
Meaning
The opel'and may specify one of the S-bit registers A,B.C,D,E,H, or L or M
(a memory reference via the 16-blt address in the Hand L registers). The
MOV Instruction. which calls for two operands, can specify M for only one
of its operands.
Designates S-bit immediate operand.
Designates a 16-bit address.
Designates an S-bit port number
Designates a 16-blt register pair (B&C,D&E,H&L, or SP).
Designates a 16-blt immediate operand,
The following illustration shows the Instructions that can affect the accumulator, The instructions listed above
the accumulator all act on the data in the accumulator, and all except CMA (complement accumulator) affect
one or more of the condition flags. The instructions listed below the accumulator move data Into or out of the
accumulator, but do not affect condition flags. The STC (set carry) and CMC (complement carry) instructions
are also shown hel'e,
ALL MNEMONICS © 7974, 7975, 7976, 7977 INTEL CORPORA TlON
1-19
Chapter 1. Assembly Lan ,uage and Processors
ADI
ACI
SUI
SBI
ANI
D
S
XRI
ORI
CPI
RRC
DAA
REGM
S
FLAGS
I
STC CMC
HIGH LOW
C
I
STACK POINTER
E
J
IPROGRAM COUNTER I
L
I
MEMORY
ADD
ADC
SUB
SBB
ANA REGM
S
XRA
ORA
CMP
RLC RAL
RAR CMA
INR}
DCR
,-1ACCUMULATORI
I I B I__---l
MOV REGM
S
: REC Msi D I
J ~ HI
LDAX}
STAX EC,DE
LDA I
STA} 1'16
MVI
MOV
[J STACK
S
F.EGMS,REG
S
ALL MNEMONICS © 7974, 7975, 7976, 7977 INTEL CORPORA TlON
1·20
Chapter 1. Assembly Language and Processors
Register Pair (Word) Instructions
The following instructions all deal with 16-bit words. Except for DAD (which adds thecontents of the B&C or
D&E register pair to H&L), none of these instructions affect the condition flags. DAD affects only the carry
flag.
IACCUMULATORI FLAGS
INX}
HIGH LOW
B C DCX REG
16 fSPH' -I STACK !
POINTER
DAD
.- D E
I"""xcHG
PCHL _I PROGRAM! COUNTER I
H L
..",..-
XTHL
LHLD
SHLD
I
MEMORY
STACK
PUSH }
POP B,D,H,PSW
ALL MNEMONICS © 7974, 7975, 7976, 7977 INTEL CORPORA TlON
1-21
Chapter 1. Assembly Lalguage and Processors
Branching Instructions
The Instructions can alter the contents of the program counter, thereby altering the normal sequential
execution flew. Jump instructions affect only the program counter. Call and Return Instructions affect the
program coullter, stack pointer, and stacK.
FLAGS
I
HIGH LOW

C
I
POINTER

E
I I PCHL
COUNTER RST

L

JMP CALL RET
JC JNC1 CC CNC} RC RNcl
JZ JNZ (> A CZ CNZ A RZ RNZ A
IP 1M I 16 CP CM 16 RP RM J> 16
JPE JPO J CPE CPO RPE RPO
MEMORY
STACK
CONTROL INSTRUCTIONS
RST
Nap
HLT
EI
01
SIM}
8085 only
RIM
ALL 7974,7975,7976,7977 INTEL CORPORATION
1-22
Chapter 1. Assembly language and Processors
Instruction Set Guide
The following is a summary of the instruction set:
ADDl
ADI
ADC ACI
SUB SUI
SBB
REGM
S
SBI
D
S
ANA ANI
XRA XRI
ORA ORI
CMP CPI
RLC RAL RRC
RAR CMA DAA
INR}
DCR REGM
S
RST
LOW
, POINT;ER
HIGH
STACK
ISTC CMC
INX}
IDCX REG
16
~
XCHG
L
E
H
"ACCUMULATORI FLAGS
MOY REGMS,REGM
S
! B I C
1 I D I
LXI REG
16
,D
16
jC
jZ
jP
jPE
jMP
jNC1
jNZ A
jM J 16
jPO
CALL
CC CNCl
CZ CNZ A
CP CM J 16
CPE CPO
RET
RC RNCi
RZ RNZ ~ A
RP RM J 16
RPE RPO
--STAC"K--- ~ - : ~ ~ H } B,D,H,PSW
MEANING
SOS5 ONLY
CONTROL
INSTRUCTIONS
RST
NOP
HLT
EI
DI
SIMI
RIM]
OUT P
s
OUTPUT
PORTS
INPUT
PORTS
LHLD}
STHD A
16
MEMORY
CODE
MYI D
S
MOY REGMS,REGM
S
~
LDAX\ BC DE
STAX) ,
REGM
S
The operand may specify one of the S-bit registers A,B,C,D,E,H, or l or M (a memory
reference via the 16-bit address in the Hand L registers). The MOY instruction, which
calls for two operands, can specify Mfor only one of its operands.
Designates S-bit immediate operand.
Designates a 16-bit address.
Designates an S-bit port number.
Designates a '16-bit register pair (B&C,D&E,H&L,or SP).
Designates a 16 -bit immediate operand.
ALL MNEMONICS © 7974, 7975, 7976, 7977 INTEL CORPORA nON
1-23
Chapter 1. Assemblv Lalguage and Processors
8085 PROCESSOR DIFFERENCES
The differences between the 8080 processor and the 8085 processor will be more obvious to the system designer
than to the programmer. Except for two additional instructions. the 8085 set is identical to and fully
compatible with the 8080 instruction set. Most programs written for the 8680 should operate on the 8085 with-
out modifica1ion. The only programs that may require changes are those with critical timing routines; the higher
system speed of the 8085 may alter the time values of such routines.
A partial listing of 8085 design features Includes the following:
• A single 5 volt power supply.
• Execution speeds approximately 50% faster than the 8080.
• Incorporation in the processor of the features of the 8224 Clock Generator and Driver and the
8228 System Controller and Bus Driver.
• A non-maskable TRAP interrupt for handling serious problems such as power failures.
• Three separately maskable interrupts that generate internal RST instructions.
• Input/output lines for serial data transfer
Programming for tile 8085
For the prog ·ammer. the new features of the 8085 are summarized In the two new Instructions SIM and RIM.
These instructions differ from the 8080 instructions in that each has multiple functions. The SIM instruction
sets the interrupt mask and/or writes out a bit of serial data. The programmer must place the deSIred interrupt
mask and/or serial output In the accumulator prior to execution of the SIM instruction. The RIM Instruction
reads a bit 0 serial data if one is present and the Interrupt mask Into the accumulator. Details of these instruc-
tions are cov"red in Chapter 3.
Despite the Ilew Interrupt features of the 8085. programming for interrupts is little changed. Notice, however, that
8085 hardware interrupt RESTART addresses fall between the eXisting 8080 RESTART addresses. Therefore.
only four bytes are available for certain RST instructions. Also, the TRAP interrupt Input is non-maskable and
cannot be di ;abled. If your application uses this input, be certain to provide an interrupt routine for it.
The interrup:s have the following priority:
TRAP
RSn.5
RST6.5
RST5.5
INTR
highest
lowest
When more han one interrupt is pending, the processor always recognizes the higher priority Interrupt first.
These priorii ies apply only to the sequence in which interrupts are recognized. Program routines that service
interrupts h,ve no special priority. Thus. an RST5.5 interrupt can Interrupt the service routine for an RST7.5
interrupt. If you want to protect a service routine from interruption, either disable the interrupt system (01
instruction), or mask out other potential interrupts (SIM instruction).
1-24
Chapter 1. Assembly Language and Processors
Conditional Instructions
Execution of conditional instructions on the 8085 differs from the 8080. The 8080 fetches all three instruction
bytes whether or not the condition is satisfied. The 8085 evaluates the condition while it fetches the second
instruction byte. If the specified condition is not satisfied, the 8085 skips over the third instruction byte and
immediately fetches the next Instruction. Skipping the unnecessary byte allows for faster execution.
1-25
2. ASSEMBLY LANGUAGE CONCEPTS
INTRODUCTION
Just as the English languagc has its [-ulcs of grammar, assembly language has certalll coding rules. The source line
[5 the assembly language equivalent of a sentencc.
Th[s assembler recognizcs three types of source lines: IIlstruct[ons, directives, and controls. This manual describes
instructions and dircctlves. Controls are dcscribed [n the operator's manual for your version of the assembler.
Th[s chapter dcscribes thc general rules for coding sourcc lincs. Specific instructions (see Chapter 3) and
directives (see Chapters 4 and 5) may have specific coding rules. Even 50, the coding of such Instructions and
directives must conform to thc gencral rules in this chapter.
SOURCE LINE FORMAT
Assembly language [nstructlons and asscmblcr directives may consist of up to four fields, as follows:
{
Label:)
Name
Opcodc Operand ;Comment
Thc fields may be separated by any numbe[- of blanks, but must be separated by at least one delimlter_ Each
IIlstruction and directive must be entered on a single line termlila ted by a carriage return and a line fced. No
continuation lines are possiblc, but you may havc lines conSisting enti[-ely of commcnts.
Character Set
The following characters are Icgal In asscmbly languagc source statements:
• Thc lctters of the alphabet, A through Z. Both upper- and lower-case letters are allowed. Internally,
the assemblc[- trcats all letters as though they wcre upper-casc, but the characters are printed exactly
as they were Input in the assembly listing.
• The digits 0 through 9.
• The following speCial characters:
2-1
Chapter 2. Assembly Lan luage Concepts
Character
+
*
&
$
@
<
>
%
blank
CR
FF
HT
Meaning
Plus sign
Minus sign
Asterisk
Slash
Comma
Left parenthesis
Right parenthesis
Single quote
Ampersand
Colon
Dollar sign
Commercial 'at' sign
Question mark
Equal sign
Less than sign
Greater than sign
Percent sign
Exclamation point
Blank or space
Semicolon
Period
Carnage return
Form feed
Horizontal tab
.. In addition, any ASCII character may appear in a string enclosed In single quotes or in a comment.
Delimiters
Certain chara<:ters have special meaning to the assembler in that they function as delimiters. Delimiters define
the end of a ,ource statement, a field, or a component of a field. The following list defines the delimiters
recognized by the assembler, Notice that many delimiters are related to the macro feature explained In Chapter
5. Delimiters Jsed for macros are shown here so that you will not accidentally use a delimiter improperly
Refer to Chal,ter 5 for a description of macros.
2-2
Label/Name Field
Charaeter(s)
blank
(..• J
CR
HT
&
<... >
%
Meaning
one or more
blanks
comma
pair of single
quote characters
pair of paren-
theses
carriage return
horizontal tab
semicolon
colon
ampersand
pair of angle
brackets
percent sign
exclamation
point
double semi-
colon
Chapter 2. Assembly Language Concepts
Use
field separator or symbol terminator
separate operands in the operands field,
including macro parameters
delimit a character string
delimit an expression
statement terminator
field separator or symbol terminator
comment field delimiter
delimiter for symbols used as labels
delimit macro prototype text or formal
parameters for concatenation
delimit macro parameter text which
contains commas or embedded blanks;
also used to delimit a parameter list
delimit a macro parameter that is to be
evaluated prior to substitution
an escape character used to pass the
following character as part of a macro
parameter when the character might
otherwise be interpreted as a delimiter
delimiter for comments in macro definitions
when the comment is to be suppressed when
the macro is expanded
Labels are always optional. An instruction label is a symbol name whose value is the location where the instruc-
tion is assembled. A label may contain from one to SIX alphanumeric characters, but the first character must be
alphabetic or the special characters '7' or '@' The label name must be terminated with a colon. A symbol used
as a label can be defined only once in your program. (See 'Symbols and Symbol Tables' later in this chapter.)
2-3
Chapter 2. Assemblv Lallguage Concepts
Alphanumerit: characters include the letters of the alphabet, the question mark character, and the decimal
digits 0 throl gh 9.
A name is required for the SET. EQU, and MACRO directives. Names follow the same coding rules as labels,
except that t ley must be terminated with a blank rather than a colon. The label/name field must be empty for
the LOCAL ind ENDM directives.
Opcode Field
This required field contains the mnemonic operation code for the 8080/8085 instruction or assembler directive
to be perforned.
Operand Field
The operand field identifies the data to be operated on by the specified opcode. Some instructions require no
operands. Otners require one or two operands. As a general rule, when two operands are required (as in data
transfer and lrithmetic operations), the first operand identifies the destination (or target) of the operation's
result, and tlie second operand specifies the source data.
Examples:
MOil
MV
Comment Field
A,C
A:B'
;MOVE CONTENTS OF REG C TO ACCUMULATOR
;MOVE B TO ACCUMULATOR
The optiona comment field may contain any information you deem useful for annotating your program. The
only coding requirement for this field is that it be preceded by a semicolon. Because the semicolon is a delimiter,
there IS no reed to separate the comment from the previous field with one or more spaces. However, spaces are
commonly Lsed to improve the readability of the comment. Although comments are always optional, you should
use them lib;rally since it is easier to debug and maintain a well documented program.
CODING O P E R A I ~ D FIELD INFORMATION
There are feur types of information (a through d in the following list) that may be requested as items in the
operand field; the information may be specified in nine ways, each of which is described below.
2-4
Chapter 2. Assembly language Concepts
OPERAND FIELD INFORMATION
Information reqUIred
(a) Register
(b) Register Pair
(c) Immediate Data
(d) 16-bit Address
Ways of specitying
(1) Hexadecimal Data
(2) Decimal Data
(3) Octal Data
(4) Binary Data
(5) Location Counter ($)
(6) ASCII Constant
(7) Labels assigned values
(8) Labels of instructions or data
(9) Expressions
Hexadecimal Data. Each hexadecimal number must begin with a numeric digit (0 through 9) and must be
followed by the letter H.
Label
HERE:
Opcode
MVI
Operand
C,OBAH
Comment
;LOAD REG C WITH HEX BA
DecImal Data. Each decimal number may be identified by the letter D immediately after its last digit or may
stand alone. Any number not specifically identified as hexadecimal, octal, or binary is assumed to be decimal.
Thus. the following statements are equivalent:
Label
ABC:
Opcode
MVI
MVI
Operand
E,15
E,15D
Comment
;LOAD E WITH 15 DECIMAL
Octal Data. Each octal number must be followed by the letter 0 or the letter Q.
Label
LABEL:
Opcode
MVI
Operand
A,nQ
Comment
;LOAD OCTAL 72 INTO ACCUM
Binary Data. Each binary number must be followed by the letter B.
Label
NOW:
Opcode
MVI
Operand
D,l1l1 011 OB
Comment
;LOAD REGISTER D
;WITH OF6H
2-5
Chapter 2. Assemblv L, nguage Concepts
Location Counter, The $ character refers to the current location counter. The location counter contains the
address w h e r ~ the current instruction or data statement will be assembled.
label
co:
Opcode
jMP
Operand
$+6
Comment
;j UMP TO ADDRESS 6 BYTES BEYOND
;THE FIRST BYTE OF THIS
;INSTRUCTION
ASCII Const1t7t. One or more ASCII characters enclosed in single quotes define an ASCII constant. Two
successive sillgle quotes must be used to represent one slllgie quote Within an ASCII constant.
i.abel Opcode Operand Comment
DATE:
MYI
DB
E '*' ;LOAD E REG WITH 8-BIT ASCII
;REPRESENTATION OF *
TODAY"S DATE'
Labels Assig led Values. The SET and EQU directives can assign values to labels. In the following example,
assume that VALUE has been assigned the value 9FH; the two statements are equivalent:
\1.
\2:
Opcode
MYI
MYI
Operand
D,9FH
D,YALUE
Comment
Labels of In;truction or Data. The label assigned to an IIlstructlon or a data definition has as its value the
address of tile first byte of the instruction or data. Instructions elsewhere in the program can refer to this
address by I:S symbolic label name.
-jERE:
fHERE;
Opcode
jMP
MVI
Operand
THERE
D,9FH
Comments
;jUMP TO INSTRUCTION AT THERE
Expressions. All of the operand types discussed previously can be combined by operators to form an expression.
In fact, the example given for the location counter ($+6) IS an expression that combines the location counter
with the decimal number 6.
Because the rules for coding expressions are rather extensive, further discussion of expressions is deferred until
later in this chapter.
2-6
Chapter 2. Assembly Language Concepts
Instructions as Operands. One operand type was intentionally omitted from the list of operand field infor-
mation: Instructions enclosed in parentheses may appear in the operands field. The operand has the value of
the left-most byte of the assembled instruction.
Label
INS:
Opcode
DB
Operand
(ADD C)
The statement above defines a byte with the value 81 H (the object code for an ADD C instruction). Such
coding is typically used where the object program modifies itself during execution, a technique that is strongly
discouraged.
Register-Type Operands. Only instructions that allow registers as operands may have register-type operands.
Expressions containing register-type operands are flagged as errors. Thus, an instruction like
JMP A
is flagged as an illegal use of a register.
The only assembler directives that may contain register-type operands are EQU, SET, and actual parameters in
macro calls. Registers can be assigned alternate names only by EQU or SET.
TWO'S COMPLEMENT REPRESENTATION OF DATA
Any 8-bit byte contains one of the 256 possible combinations of zeros and ones. Any particular combination may
be interpreted in a number of ways. For example, the code 1FH may be interpreted as an instruction (Rotate
Accumuiator Right Through Carry), as the hexadecimal value 1F, the decimal value 31, or simply the bit
pattern 00011111.
Arithmetic instructions assume that the data bytes upon which they operate are in the 'two's complement'
format. To understand why, let us first examine two examples of decimal arithmetic:
35
-12
23
35
+88
123
Notice that the results of the two examples are equal if we disregard the carry out of the high order position in
the second example. The second example illustrates subtraction performed by adding the ten's complement of
the subtrahend (the bottom number) to the minuend (the top number). To form the ten's complement of a
decimal number, first subtract each digit of the subtrahend from 9 to form the nine's complement; then add one
to the result to form the ten's complement. Thus, 99-12=87; 87+1=88, the ten's complement of 12.
The ability to perform subtraction with a form of addition is a great advantage in a computer since fewer cir-
cuits are required. Also, arithmetic operations within the computer are binary, which simplifies matters even more.
2-7
Chapter 2. Assembly Lalguage Concepts
The processol forms the two's complement of a binary value simply by reversing the value of each bit and then
adding one tc the result. Any carry out of the high order bit is ignored when the complement is formed. Thus,
the subtractic n shown previously is performed as follows:
35 =001 0 0011
-12 =0000 1100 =1111 0011
00100011
+11110100
23 +
1111 01 00
1 0001 0111 = 23
Again, by dis 'egarding the carry out of the high order position, the subtraction IS performed through a form of
addition. HO\/ever, if this operation were performed by the 8080 or [he 8085, the carry flag would be set OFF
at the end of the subtraction. This is because the processors complement the carry flag at the end of a subtract
operation so :hat it can be used as a 'borrow' flag in multibyte subtractions. In the example shown, no borrow
IS reqUired. St> the carry flag IS set OFF. By contrast, the carry flag IS set ON if we subtract 35 from 12:
12 = 000011 00
-35 =0010 0011 =11 01 11 00
+
-----'-
1101 1101
00001100
+1101 1101
1110 1001 =233 or --105
In this case, he absence of a carry indicates that a borrow IS reqUired from the next higher order byte, if any
Therefore, th 0 processor sets the carry flag ON. Notice also that the result is stored In a complemented form.
If you want 0 Interpret this result as a deCimal value, you must again form its two's complement:
111 0 1001 =0001 011 0
+ 1
0001 0111 = 23
Two's compl·'ment numbers may also be signed. When a byte IS Interpreted as a signed two's complement number,
the high ordu bit indicates the sign. A zero In thiS bit indicates a positive number, a one a negative number. The
seven low order bits provide the magnitude of the number. Thus, 0111 1111 equals +127
At the beglnlling of this description of two's complement arithmetic, it was stated that any 8-blt byte may con-
tain one of tile 256 possible combinations of zeros and ones. It must also be stated that the proper interpretation
of data is a r r,ogramming responsibility.
As an examp,e, consider the compare instruction. The compare logiC considers only the raw bit values of the
Items being compared. Therefore, a negative two's complement number always compares higher than a positive
number, bec;use the negative number's high order bit IS always ON. As a result, the meanings of the flags set by
the compare instruction are reversed. Your program must account for this condition.
2-8
Chapter 2. Assembly Language Concepts
SYMBOLS AND SYMBOL TABLES
Symbolic Addressing
If you have never done symbolic programming before, the following analogy may help clarify the distinction
between a symbolic and an absolute address.
The locations in program memory can be compared to a cluster of post office boxes. Suppose Richard Roe
rents box 500 for two months. He can then ask for his letters by saying 'Give me the mail in box 500: or
'Give me the mail for Roe.' If Donald Smith later rents box 500, he too can ask for his mail by either box
number 500 or by his name. The content of the post office box can be accessed by a fixed. absolute address
(500) or by a symbolic. variable name. The postal clerk correlates the symbolic names and their absolute values
In hiS log book. The assembler performs the same function. keeping track of symbols and their values in a
symbol table. Note that you do not have to assign values to symbolic addresses. The assembler references its
location counter during the assembly process to calculate these addresses for you. (The location counter does
for the assembler what the program counter does for the microcomputer. It tells the assembler where the next
instruction or operand is to be placed in memory.)
Symbol Characteristics
A symbol can contain one to six alphabetic (A-Z) or numeric (0-9) characters (with the first character alphabetic)
or the special character '7' or '@'. A dollar sign can be used as a symbol to denote the value currently in the
location counter For example, the command
jMP $+6
forces a jump to the instruction residing six memory locations higher than the JMP instruction. Symbols of the
form '??nnn' are generated by the assembler to uniquely name symbols local to macros.
The assembler regards symbols as haVing the following attributes: reserved or user-defined; global or limited;
permanent or redefinable; and absolute or relocatable.
Reserved. User-Defined. and Assembler-Generated Symbols
Reserved symbols are those that already have special meaning to the assembler and therefore cannot appear as
user-defined symbols. The mnemonic names for machine instructions and the assembler directives are all reserved
symbols.
2-9
Chapter 2. Assembly Lan;:uage Concepts
The following instruction operand symbols are also reserved:
Symbol
$
A
B
C
D
E
H
L
SP
PSW
M
STACK
MEMORY
Meaning
Location counter reference
Accumulator register
Register B or register pair Band C
Register C
Register D or register pair D and E
Register E
Register H or register pair Hand L
Register L
Stack pointer register
Program status word (Contents of A and status flags)
Memory reference code using address in Hand L
Special relocatability feature
Special relocatability feature
NOTE
The STACK and MEMORY symbols are fully discussed
in Chapter 4.
User-defined' ymbols are symbols you create to reference Instruction and data addresses. These symbols are
defined when they appear in the label field of an instruction or In the name field of EQU, SET, or MACRO
directives (see Chapters 4 and 5).
Assembler-ger erated symbols are created by the assembler to replace user-defined symbols whose scope is limited
to a macro d, finition.
Global and Um/'ed Symbols
Most symbol, are global. This means that they have meaning throughout your program. Assume, for example,
that you assifn the symbolic name RTN to a routine. You may then code a iump or a calJ to RTN from any
POlllt in your program. If you assign the symbolic name RTN to a second routine, an error results since you
have given ml i1tiple definitions to the same name.
Certain symbJls have meaning only within a macro definition or within a calJ to that macro; these symbols are
'local' to the macro. Macros require local symbols because the same macro may be used many times in the
program. If tile symbolic names within macros were global, each use of the macro (except the first) would cause
multiple defililtlons for those symbolic names.
See Chapter .; for additional information about macros.
2·10
Chapter 2. Assembly Language Concepts
Permanent and Redefinable Symbols
Most symbols are permanent since their value cannot change during the assembly operation. Only symbols
defined with the SET and MACRO assembler directives are redefinable.
Absolute and Relocatable Symbols
An important attribute of symbols with this assembler is that of relocatability. Relocatable programs are
assembled relative to memory location zero. These programs are later relocated to some other set of memory
locations. Symbols with addresses that change dUring relocation are relocatable symbols. Symbols with
addl-esses that do not change during relocation are absolute symbols. This distinction becomes important when
the symbols are used within expressions, as will be explained later.
External and public symbols are special types of relocatable symbols. These symbols are required to establish
program linkage when several relocatable program modules are bound together to form a single application
program. External symbols are those used in the current program module, but defined In another module.
Such symbols must appear in an EXTRN statement, or the assembler will flag them as undefined.
Conversely, PUBLIC symbols are defined in the current program module, but may be accessed by other
modules. The addresses for these symbols are resolved when the modules are bound together.
Absolute and relocatable symbols may both appear in a relocatable module. References to any of the assembler-
defined registers A through E, Hand L, PSW, SP, and M are absolute since they refer to hardware locations.
But these references are valid in any module.
ASSEMBLY-TIME EXPRESSION EVALUATION
An expression IS a combination of numbers, symbols, and operators. Each element of an expression is a term.
Expressions, like symbols, may be absolute or relocatable. For the sake of readers who do not require the
relocation feature, absolute expressions are described first. However, users of relocation should read all the
following.
Operators
The assembler Includes five groups of operators which permit the following assembly-time operations: arithmetic
operations, shift operations, logical operations, compare operations, and byte Isolation operations. It is important
to keep in mind that these are all assembly-time operations. Once the assembler has evaluated an expression, it
becomes a permanent part of your program. Assume, for example, that your program defines a list of ten con-
stants starting at the label LIST; the following instruction loads the address of the seventh item in the list Into
the Hand L registers:
LXI H,L1ST+6
Notice that LIST addresses the first item, L1ST+l the second, and so on.
2-11
Chapter 2. Assembly Lan ~ u a g e Concepts
Arithmetic Open tors
The anthmeti, operators are as follows:
Operator
+
*
MOD
Examples:
Meaf7/1lg
Unary or binary addition
Unary or blllary subtraction
Multiplication
Division. Any remainder is discarded (7/2=3).
Division by zero causes an error.
Modulo. Result is the remainder caused by a
division operation. (7 MOD 3=1)
The follOWing expressions generate the bit pattern for the ASCII character A;
5+30*2
(25/5)+30*2
5+( -30*·2)
Notice that tLe MOD operdtor must be separdted from ItS operands by spaces:
NUMBR MOD 8
Assuming tha. NUMBR has the value 25, the previous expression evaluates to the value
Shift Operators
The shift ope'atars are as !"ollows:
Operator
y SHR x
y SHL x
Meol7lf7g
Shift operand 'y' to the nght 'x' bit posItions.
Shift operand 'y' to the le!"t 'x' bit positions.
The shift operators do not wraparound any bits shihed out of the byte. Bit positions vacated by the shift
operation are zero·filled. Notice that the shift operatar must be separated from ItS operands by spaces.
Example:
Assume that NUMBR has the value 0101 0101, The effects of the shift operators is as follows:
2-12
NUMBR SHR
NUMBR SHL
0001 0101
1010 1010
Chapter 2. Assembly Language Concepts
Notice that a shift one bit position to the left has the effect of multiplying a value by two; a shift one bit
position to the right has the effect of dividing a value by two.
Logical Operators
The logical operators are as follows;
Operator
NOT
AND
OR
XOR
Meaning
Logical one's complement
Logical AND (=1 if both ANDed bits are 1)
Logical OR (=1 if either ORed bit is 1)
Logical EXCLUSIVE OR (=1 if bits are different)
The logical operators act only upon the least significant bit of values involved in the operation. Also, these
operators are commonly used In conditional IF directives. These directives are fully explained in Chapter 4.
Example:
The following IF directive tests the least significant bit of three Items. The assembly language code that follows
the IF is assembled only if the condition IS TRUE. This means that all three fields must have a one bit in the
least significant bit position.
IF FLDI AND FLD2 AND FLD3
Compare Operators
The compare operators are as follows:
Operator
EQ
NE
LT
LE
GT
GE
NUL
Meaning
Equal
Not equal
Less than
Less than or equal
Greater than
Greater than or equal
Special operator used to test for null (missing) macro
parameters
2-13
Chapter 2. Assembly Lan ;uage Concepts
The compare )perators Yield a yes-no result. Thus. if the evaluation of the relation is TRUE. the value of the
result is all ores. If false. the value of the result is all zeros. Relational operations are based strictly on magni-
tude comparisons of bit values. Thus. a two's complement negative number (which always has a one in its high
order bit) is g'eater than a two's complement positive number (which always has a zero in its high order bit).
Since the NU'_ operator applies only to the macro feature, NUL is described in Chapter 5.
The compare operators are commonly used in conditional IF directives. These directives are fully explained in
Chapter 4.
Notice that tl,e compare operator must be separated from its operands by spaces.
Example:
The following IF directive tests the values of FLDl and FLD2 for equality. If the result of the comparison is
TRUE, the aSiembly language coding following the IF directive IS assembled. Otherwise. the code is skipped over.
IF FLDl EQ FLD2
Byte Isolation Ooerators
The byte isolltion operators are as follows:
Operator
HIGH
LOW
Meaning
Isolate hlgh·order 8 bits of 16-bit value
Isolate low-order 8 bits of 16-blt value.
The assemble- treats expressions as 16-blt addresses. In certain cases. you need to deal only with a part of an
address. or Y<lU need to generate an 8-bit value. This IS the function of the HIGH and LOW operators.
The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbol; appears in the operand expression of an Immediate instruction. It must be preceded by either the
HIGH or LON operator to specify which byte of the address IS to be used In the evaluation of the expression.
When neithel operator is present. the assembler assumes the LOW operator and Issues an error message.
NOTE
Any program segment containing a symbol used as the
argument of a HIGH operator should be located only on
a page boundary. This is done using the PAGE option
with the CSEG or DSEG directives described in Chapter
4. Carries are not propagated from the low-order byte
when the assembler object code is relocated and the
carry flag will be lost. Using PAGE ensures that this
flag is 0_
2-14
Chapter 2. Assembly Language Concepts
Examples:
Assume that ADRS is an address manipulated at assembly-time for building tables or lists of items that must all
be below address 255 in memory. The following IF directive determines whether the high-order byte of ADRS
is zero, thus indicating that the address is still less than 256:
IF HIGH ADRS EQ 0
Permissible Range of Values
Internally, the assembler treats each term of an expression as a two-byte, 16-bit value. Thus, the maximum
range of values is OH through OFFFFH. All arithmetic operations are performed using unsigned two's comple-
ment arithmetic. The assembler performs no overflow detection for two-byte values, so these values are evaluated
modulo 64K.
Certain Instructions require that their operands be an eight-bit value. Expressions for these instructions must
yield values in the range -256 through +255. The assembler generates an error message if an expression for one
of these instructions yields an out-of-range value.
NOTE
Only instructions that allow registers as operands may have
register-type operands. Expressions containing register-type
operands are flagged as errors. The only assembler directives
that may contain register-type operands are EQU, SET, and
actual parameters in macro calls. Registers can be assigned
alternate names only by EQU or SET.
Precedence of Operators
Expressions are evaluated left to right. Operators with higher precedence are evaluated before other operators
that immediately precede or follow them. When two operators have equal precedence, the left-most is evaluated
first.
Parentheses can be used to override normal rules of precedence. The part of an expression enclosed In paren-
theses is evaluated first. If parentheses are nested, the Innermost are evaluated first.
15/3 + 18/9
15/(3 + 18/9)
=5+2=7
= 15/(3 + 2) = 15/5 = 3
2-15
Chapter 2. Assembly Lan :uage Concepts
The following list describes the classes of operators in order of precedence:
• Parenthesized expressions
• NUL
• HIGH, LOW
• Multiplication/Division: *. /, MOD, SHL, SHR
• Addition{Subtraction: +, - (unary and binary)
Relational Operators: EQ, LT, LE, GT, GE, NE
• Logical NOT
• Logical AND
• Logical OR, XOR
The relational, logical, and HIGH{LOW operators must be separated from their operands by at least one blank.
Relocatable Express ions
Determining t le relocatability of an expression requires that you understand the relocatability of each term used
in the express on. This is easier than it sounds since the number of allowable operators is substantially reduced.
But first it is lecessary to know what determines whether a symbol is absolute or relocatable.
Absolute symJols can be defined two ways:
• A symbol that appears in a label field when the ASEG directive is in effect IS an absolute symbol.
• A symbol defined as equivalent to an absolute expression using the SET or EQU directive is an
absolute symbol.
Relocatable s"mbols can be defined a number of ways:
• A symbol that appears in a label field when the DSEG or CSEG directive IS in effect is a relocatable
symbol.
• A symbol defined as equivalent to a relocatable expression using the SET or EQU directive is
reocatable.
• Tile special assembler symbols STACK and MEMORY are relocatable.
• E,ternal symbols are considered relocatable.
• A reference to the location counter (specified by the $ character) IS relocatable when the CSEG or
o,EG directive is in effect.
The expressions shown in the following list are the only expressions that yield a relocatable result. Assume that
ABS IS an symbol and RELOC IS a relocatable symbol:
ABS + RELOC
RELOC + ABS
RELOC - ABS
fHIGH'( RELOC+ABS
\ LOW )
[ HIGH RELOC _ ABS
)
r HIGH}
RELOC + LOW ABS
f HIGH '1
RELOC \ LOW } ABS
2-16
Chapter 2. Assemblv Language Concepts
Remember that numbers are absolute terms. Thus the expression RELOC - 100 is legal, but 100 - RELOC
is not.
When two relocatable symbols have both been defined with the same type of relocatability, they may appear In
certain expressions that yield an absolute result. Symbols have the same type of relocatability when both are
relative to the CSEG location counter, both are relative to the DSEG location counter, both are relative to
MEMORY, or both are relative to STACK. The following expressions are val id and produce absolute results:
RELOCl - RELOC2
EQ
LT
RELOCl LE RELOC2
GT
GE
NE
Relocatable symbols may not appear In expressions with any other operators.
The following list shows all possible combinations of operators with absolute and relocatable terms. An A in the
table indicates that the resulting address is absolute: an R indicates a relocatable address; an I Indicates an
illegal combination. Notice that only one term may appear with the last five operators in the list.
X absolute X absolute X relocatable X relocatable
Operator
Y absolute Y relocatable Y absolute Y reloca table
X + Y A R R I
X Y A I R A
X *
y
A I I I
X /
y
A I I I
X MOD
y
A I I I
X SHL Y A I I I
X SHR Y A I I I
X EQ Y A I I A
X LT Y A I I A
X LE Y A I I A
X GT Y A I I A
X GE Y A I I A
X NE Y A I I A
X AND
y
A I I I
X OR
y
A I I I
X XOR Y A I I I
NOT X A
- I
HIGH X A
-
R -
LOW X A
- R -
unary+ X A
- R -
unary- X A
- I
2-17
Chapter 2. Assemblv Larguage Concepts
Chaining of Symbol Definitions
The ISIS-II 81180/808S Macro Assembler is essentially a 2-pass assembler. All symbol table entries must be
resolvable in ; wo passes. Therefore,
x
y
is legal, but iii the series
x
y
Z
EQU
EQU
EQU
EQU
EQU
y
1
y
Z
1
the first line s illegal as X cannot be resolved in two passes and remains undefined.
2-18
3. INSTRUCTION SET
HOW TO USE THIS CHAPTER
This chapter is a dictionary of 8080 and 8085 Instructions. The instruction descriptions are listed alphabetically
for quick reference. Each description is complete so that you are seldom required to look elsewhere for addition-
al information.
This reference format necessarily requires repetitive information. If you are reading this manual to learn about
the 8080 or the 8085, do not try to read this chapter from ACI (add immediate with Carry) to XTHL (exchange
top of stack with Hand L registers). Instead, read the description of the processor and instruction set in
Chapter 1 and the programming examples in Chapter 6. When you begin to have questions about particular
instructions, look them up in this chapter.
TIMING INFORMATION
The instruction descriptions in this manual do not explicitly state execution timings. This is because the basic
operating speed of your processor depends on the clock frequency used in your system.
The 'state' IS the basic unit of time measurement for the processor. A state may range from 480 nanoseconds
(Cl20 nanoseconds on the 8085) to 2 microseconds, depending on the clock frequency. When you know the
length of a state In your system. you can determine an instruction's basic execution time by multiplying that
figure by the number of states required for the instruction.
Notice that two sets of cycle/state specifications are given for 8085 conditional call and jump instructions. This
is because the 8085 fetches the third instruction byte only if it is actually needed; i.e., the specified condition
is satisfied.
This basic timing factor can be affected by the operating speed of the memory in your system. With a fast
clock cycle and a slow memory, the processor can outrun the memory. In this case, the processor must wait
for the memory to deliver the desired instruction or data. In applications with critical timing requirements, this
wait can be significant. Refer to the appropriate manufacturer's literature for memory timing data.
3·1
Chapter 3. Instruction Se·
ACI ADD IMMEDIATE WITH CARRY
ACI adds the :ontents of the second instruction byte and the carry bit to the contents of the accumulator and
stores the result in the accumulator,
Opcode
ACI
Operand
data
The operand SJecifies the actual data to be added to the accumulator except, of course, for the carry bit. Data
may be in the form of a number, an ASCII constant, the label of a previously defined value, or an expression.
The data may not exceed one byte.
The assemblers relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbols appears in the operand expression of an immediate instruction, It must be preceded by either the
HIGH or LO\A operator to specify which byte of the address is to be used in the evaluation of the expression.
When neither )perator is present, the assembler assumes the LOW operator and issues an error message.
Example:
o 0
data
Cycles:
States:
AddreSSing:
Flags:
o
2
7
Immediate
Z,S,P,CY,AC
Assume that the accumulator contains the value 14H and that the carry bit is set to one. The instruction ACI 66
has the follol' ing effect:
ADC
Accumulator = 14H
Immediate data = 42H
Carry
00010100
01000010
1
01010111 57H
ADD WITH CARRY
3-2
The ADC inst ruction adds one byte of data plus the setting of the carry flag to the contents of the accumulator.
The result istored in the accumulator ADC then updates the setting of the carry flag to indicate the outcome
of the operaton.
The ADC innuction's use of the carry bit enables the program to add multi-byte numeric strings.
Chapter 3. Instruction Set
Add RegIster to Accumulator with Carry
Opccde
ADC
Operand
reg
The operand must specify one of the registers A through E, H or L. This instruction adds the contents of the
specified register and the carry bit to the accumulator and stores the result in the accumulator.
',-1__0_0__0__1 S S S I
CYcles:
States:
Addressings:
Flags:
Add Memory to Accumulator with Carry
Opcode
ADC
Operand
M
1
4
register
Z.s,P,CY,AC
This instruction adds the contents of the memory location addressed by the Hand L registers and the carry
bit to the accumulator and stores the result in the accumulator. M is a symbolic reference to the Hand L
registers.
Example:
CYcles:
States:
AddreSSing:
Flags:
2
7
register indirect
Z,S,P,CY,AC
Assume that register C contains 3DH, the accumulator contains 42H, and the carry bit is set to zero. The
instruction ADC C performs the addition as follows:
3DH
42H
CARRY
The condition flags are set as follows:
00111101
01000010
o
01111111 = 7FH
Carry 0
Sign 0
Zero 0
ParitY 0
Aux. Carry 0
3-3
Chapter 3. Instruction Set
If the carry !>it IS set to one, the instruction has the following results:
ADD
3DH
42H
CARRY
Carry
Sign
Zero
ParitY
Aux, Carry
00111101
01000010
1
10000000
o
1
o
o
1
SOH
ADD
The ADD In,truction adds one byte of data to the contents of the accumulatoL The result is stored in the
accumulator Notice that the ADD instruction excludes the carry flag from the addition but sets the flag to
indicate the Jutcome of the operation.
Add Regtstet to Register
Opcode
ADD
Operand
reg
The operand must specify one of the registers A through E, H or L. The instruction adds the contents of the
specified reg ster to the contents of the accumulator and stores the result in the accumulator.
11 0 0 0 0 Iss sl
Add From Memory
Cycles:
States:
Addressing:
Flags:
Opcode
ADD
Operand
M
1
4
register
Z,S,P,CY,AC
This InstruCilon adds the contents of the memory location addressed by the Hand L registers to the contents of
the accumulltor and stores the result in the accumulator. M is a symbolic reference to the Hand L registers.
11 0 0 0 0
34
Cycles:
States:
Addressing:
Flags:
2
7
register Indirect
Z,S,P,CY,AC
ADI
Chapter 3. Instruction Set
Examples:
Assume that the accumulator contains 6CH and register D contains 2EH. The Instruction ADD D performs the
addition as follows:
2EH 0010111 0
6CH 011011 00
9AH 10011010
The accumulator contains the value 9AH following execution of the ADD D instruction. The contents of the D
register remain unchanged. The condition flags are set as follows:
Carry 0
Sign 1
Zero 0
Parity 1
Aux. Carry 1
The following instruction doubles the contents of the accumulator:
ADD A
ADD IMMEDIATE
ADI adds the contents of the second instruction byte of the contents of the accumulator and stores the result
in the accumulator.
Opcode
ADI
Operand
data
The operand specifies the actual data to be added to the accumulator This data may be In the form of a number,
an ASCII constant, the label of a previously defined value, or an expression. The data may not exceed one byte.
The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbols appears in the operand expression of an immediate instruction, it must be preceded by either
the HIGH or LOW operator to specify which byte of the address is to be used In the evaluation of the expression.
When neither operator is present. the assembler assumes the LOW operator and Issues an error message.
l
'
000
data
Cycles:
States:
Addressing:
Flags:
2
7
immediate
Z.S.P.CY,AC
3-5
Chapter 3. Instruction Se
Example:
Assume that he accumulator contains the value 14H. The Instruction ADI 66 has the following effect:
Accumulator
Immediate data
14H
42H
00010100
01000010
01010110 = 56H
ANA
Notice that ti,e assembler converts the decimal value 66 into the hexadecimal value 42.
LOGICAL AND WITH ACCUMULATOR
ANA perforrrs a logical AND operation using the contents of the specified byte and the accumulator, The result
IS placed in tlie accumulator.
SummGlY of Operations
AN D product s a one bit In the result only when the corresponding bits In the test data and the mask data are
ones.
OR produces a one bit In the result when the corresponding bits in either the test data or the mask data are
ones.
Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are
different; I.e. a one bit in either the test data or the mask data - but not both - produces a one bit In the
result.
AND OR EXCLUSIVE OR
1010 1010
0000 1111
0000 1010
AND Registe, with Accumulator
Opcode
ANA
1010 1010
0000 1111
1010 1111
Operand
reg
1010
0000
1010
1010
1111
0101
The operand must specify one of the registers A through E, H or L. ThiS instruction ANDs the contents of the
specified regi iter with the accumulator and stores the result in the accumulator, The carry flag is reset to zero.
O_O_I S S S I
3-6
Cycles:
States:
Addressing:
Flags:
1
4
register
Z,S,P,CY,AC
Chapter 3. Instruction Set
AND Memory with Accumulator
Opcode
ANA
Operand
M
This Instruction ANDs the contents of the specified memory location with the accumulator and stores the result
in the accumulator. The carry flag is reset to zero.
Example:
o
Cycles:
States:
Addressing:
Flags:
o 0
2
7
register Indirect
Z,S,P,CY.AC
Since any bit ANDed with a zero produces a zero and any bit ANDed with a one remains unchanged, AND is
frequently used to zero particular groups of bits. The following example ensures that the high-order four bits of
the accumulator are zero, and the low·order four bits are unchanged. Assume that the C register contains OFH:
Accumulator
C Register
1 1 1 1
o 000
000 0
o 0
1 1
o 0
OFCH
OFH
OCH
ANI AND IMMEDIATE WITH ACCUMULATOR
ANI performs a logical AND operation using the contents of the second byte of the Instruction and the accumu-
lator. The result is placed In the accumulator. AN I also resets the carry flag to zero.
Opcode
ANI
Operand
data
The operand must specify the data to be used In the AND operation. This data may be in the form of a number,
an ASCII constant, the label of some previously defined value, or an expression. The data may not exceed one
byte.
The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbols appears in the operand expression of an immediate instruction, it must be preceded by either the
HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression.
When neither operator is present, the assembler assumes the LOW operator and issues an error message.
3-7
Chapter 3. Instruction Se:
l
'
Cycles:
States:
Addressing:
Flags:
Summary of ~ o g l c a l Operations
o 0
data
2
7
immediate
Z.S.P.CY,AC
AND prodUCt s a one bit in the result only when the corresponding bits In the test data and the mask data are
ones.
OR produces a one bit in the result when the corresponding bits In either the test data or the mask data are
ones.
Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are
different; i.e. a one bit in either the test data or the mask data - but not both - produces a one bit in the
result.
Example:
AND
1010 1010
0000 1111
00001010
OR
1010 1010
0000 1111
1010 1111
EXCLUSIVE OR
1010 1010
0000 1111
1010 0101
The followin;. instruction IS used to reset OFF bit SIX of the byte In the accumulator:
ANI 1011111IB
CALL
3-8
Since any bit ANDed with a one remains unchanged and a bit ANDed with a zero is rest to zero, the ANI
instruction srown above sets bit six OFF and leaves the others unchanged. This technique IS useful when a
program uses individual bits as status flags.
CALL
The CALL Irstructlon combines functions of the PUSH and IMP Instructions. CALL pushes the contents of the
program coullter (the address of the next sequential instruction) onto the stack and then iumps to the address
specified in t le CALL instruction.
Each CALL Instruction or one of ItS variants implies the use of a subsequent RET (return) Instruction. When a
call has no cllrresponding return. excess addresses are built up in the stack.
Opcode
CALL
Operand
address
Chapter 3. Instruction Set
The address may be specified as a number, a label, or an expression. (The label is most common.) The assembler
inverts the high and low address bytes when it assembles the instruction.
1 1 0 0 1 1 0 1
low addr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
5
17 (18 on 8085)
immediate/register indirect
none
When a given coding sequence is required several times in a program, you can usually conserve memory by coding
the sequence as a subroutine invoked by the CALL instruction or one of its variants. For example, assume that
an application drives a six-digit LED display; the display is updated as a result of an operator input or because
of two different calculations that occur in the program. The coding required to drive the display can be included
in-line at each of the three points where it is needed, or it can be coded as a subroutine. If the label DISPLY is
assigned to the first instruction of the display driver, the following CALL instruction is used to invoke the
display subroutine:
CALL DISPLY
This CALL instruction pushes the address of the next program instruction onto the stack and then transfers
control to the DISPLY subroutine. The DISPLY subroutine must execute a return instruction or one of its
variants to resume normal program flow. The following is a graphic illustration of the effect of CALL and return
instructions:
_ ~ DISPLY
---
CALL
CALL ~ DISPLY - - - - -
-------
---
- --
RET
CALL DISPLY
Consideration for Using Subroutines
The larger the code segment to be repeated and the greater the number of repetitions, the greater the potential
memory savings of using a subroutine. Thus, if the display driver in the previous example requires one hundred
3-9
Chapter 3. Instruction Se:
bytes, coding it In-line would require three hundred bytes. Coded as a subroutine, it requires one hundred bytes
plus nine bytls for the three CALL instructions.
Notice that slJbroutines require the use of the stack. This requires the application to include random access
memory for 1he stack. When an application has no other need for random access memory, the system designer
might elect to) avoid the use of subroutines.
CC CALL IF CARRY
The CC instnlction combines functions of the JC and PUSH instructions. CC tests the setting of the carry flag.
If the flag is ,et to one, CC pushes the contents of the program counter onto the stack and then jumps to the
address sped"ied in bytes two and three of the CC instruction. If the flag is reset to zero, program execution
continues whh the next sequential instruction.
Opcode
CC
Operand
address
Although thE use of a label is most common, the address may also be specified as a number or expression.
1 1 0 1 1 1 0 0
lowaddr
high addr
Example:
Cycles:
States:
AddreSSing:
Flags:
3 or 5 (2 or 5 on 8085)
11 or 17 (9 or 18 on 8085)
immediate/register indirect
none
CM
For the sake of brevity, an example IS given for the CALL instruction but not for each of its closely related
variants.
CALL IF MINUS
The CM inst-uction combines functions of the JM and PUSH instructions. CM tests the setting of the sign flag.
If the flag is set to one (indicating that the contents of the accumulator are minus), CM pushes the contents
of the progr,lm counter onto the stack and then jumps to the address specified by the CM instruction. If the
flag is set to zero, program execution simply continues with the next sequential instruction.
3-10
Opcode
CM
Operand
address
Chapter 3. Instruction Set
Although the use of a label is most common, the address may also be specified as a number or an expression.
1 1 1 1 1 1 0 0
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 or 5 (2 or 5 on 8085)
11 or 17 (9 or 18 on 8085)
immediate/register indirect
none
CMA
For the sake of brevity, an example is given for the CALL instruction but not for each of ItS closely related
variants.
COMPLEMENT ACCUMULATOR
CMA complements each bit of the accumulator to produce the one's complement. All condition flags remain
unchanged.
Opcode
CMA
Operand
Operands are not permitted with the CMA instruction.
10 0
Cycles:
States:
Flags:
o
1
4
none
To produce the two's complement, add one to the contents of the accumulator after the CMA instructions has
been executed.
Example:
Assume that the accumulator contains the value 51H; when complemented by CMA, it becomes OAEH:
51H
OAEH
01010001
10101110
3-11
Chapter 3. Instruction S, t
CMC COMPLEMENT CARRY
If the carry flag equals zero, CMC sets it to one. If the carry flag is one, CMC resets it to zero. All other flags
remain unch,nged.
Opcode
CMC
Operand
Operands are not permitted with the CMC instruction.
10 0
Example:
Cycles:
States:
Flags:
1
4
CYonly
Assume that a program uses bit 7 of a byte to control whether a subroutine is called. To test the bit, the pro-
gram loads ti,e byte into the accumulator, rotates bit 7 into the carry flag, and executes a CC (Call if Carry)
instruction. l:efore returning to the calling program, the subroutine reinitializes the flag byte using the following
code:
CMP
CMC
RAR
RET
;SET BIT 7 OFF
;ROTATE BIT 7 INTO ACCUMULATOR
;RETURN
COMPARE WITH ACCUMULATOR
3-12
CMP compar,s the specified byte with the contents of the accumulator and Indicates the result by setting the
carry and zelo flags. The values being compared remain unchanged.
The zero flal indicates equality. No carry indicates that the accumulator is greater than the specified byte; a
carry indicaus that the accumulator IS less than the byte. However, the meaning of the carry flag is reversed
when the values have different signs or one of the values is complemented.
The program tests the condition flags using one of the conditional Jump, Call, or Return instructions. For
example, J Z (J ump if Zero l tests for equality
Functnnal Description:
Comparisons are performed by subtracting the specified byte from the contents of the accumulator, which
IS why the zero and carry flags indicate the result. This subtraction uses the processor's internal registers
so that source data is preserved. Because subtraction uses two's complement addition, the CMP instruction
recoml'lements the carry flag generated by the sUbtraction.
Chapter 3. Instruction Set
Compare Register with Accumulator
Opcode
CMP
Operand
reg
The operand must name one of the registers A through E, H or L.
S s sl
Cycles:
States:
Addressing:
Flags:
Compare Memory with Accumulator
Opcode
CMP
1
4
register
Z,S,P,CY,AC
Operand
M
This instruction compares the contents of the memory location addressed by the Hand L registers with the
contents of the accumulator. M is a symbolic reference to the Hand L register pair.
Example 1:
Cycles:
States:
Addressing:
Flags:
2
7
register indirect
Z,S,P,CY,AC
Assume that the accumulator contains the value OAH and register E contains the value OSH. The instruction
CMP E performs the following internal subtraction (remember that subtraction is actually two's complement
addition):
Accumulator
+( -E Register)
00001010
11111011
00000101 +(-carry)
After the carry is complemented to account for the subtract operation, both the zero and carry bits are zero,
thus indicating A greater than E.
Example 2:
Assume that the accumulator contains the value -1 BH and register E contains OSH:
Accumulator
+(-E Register)
11100101
11111011
111 00000 +(-carry)
3-13
Chapter 3. Instruction S ,t
After the 01P Instruction recomplements the carry flag, both the carry flag and zero flag are zero. Normally
this indicate, that the accumulator is greater than register E. However. the meaning of the carry flag IS reversed
since the val Jes have different signs. The user program is responsible for proper interpretation of the carry flag.
CNC CALL IF NO CARRY
The CNC in, truction combines functions of the JNC and PUSH instructions. CNC tests the setting of the carry
flag. If the fag is set to zero, CNC pushes the contents of the program counter onto the stack and theniumps
to the addre;s specified by the CNC instruction. If the flag IS set to one, program execution simply continues
with the ne> t sequential instruction.
Opcode
CNC
Operand
address
Although th,: use of a label is most common, the address may also be specified as a number or an expression.
1 1 0 1 0 1 0 0
low addr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 or 5 (2 or 5 on 8085)
11 or 17 (9 or 18 on 8085)
immediate/register Indirect
none
CNZ
For the sake of brevity, an example IS given for the CALL instruction but not for each of its closely related
vanants.
CALL IF NOT ZERO
The CNZ In, tructlon combines functions of the JNZ and PUSH Instructions. CNZ tests the setting of the zero
flag. If the fag is off (indicating that the contents of the accumulator are other than zero), CNZ pushes the
contents of :he program counter onto the stack and then jumps to the address specified in the Instruction's
second and hiI'd bytes. If the flag is set to one, program execution simply continues with the next sequential
instruction.
Opcode
CNZ
Operand
address
3-14
Although th; use of a label is most common, the address may also be specified as a number or an expression.
1 1 0 0 0 1 0 0
lowaddr
high addr
Chapter 3. Instruction Set
Example:
Cycles:
States:
Addressing:
Flags:
3 or 5 (2 or 5 on 8085)
1.1 or 17 (9 or 18 on 8085)
immediate/register indirect
none
CP
For the sake of breVity, an example is given for the CALL instruction but not for each of its closely related
variants.
CALL IF POSITIVE
The CP instruction combines features of the JP and PUSH instructions. CP tests the setting of the sign flag. If
the flag is set to zero (indicating that the contents of the accumulator are positive). CP pushes the contents of
the program counter onto the stack and theniumps to the address specified by the CP Instruction. If the flag
is set to one, program execution simply continues with the next sequential instruction.
Opcode
CP
Operand
address
Although the use of a label is more common, the address may also be specified as a number or an expression.
1 1 1 1 0 1 0 0
low address
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 or 5 (2 or 5 on 8085)
11 or 17 (9 or 18 on 8085)
immediate/register indirect
none
For the sake of brevity, an example is given for the CALL instruction but not for each of its closely related
variants.
3-15
Chapter 3. Instruction Se,
CPE CALL IF PARITY EVEN
Parity is even if the byte in the accumulator has an even number of one bits. The parity flag is set to one to
indicate this condition. The CPE and CPO instructions are useful for testing the parity of input data. However,
the IN instruc tion does not set any of the condition flags. The flags can be set without altering the data by
adding OOH t" the contents of the accumulator.
The ePE instI uction combines functions of the JPE and PUSH instructions. CPE tes\s the setting of the parity
flag. If the flog is set to one, CPE pushes the contents of the program counter onto the stack and then jumps
to the addres' specified by the CPE instruction. If the flag is set to zero, program execution simply continues
with the next sequential instruction.
Opcode
CPE
Operand
address
Although the use of a label is more common, the address may also be specified as a number or an expression.
1 1 1 0 1 1 0 0
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 or 5 (2 or 5 on 8085)
11 or 17 (9 or 18 on 8085)
immediate/register Indirect
none
CPI
For the sake )f brevity, an example is given for the CALL instruction but not for each of its closely related
variants.
COMPARE IMMEDIATE
CPI compare, the contents of the second instruction byte with the contents of the accumulator and sets the zero
and carry flap to indicate the result. The values being compared remain unchanged.
The zero flag Indicates equality. No carry indicates that the contents of the accumulator are greater than the
immediate da :a; a carry Indicates that the accumulator is less than the immediate data. However, the meaning
of the carry 1lag is reversed when the values have different signs or one of the values is complemented.
3·16
Opcode
CPI
Operand
data
Chapter 3. Instruction Set
The operand must specify the data to be compared. This data may be in the form of a number, an ASCII
constant, the label of a previously defined value, or an expression. The data may not exceed one byte.
The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbols appears in the operand expression of an immediate instruction, it must be preceded by either
the HIGH or LOW operator to specify which byte of the address is to be used In the evaluation of the
expression. When neither operator is present, the assembler assumes the LOW operator and issues an error
message.
o
data
Example:
Cycles:
States:
Addressing:
Flags:
2
7
register Indirect
Z,S,P,CY,AC
CPO
The instruction CPI 'C' compares the contents of the accumulator to the letter C (43H).
CALL IF PARITY ODD
Parity is odd if the byte in the accumulator has an odd number of one bits. The panty flag is set to zero to
indicate this condition. The CPO and CPE instructions are useful for testing the parity of input data. However,
the IN instruction does not set any of the condition flags. The flags can be set without altering the data by
adding OOH to the contents of the accumulator.
The CPO instruction combines functions of the JPO and PUSH instructions. CPO tests the setting of the panty
flag. If the flag is set to zero, CPO pushes the contents of the program counter onto the stack and then jumps
to the address specified by the CPO instruction. If the flag is set to one, program execution simply continues
with the next sequential instruction.
Opcode
CPO
Operand
address
Although the use of a label is more common, the address may also be specified as a number or an expression.
1 1 1 0 0 1 0 0
lowaddr
high addr
Cycles:
States:
Addressing:
Flags:
3 or 5 (2 or 5 on 8085)
11 or 17 (9 or 18 on 8085)
immediate/register indirect
none
3-17
Chapter 3. Instruction Sf t
Example:
For the sake of brevity, an example is given for the CALL Instruction but not for each of its closely related
vanants.
CZ CALL IF ZERO
The CZ instrJCtion combines functions of the I Z and PUSH Instructions. CZ tests the setting of the zero flag.
If the flag IS ;et to one (indicating that the contents of the accumulator are zero), CZ pushes the contents of
the program :ounter onto the stack and then lumps to the address specified in the CZ instruction. If the flag
IS set to zero (indicating that the contents of the accumulator are other than zero), program execution simply
continues wil h the next sequential Instruction.
Opcode
CZ
Operand
address
Although the use of a label is most common, the address may also be specified as a number or an expression.
1 I 0 0 1 1 0 0
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 or 5 (2 or 5 on 8085)
11 or 17 (9 or 18 on 8085)
Immediate/register Indirect
none
DAA
For the sake of brevity, an example IS given for the CALL instruction but not for each of its closely related
vanants.
DECIMAL ADJUST ACCUMULATOR
The DAA adjusts the eight-bit value in the accumulator to form two four-bit binary coded deCimal
digits.
Opcode
DAA
Operand
3-18
Operands are not permitted with the DAA IIlstructlon.
DAA IS used when adding deCimal numbers. It is the only instruction whose function requires use of the auxiliary
carry flag. In multi-byte arithmetiC operations, the DAA instruction typically is coded immediately after the arith-
metic instruc tion so that the auxiliary carry flag is not altered unintentionally.
Chapter 3. Instruction Set
DAA operates as follows:
1. If the least significant four bits of the accumulator have a value greater than nine, or if the auxiliary
carry flag is ON, DAA adds six to the accumulator.
2. If the most significant four bits of the accumulator have a value greater than nine, or if the carry
flag IS ON, DAA adds six to the most significant four bits of the accumulator.
Example:
10 0
Cycles:
States:
Addressing:
Flags:
o 0
1
4
register
Z,S,P,CY,AC
Assume that the accumulator contains the value 9BH as a result of adding 08 to 93:
CY AC
0 0
1001 0011
0000 1000
1001 1011 = 9BH
Since OBH IS greater than nine, the Instruction adds six to contents of the accumulator:
CY
o
1001
0000
1010
AC
1
1011
0110
0001 = A1H
Now that the most significant bits have a value greater than nine, the instruction adds SIX to them:
CY
1
1010
0110
0000
AC
1
0001
0000
0001
When the DAA has finished, the accumulator contains the value 01 in a BCD format; both the carry and auxiliary
carry flags are set ON. Since the actual result of this addition is 101, the carry flag IS probably significant to the
program. The program IS responsible for recovering and using this information. Notice that the carry flag setting is
lost as soon as the program executes any subsequent Instruction that alters the flag.
3-19
Chapter 3. Instruction S,t
DAD DOUBLE REGISTER ADD
DAD adds ti,e 16-bit value in the specified register pair to the contents of the Hand L register pair. The result
is stored in Hand L.
Opcode
DAD
Operand
DAD may add only the contents of the B&C, D&E, H&L, or the SP (Stack Pointer) register pairs to the contents
of H& L. No ice that the letter H must be used to specify that the H& L register pair is to be added to Itself.
DAD sets th ~ carry flag ON if there is a carry out of the Hand L registers. DAD affects none of the condition
flags other han carry.
Examples:
Cycles:
States:
Addressing:
Flags:
3
10
register
CY
The DAD in ;truction provides a means for saving the current contents of the stack pointer.
LXI
DAD
SHLD
H,OOH
SP
SAVSP
;CLEAR H&L TO ZEROS
;GET SP INTO H&L
;STORE SP IN MEMORY
DCR
The instruct on DAD H doubles the number in the Hand L registers except when the operation causes a carry
out of the f- register.
DECREMENT
DCR subtra'ts one from the contents of the specified byte. DCR affects all the condition flags except the carry
flag. Becaus( DCR preserves the carry flag, it can be used within multi-byte arithmetic routines for decrementing
character co Jnts and similar purposes.
Decrement I ~ e g i s t e r
3-20
Opcode
DCR
Operand
reg
Chapter 3. Instruction Set
The operand must specify one of the registers A through E, H or L. Thp. instruction subtracts one from the
contents of the specified register.
~ D D D
Decrement Memory
Cycles:
States:
Addressing:
Flags:
Opcode
DCR
1
5 (4 on 8085)
register
Z,S,P,AC
Operand
M
This instruction subtracts one from the contents of the memory location addressed by the Hand L registers.
M is a symbol ic reference to the Hand L registers.
Example:
10 0
Cycles:
States:
Addressing:
Flags:
o
3
10
register indirect
Z,S,P,AC
The DCR instruction is frequently used to control multi-byte operations such as moving a number of characters
from one area of memory to another:
LOOP:
MVI
LXI
LXI
MOV
STAX
DCX
DCX
DCR
JNZ
B,5H
H,260H
D.900H
A,M
D
D
M
B
LOOP
;SET CONTROL COUNTER
;LOAD H&L WITH SOURCE ADDR
;LOAD D&E WITH DESTINATION ADDR
;LOAD BYTE TO BE MOVED
;STORE BYTE
;DECREMENT DESTINATION ADDRESS
;DECREMENT SOURCE ADDRESS
;DECREMENT CONTROL COUNTER
;REPEAT LOOP UNTIL COUNTER=O
This example also illustrates an efficient programming technique. Notice that the control counter is decremented
to zero rather than incremented until the desired count is reached. This technique avoids the need for a compare
instruction and therefore conserves both memory and execution time.
3-21
Chapter 3. Instruction Sct
DCX DECREMENT REGISTER PAIR
DCX decrerrents the contents of the specified register pair by one. DCX affects none of the condition flags.
Because DC: preserves all the flags, it can be used for address modification in any instruction sequence that
relies on the passing of the flags.
Opcode
DCX
Operand
DCX may dlcrement only the B&C, D&E, H&L, or the SP (Stack Pointer) register pairs. Notice that the letter
H must be u;ed to specify the Hand L pair.
Exercise carl' when decrementing the stack pointer as this causes a loss of synchronization between the pointer
and the actual contents of the stack.
Example:
Cycles:
States:
Addressing:
Flags:
1
5 (6 on 8085)
register
none
DI
Assume that the Hand L registers contain the address 9800H when the instruction DCX H is executed. DCX
considers tht: contents of the two registers to be a single 16-bit value and therefore performs a borrow from the
H register te produce the value 97FFH.
DISABLE INTERRUPTS
The interruet system is disabled when the processor recognizes an interrupt or Immediately following execution
of a DI instl uction.
In applicaticns that use interrupts, the DI instruction is commonly used only when a code sequence must not be
interrupted. For example, time-dependent code sequences become inaccurate when interrupted. You can disable
the interrup system by including a DI instruction at the beginning of the code sequence. Because you cannot
predict the llccurrence of an interrupt, include an EI instruction at the end of the time-dependent code sequence.
Opcode
DI
Operand
3-22
Operands an not permitted with the DI instruction.
EI
Chapter 3. Instruction Set
1
1 0 0
11
Cycles: 1
States: 4
Flags: none
NOTE
The 8085 TRAP interrupt cannot be disabled. This special interrupt is
intended for serious problems that must be serviced regardless of the
interrupt flag such as power failure or bus error. However. no interrupt
including TRAP can interrupt the execution of the 01 or EI instruction.
ENABLE INTERRUPTS
The EI instruction enables the interrupt system following execution of the next program instruction. Enabling
the interrupt system is delayed one instruction to allow interrupt subroutines to return to the main program
before a subsequent interrupt is acknowledged.
In applications that use interrupts, the interrupt system is usually disabled only when the processor accepts an
interrupt or when a code sequence must not be interrupted. You can disable the interrupt system by including
a 01 instruction at the beginning of the code sequence. Because you cannot predict the occurrence of an
interrupt, include an EI instruction at the end of the code sequence.
Opcode
EI
Operand
Operands are not permitted With the EI instruction.
o
Cycles:
States:
Flags:
1
4
none
NOTE
The 8085 TRAP interrupt cannot be disabled. This special interrupt is
intended for serious problems that must be serviced regardless of the
interrupt flag such as power failure or bus failure. However, no interrupt
including TRAP can interrupt the execution of the 01 or EI instruction.
Example:
The EI instruction is frequently used as part of a start-up sequence. When power is first applied. the processor
begins operating at some indeterminate address_ Application of a RESET signal forces the program counter to
3-23
Chapter 3. Instruction 5et
zero. A common instruction sequence at this point is El, HLT, These instructions enable the interrupt system
(RESET als" disables the interrupt system) and halt the processor. A subsequent manual or automatic interrupt
then determ Ines the effective start-up address.
HLT HALT
The HLT in ;truction halts the processor. The program counter contains the address of the next sequential
instruction. Jtherwise, the flags and registers remain unchanged.
o
Cycles:
States:
Flags:
1
7 (5 on 8085)
none
IN
Once in the halt state, the processor can be restarted only by an external event, typically an interrupt. Therefore,
you should Je certain that interrupts are enabled before the HLT instruction is executed. See the description of
the EI (EnaJle Interrupt) instruction.
If an 8080 I-lLT instruction IS executed while interrupts are disabled, the only way to restart the processor is
by applicatim of a RESET signal. This forces the program counter to zero. The same is true of the 8085, except
for the TR/,P Interrupt, which IS recognized even when the interrupt system is disabled.
The proceSSJr can temporarily leave the halt state to service a direct memory access request. However, the pro-
cessor the halt state once the request has been serviced.
A basic purpose for the HLT instruction is to allow the processor to pause while waiting for an interrupt from a
peripheral However, a halt wastes processor resources and should be used only when there is no useful
processing t Isk available.
INPUT FROM PORT
The IN inst uction reads eight bits of data from the specified port and loads it into the accumulator.
NOTE
fhis description IS restricted to the exact function of the IN instruction.
Input/output structures are described in the 8080 or 8085 Microcomputer
Systems User's Manual.
Opcode
IN
Operand
exp
3·24
The operand expression may be a number or any expression that yields a value in the range OOH through OFFH.
INR
°
Cycles:
States:
Addressing:
Flags:
exp
°
3
10
direct
none
Chapter 3. Instruction Set
INCREMENT
INR adds one to the contents of the specified byte. INR affects all of the condition flags except the carry flag.
Because INR preserves the carry flag, it can be used within multi-byte arithmetic routines for incrementing
character counts and similar purposes.
Increment Register
Opcode
INR
Operand
reg
The operand must specify one of the registers A through E, H or L. The Instruction adds one to the contents of
the specified register,
~ I D D D 1__0_01
Increment Memory
Cycles:
States:
Addressing:
Flags:
Opcode
INR
1
5 (4 on 8085)
register
Z,S,P,AC
Operand
M
This instruction increments by one the contents of the memory location addressed by the Hand L registers. M
is a symbolic reference to the Hand L registers.
1° °
Cycles:
States:
Addressing:
Flags:
°
°°I
3
10
register indirect
Z,S,P,AC
3·25
Chapter 3. Instruction 5,t
Example:
If register C contains 99H, the instruction INR C increments the contents of the register to 9AH.
INX INCREMENT REGISTER PAIR
INX adds olle to the contents of the specified register pair. INX affects none of the condition flags. Because
INX preserVlS all the condition flags, it can be used for address modification within multi-byte arithmetic
routines.
Opcode
INX
Operand
INX may lIl;rement only the B&C, D&E, H& L, or the SP (Stack Pointer) register pairs. Notice that the letter H
must be usd to specify the Hand L register pair.
Exercise caro when incrementing the stack pOlllter. Assume, for example, that INX SP IS executed after a number
of Items ha' e been pushed onto the stack. A subsequent POP instruction accesses the high-order byte of the most
recent stack entry and the low-order byte of the next older entry. Similarly, a PUSH Instruction adds the two
new bytes t) the stack, but overlays the low-order byte of the most recent entry
Example:
Cycles:
States:
Addresslllg:
Flags:
1
5 (6 on 8085)
register
none
JC
3-26
Assume tha. the D and E registers contalll the value 01 FFH. The instruction INX D increments the value to
0200H. By ;ontrast, the INR E Instruction ignores the carry out of the low-order byte and produces a result of
0100H. (Tills condition can be detected by testing the Zero condition flag.)
If the stack pointer register contallls the value OFFFFH, the instruction INX SP increments the contents of SP
to OOOOH. --he INX instruction sets no flags to IIldicate this condition.
JUMP IF CARRY
The JC instruction tests the setting of the carry flag. If the flag is set to one, program execution resumes at the
address spe;ified in the JC instruction. If the flag is reset to zero, execution continues with the next sequential
instruction.
Opcode
JC
Operand
address
Chapter 3. Instruction Set
The address may be specified as a number, a label, or an expression. The assembler inverts the high and low
address bytes when it assembles the instruction.
1 1 0 1 1 0 1 0
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 (2 or 3 on 8085)
10 (7 or 10 on 8085)
immediate
none
JM
Examples of the variations of the jump instruction appear in the description of the JPO instruction.
JUMP IF MINUS
The JM Instruction tests the setting of the sign flag. If the contents of the accumulator are negative (sign flag =1),
program execution resumes at the address specified In the Jrv1 instruction. If the contents of the accumulator are
positive (sign flag =0), execution continues with the next sequential instruction.
Opcode
JM
Operand
address
The address may be specified as a number, a label, or an expression. The assembler inverts the high and low
address bytes when it assembles the instructions.
1 1 1 1 1 0 1 0
lowaddr
high addr
Example:
CYcles:
States:
Addressing:
Flags:
3 (2 or 3 on 8085)
10 (7 or 10 on 8085)
immediate
none
Examples of the variations of the lump instruction appear in the description of the JPO instruction.
3-27
Chapter 3. Instruction Set
JMP JUMP
The IMP inst"uction alters the execution sequence by loading the address in its second and third bytes into the
program courter.
Opeode
IMP
Operand
address
The address rnay be specified as a number, a label, or an expression. The assembler inverts the high and low
address bytes when it assembles the address.
1 1 0 0 0 0 1 1
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3
10
immediate
none
JNC
Examples of the variations of the Jump instruction appear in the description of the JPO instruction.
JUMP IF NO CARRY
The INC ins;ruction tests the setting of the carry flag. If there is no carry (carry flag =0), program execution
resumes at ti,e address specified in the I NC instruction. If there is a carry (carry flag =1), execution continues
with the nex t sequential Instruction.
Ooeode
INC
Operand
address
The address nay be specified as a number, a label, or an expression. The assembler inverts the high and Jow
address byte; when it assembles the instruction.
1 1 0 1 0 0 1 0
lowaddr
high addr
3-28
Cycles:
States:
Addressing:
Flags:
3 (2 or 3 on 8085)
10 (7 or 10 on 8085)
immediate
none
JNZ
Chapter 3. Instruction Set
Example:
Examples of the variations of the jump instruction appear in the description of the JPO Instruction.
JUMP IF NOT ZERO
The JNZ Instruction tests the setting of the zero flag. If the contents of the accumulator are not zero (zero
flag = 0), program execution resumes at the address specified In the JNZ instruction. If the contents of the
accumulator are zero (zero flag = 1), execution continues with the next sequential instruction.
Opcode
JNZ
Operand
address
The address may be specified as a number, a label, or an expression. The assembler inverts the high and low
address bytes when it assembles the instruction.
1 1 0 0 0 0 1 0
lowaddr
high addr
Example:
Cycles:
States:
AddreSSing:
Flags:
3 (2 or 3 on 8085)
10 (7 or 10 on 8085)
immediate
none
JP
Examples of the variations of the lump instruction appear In the description of the J PO instruction.
JUMP IF POSITIVE
The JP instruction tests the setting of the sign flag. If the contents of the accumulator are positive (sign flag =0),
program execution resumes at the address specified in the JP Instruction. If the contents of the accumulator are
minus (sign flag =1), execution continues with the next sequential instruction.
Opcode
JP
Operand
address
The address may be specified as a number, a label, or an expression. The assembler inverts the high and low order
address bytes when it assembles the instruction.
3-29
Chapter 3. Instruction 51 t
1 1 1 1 0 0 1 0
lowaddr
high addr
Example:
Cycles:
States:
Addressi ng:
Flags:
3 (2 or 3 on 8085)
10 (7 or 10 on 8085)
immediate
none
JPE
Examples of the variations of the lump instruction appear in the description of the JPO instruction.
JUMP IF PARITY EVEN
Parity IS evell if the byte In the accumulator has an even number of one bits. The parity flag IS set to one to
indicate this condition.
The J PE Instruction tests the setting of the parity flag. If the parity flag is set to one, program execution resumes
at the a d d r e ~ s specified in the JPE instruction. If the flag IS reset to zero, execution continues with the next
sequential in ;truction.
Opcode
JPE
Operand
address
The address may be specified as a number, a label, or an expression. The assembler inverts the high and low
address byte, when it assembles the instruction.
The J PE anc J PO (jump if parity odd) instructions are especially useful for testing the parity of input data.
However, th., IN instruction does not set any of the condition flags. The flags can be set by adding OOH to the
contents of .he accumulator.
1 1 1 0 1 0 1 0
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 (2 or 3 on 8085)
10 (7 or 10 on 8085)
Immediate
none
3-30
Examples 01 the variations of the lump instruction appear In the deSCrIption of the JPO instruction.
JPO
Chapter 3. Instruction Set
JUMP IF PARITY ODD
Parity is odd if the byte in the accumulator has an odd number of one bits. The parity flag is set to zero to
indicate this condition.
The JPO Instruction tests the setting of the parity flag. If the parity flag is reset to zero, program execution
resumes at the address specified in the JPO instruction. If the flag is set to one. execution continues with the
next sequential instruction.
Opcode
JPO
Operand
address
The address may be specified as a number. a label. or an expression. The assembler Inverts the high and low
address bytes when it assembles the instruction.
The JPO and JPE (jump if panty even) instructions are especially useful for testing the parity of Input data.
However. the IN instruction does not set any of the condition flags. The flags can be set by adding OOH to the
contents of the accumulator.
1 1 1 0 0 0 1 0
low addr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 (2 or 3 on 8085)
10 (7 or 10 on 8085)
Immediate
none
This example shows three different but equivalent methods for lumping to one of two points in a program based
upon whether or not the Sign bit of a number is set. Assume that the byte to be tested IS the C register.
Label
ONE:
TWO:
THREE:
PLUS:
MINUS:
Code Operand
MOV A.C
ANI 80H
JZ
PLUS
JNZ MINUS
MOV A.C
RLC
JNC PLUS
JMP MINUS
MOV A.C
ADI 0
JM MINUS
;SIGN BIT RESET
;SIGN BIT SET
3-31
Chapter 3. Instruction Set
The AND iinmediate instruction in block ONE zeroes all bits of the data byte except the Sign bit, which re-
mains unch lnged. If the Sign bit was zero, the Zero condition bit will be set, and the JZ instruction will cause
program coltrol to be transferred to the Instruction at PLUS. Otherwise, the JZ instruction will merely update
the progranl counter by three, and the JNZ instruction will be executed, causing control to be transferred to
the instruct ion at MINUS. (The Zero bit IS unaffected by all jump instructions.)
The RLC illstruction in block TWO causes the Carry bit to be set equal to the Sign bit of the data byte. If the
Sign bit wai reset, the JNC instruction causes a lump to PLUS. Otherwise the JMP instruction is executed,
unconditiollally transferring control to MINUS. (Note that, in this instance, a JC instruction could be sub-
stituted for the unconditional jump with identical results.)
The add irrmediate instruction In block THREE causes the condition bits to be set. If the sign bit was set, the
JM instruction causes program control to be transferred to MINUS. Otherwise, program control flows auto-
matically ino the PLUS routine.
JZ JUMP IF ZERO
The JZ Ins",ruction tests the setting of the zero flag. If the flag is set to one, program execution resumes at the
address in the JZ instruction. If the flag is reset to zero, execution continues with the next sequential
Instruction
Opcode
JZ
Operand
address
The addresi may be specified as a number, a label, or an expression. The assembler inverts the high and low
address by! es when it assembles the instruction.
1 1 0 0 1 0 1 0
low addr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
3 (2 or 3 on 8085)
10 (7 or lOon 8085)
Immediate
none
LOA
3-32
Examples )f the variations of the jump instruction appear In the deswptlon of the JPO instruction.
LOAD ACCUMULATOR DIRECT
LDA the accumulator with a copy of the byte at the location specified In bytes two and three of the
LDA instr Jction.
Opcode
LDA
Operand
address
Chapter 3. Instruction Set
The address may be stated as a number. a previously defined label. or an expression. The assembler inverts the
high and low address bytes when it builds the instruction.
0 0 1 1 1 0 1 0
lowaddr
high addr
Examples:
CYcles:
States:
Addressing:
Flags:
4
13
direct
none
The following instructions are equivalent. When executed. each replaces the accumulator contents with the byte
of data stored at memory location 300H.
LDAX
LOAD: LDA
LDA
LDA
300H
3*{16*16)
200H+256
LOAD ACCUMULATOR INDIRECT
L DAX loads the accumulator with a copy of the byte stored at the memory location addressed by register pair
B or register pair D.
Opcode
LDAX
Operand
The operand B specifies the Band C register pair: D specifies the D and E register pair. This instruction may
specify only the B or D register pair.
10 0 0 I ~ 0 0 I
-'--------
I fo '" register pair B
II '" register pair D
Cycles:
States:
Addressing:
Flags:
2
7
register indirect
none
3-33
Chapter 3. Instruction :,et
Example:
Assume that register D contains 93H and register E contains 8BH. The following instruction ioads the accumulator
with the contents of memory location 938BH:
LDAX D
LHLD LOAD HAND L DIRECT
LHLD loads the L register with a copy of the byte stored ilt the memory location specified in bytes two and
three of the LHLD instruction. LHLD then loads the H register with a copy of the byte stored at the next
higher memory location.
Opcode
LHLD
Operand
address
The address may be stated as a number, a label, or an expression.
Certain instl uctions use the symbolic reference M to access the memory location currently specified by the Hand
L registers. _HLD is one of the instructions provided for loading new addresses into the Hand L registers. The
user may al:o load the current top of the stack into the Hand L registers (POP instruction). Both LHLD and
POP replace the contents of the Hand L registers. You can also exchange the contents of Hand L with the D
and E r e g i s t ~ r s (XCHG instruction) or the top of the stack (XTHL instruction) if you need to save the current
Hand L registers for subsequent use. SHLD stores Hand L in memory.
0 0 1 0 1 0 1 0
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
5
16
direct
none
Assume that locations 3000 and 3001 H contain the address 064EH stored in the format 4E06. In the following
sequence, tlie MaY instruction moves a copy of the byte stored at address 064E into the accumulator:
3·34
LHLD
MaY
3000H
A,M
;SET UP ADDRESS
;LOAD ACCUM FROM ADDRESS
LXI
Chapter 3. Instruction Set
LOAD REGISTER PAIR IMMEDIATE
LXI is a three-byte instruction; its second and third bytes contain the source data to be loaded into a register
pair. LXI loads a register pair by copying its second and third bytes into the specified destination register pair.
Opcode
LXI
Operand
The first operand must specify the register pair to be loaded. LXI can load the Band C register pair, the D and
E register pair, the Hand L register pair, or the Stack Pointer.
The second operand specifies the two bytes of data to be loaded. This data may be coded in the form of a num-
ber, an ASCII constant, the label of some previously defined value, or an expression. The data must not exceed
two bytes.
LXI is the only immediate instruction that accepts a 16-bit value. All other immediate instructions require 8-bit
values.
Notice that the assembler inverts the two bytes of data to create the format of an address stored in memory.
LXI loads its third byte into the first register of the pair and its second byte into the second register of the
pair. This has the effect of reinverting the data into the format required for an address stored in registers. Thus,
the instruction LXI S,'AZ' loads A Into register Band Z into register C.
0
o IR P I0
0 0 1
low-order data
high-order data
Examples:
Cycles:
States:
Addressing:
Flags:
3
10
immediate
none
A common use for LXI is to establish a memory address for use in subsequent instructions. In the following
sequence, the LXI instruction loads the address of STRNG into the Hand L registers. The MOV instruction then
loads the data stored at that address into the accumulator.
LXI
MOV
H,STRNG
A,M
;SET ADDRESS
;LOAD STRNG INTO ACCUMULATOR
The following LXI instruction is used to initialize the stack pointer in a relocatable module. The LOCATE pro-
gram provides an address for the special reserved label STACK.
LXI SP,STACK
3-35
Chapter 3. Instruction 5et
MOV MOVE
The MOV i n ~ tructlon moves one byte of data by copying the source field into the destination field. Source data
remains unchanged. The instruction's operands specify whether the move is from register to register, from a
register to m"mory, or from memory to a register.
Move Reglsur to Register
Opcode
MOV
Operand
regl,reg2
The instructi)n copies the contents of reg2 into regl. Each operand must specify one of the registers A, B, C, D,
E, H, or L.
When the sal ne register is specified for both operands (as in MOV A,A), the MOV functions as a NOP (no opera-
tion) since it has no other noticeable effect. This form of MOV requires one more machine state than NOP, and
therefore h a ~ a slightly longer execution time than NOP. Since M addresses a register pair rather than a byte of
data, MOV H,M is not allowed.
G D D Dis 5 51
Move to Men'lOry
Cycles:
States:
Addressing:
Flags:
Opcode
MOV
1
5 (4 on 8085)
register
none
Operand
M,r
This instruct ion copies the contents of the specified register Into the memory location addressed by the Hand L
registers. M s a symbolic reference to the Hand L register pair. The second operand must address one of the
registers.
1,--0 0Is 5 51
3-36
Move from .Vlemory
Cycles:
States:
Addressing:
Flags:
Opcode
MOV
2
7
register Indirect
none
Operand
r,M
Chapter 3. Instruction Set
This instruction copies the contents of the memory location addressed by the Hand L registers into the specified
register. The first operand must name the destination register. The second operand must be M. M is a symbolic
reference to the Hand L registers.
CID 0 °I 01
Examples:
Cycles:
States:
Addressing:
Flags:
2
7
register indirect
none
MVI
Label Opcode Operands
LDACC: MOV A,M
MOV E,A
NULOP: MOV C,C
Comment
;LOAD ACCUM FROM MEMORY
;COPY ACCUM INTO E REG
;NULL OPERATION
MOVE IMMEDIATE
MVI is a two-byte instruction; its second byte contains the source data to be moved. MVI moves one byte of
data by copying its second byte into the destination field. The instruction's operands specify whether the move
is to a register or to memory.
Move Immediate to Register
Opcode
MVI
Operand
reg,data
The first operand must name one of the registers A through E, H or L as a destination for the move.
The second operand specifies the actual data to be moved. This data may be in the form of a number, an ASCII
constant, the label of some previously defined value, or an expression. The data must not exceed one byte.
The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbols appears in the operand expression of an immediate instruction, it must be preceded by either the
HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression.
When neither operator is present, the assembler assumes the LOW operator and issues an error message.
data
Cycles:
States:
Addressing:
Flags:
2
7
immediate
none
3-37
Chapter 3. Instruction iet
Move Immediate to Memory
Opcode
MVI
Operand
M,data
This instruc:ion copies the data stored in its second byte into the memory location addressed by Hand L. M is
a symbolic eference to the Hand L register pair.
Examples:
o 0
Cycles:
States:
AddreSSing:
Flags:
o
data
o
3
10
Immediate/register indirect
none
The followilg examples show a number of methods for defining immediate data In the MVI instruction. All of
the exampk s generate the bit pattern for the ASCII character A.
NOP
MVI
MVI
MVI
MVI
MVI
MVI
M,01000001B
M:A'
M.41H
M,101Q
M,65
M,5+30*2
NO OPERATION
NOP perfor TIS no operation and affects none of the condition flags. NOP IS useful as filler in a timing loop.
Opcode
NOP
Operand
ORA
3-38
Operands al e not permitted with the NOP instruction.
INCLUSIVE OR WITH ACCUMULATOR
ORA perf01 ms an inclusive OR logical operation uSing the contents of the specified byte and the accumulator. The
result is pla:ed in the accumulator.
Chapter 3. Instruction Set
Summary of Logical Operations
AND produces a one bit in the result only when the corresponding bits in the test data and the mask data are
one.
OR produces a one bit in the result when the corresponding bits in either the test data or the mask data are
ones.
Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are
different; i.e., a one bit in either the test data or the mask data - but not both - produces a one bit in the
result.
AND
1010 1010
0000 1111
00001010
OR Register with Accumulator
Opcode
ORA
OR
1010 1010
0000 1111
1010 1111
Operand
reg
EXCLUSIVE OR
1010 1010
0000 1111
1010 0101
The operand must specify one of the registers A through E, H or L. This instruction ORs the contents of the
specified register and the accumulator and stores the result in the accumulator. The carry and auxiliary carry
flags are reset to zero.
o
Cycles:
States:
Addressing:
Flags:
OR Memory with Accumulator
Opcode
ORA
oIss S I
1
4
register
Z,S,P,CY,AC
Operand
M
The contents of the memory location specified by the Hand L registers are inciusive-oRed with the contents of
the accumulator. The result is stored in the accumulator. The carry and auxiliary carry flags are reset to zero.
o
Cycles:
States:
Addressing:
Flags:
o
2
7
register indirect
Z,S,P,CY,AC
3-39
Chapter 3. Instruction Set
Example:
Since any tit inciusive-ORed with a one produces a one and any bit ORed with a zero remains unchanged, ORA
is frequentl y used to set ON particular bits or groups of bits. The following example ensures that bit 3 of the
accumulator is set ON, but the remaining bits are not disturbed. This is frequently done when individual bits
are used as status flags in a program. Assume that register D contains the value OSH:
ORI
Accumulator
Register D
01000011
o 0 0 0 1 000
01001011
INCLUSIVE OR IMMEDIATE
ORI performs an inclusive OR logical operation using the contents of the second byte of the instruction and the
contents 01 the accumulator, The result is placed in the accumulator. ORI also resets the carry and auxiliary
carry flags to zero.
Opcode
ORI
Operand
data
The operar d must specify the data to be used In the inclusive OR operation. This data may be in the form of a
number, ar ASCII constant, the label of some previously defined value, or an expression. The data may not
exceed one byte.
The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbols appears in the operand expression of an immediate instruction, it must be preceded by either the
HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression.
When neitrer operator is present, the assembler assume the LOW operator and issues an error message.
Summary, If Logical Operations
Cycles:
States:
Addressing:
Flags:
o
data
o
2
7
immediate
Z,S,P,SY,AC
3-40
AND prod Jces a one bit in the result only when the corresponding bits in both the test data and the mask data
are ones.
OR prodU< es a one bit in the result when the corresponding bits in either the test data or the mask data are ones.
Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are
different; I.e., a one bit in either the test data or the mask data - but not both produces a one bit in the
result.
Example:
AND
1010 1010
00001111
00001010
OR
1010 1010
00001111
1010 1111
EXCLUSIVE OR
1010 1010
0000 1111
10100101
Chapter 3. Instruction Set
See the description of the ORA instruction for an example of the use of the inclusive OR. The following
examples show a number of methods for defining immediate data in the ORI instruction. All of the examples
generate the bit pattern for the ASCII character A.
OUT
ORI
ORI
ORI
ORI
ORI
ORI
01000001B
'A'
41H
101Q
65
5+30*2
OUTPUT TO PORT
The OUT instruction places the contents of the accumulator on the eight-bit data bus and the number of the
selected port on the sixteen-bit address bus. Since the number of ports ranges from 0 through 255, the port
number is duplicated on the address bus.
It is the responsibility of external logic to decode the port number and to accept the output data.
NOTE
Because a discussion of input/output structures is beyond the scope of
this manual, this description is restricted to the exact function of the
OUT instruction. Input/output structures are described in the 8080 or
8085 Microcomputer Systems User's Manual.
Opcode
OUT
Operand
exp
The operand must specify the number of the desired output port. This may be in the form of a number or an
expression in the range OOH through OFFH.
I
1 0 0 0
1 I
exp
Cycles: 3
States: 10
Addressing: direct
Flags: none
3·41
Chapter 3. Instruction Se:
PCHL MOVE H&L TO PROGRAM COUNTER
PCHL loads tle contents of the Hand L registers Into the program counter register. Because the processor
fetches the next instruction from the updated program counter address, PCHL has the effect of a iump instruc-
tion.
Opcode
PCHL
Operand
Operands are not permitted with the PCHL instruction.
PCHL moves the contents of the H register to the high-order eight bits of the program counter and the contents
of the L regHer to the low-order eight bits of the program counter.
The user p r o ' ~ r a m must ensure that the Hand L registers contain the address of an executable instruction when
the PCHL In: truction is executed.
Example:
Cycles:
States:
AddreSSing:
Flags:
o
o 0 1 I
1
5 (6 on 8085)
register
none
One techniqlle for passing data to a subroutine IS to place the data Immediately after the subroutine call. The
return addre, s pushed onto the stack by the CALL Instruction actually addresses the data rather than the next
instruction ater the CALL. For tillS example, assume that two bytes of data follow the subroutine call. The
following coding sequence performs a return to the next Instruction after the call:
POP
GOBACK: POP H
INR L
INR L
PCHL
;GET DATA ADDRESS
;ADD 2 TO FORM
;RETURN ADDRESS
;RETURN
POP
3-42
The POP ins:ruction removes two bytes of data from the stack and copies them to a register pair or copies the
Program Stttus Word into the accumulator and the condition flags.
POP Registe, Pair
POP copies: he contents of the memory location addressed by the stack pointer Into the low-order register of the
register pair POP then increments the stack pointer by one and copies the contents of the resulting address into
Chapter 3. Instruction Set
the high-order register of the pair. POP then increments the stack pointer again so that it addresses the next
older Item on the stack.
Opcode
POP
Operand
The operand may specify the B&C, D&E, or the H&L register pairs. POP PSW is explained separately.
~ R pi 0 0 0 11
POP PSW
Cycles:
States:
Addressing:
Flags:
3
10
register indirect
none
POP PSW uses the contents of the memory location specified by the stack pointer to restore the condition flags.
POP PSW increments the stack pointer by one and restores the contents of that address to the accumulator.
POP then increments the stack pointer again so that it addresses the next older item on the stack.
Example:
Cycles:
States:
Addressing:
Flags:
3
10
register Indirect
Z,S,P,CY,AC
Assume that a subroutine is called because of an external interrupt. In general, such subroutines should save and
restore any registers it uses so that main program can continue normally when it regains control. The following
sequence of PUSH and POP instructions save and restore the Program Status Word and all the registers:
343
Chapter 3. Instruction :,et
PUSH PSW
PUSH B
PUSH D
PUSH H
subroutine coding
POP H
POP D
POP B
POP PSW
RET
Notice that the sequence of the POP instructions is the opposite of the PUSH instruction sequence.
PUSH PUSH
The PUSH ilstruction copies two bytes of data to the stack. This data may be the contents of a register pair or
the Progran Status Word. as explained below:
PUSH Regis'er Pair
PUSH decrements the stack pointer register by one and copies the contents of the high-order register of the
register pair to the resulting address. PUSH then decrements the pointer again and copies the low-order register
to the resuh ing address. The source registers remain unchanged.
Opcode
PUSH
Operand
{U
The operand may specify the B&C. D&E. or H&L register pairs. PUSH PSW is explained separately.
Example:
Cycles:
States:
Addressi ng:
Flags:
3
11 (13 on 8085)
register indirect
none
344
Assume tha: register B contains 2AH. the C register contains 4CH, and the stack pOinter is set at 9AAF. The
instruction'USH B stores the B register at memory address 9AAEH and the C register at 9AADH. The stack
pointer is st:t to 9AADH:
Chapter 3. Instruction Set
Stack Stack
Before PUSH Address After PUSH
SP before .. xx 9AAF xx
xx 9AAE 2A
xx 9AAD 4C .. SP after
xx 9AAC xx
PUSH PSW
PUSH PSW copies the Program Status Word onto the stack. The Program Status Word comprises the contents
of the accumulator and the current settings of the condition flags. Because there are only five condition flags,
PUSH PSW formats the flags Into an eight-bit byte as follows:
7 6 5 4 3
~ A C 0
2
P
o
I CY I
On the 8080, bits 3 and 5 are always zero; bit one is always set to one. These filler bits are undefined on the
8085.
PUSH PSW decrements the stack pointer by one and copies the contents of the accumulator to the resulting
address. PUSH PSW again decrements the pointer and copies the formatted condition flag byte to the resulting
address. The contents of the accumulator and the condition flags remain unchanged.
o
Example:
Cycles:
States:
Addressing:
Flags:
3
11 (120n8085)
register indirect
none
RAL
When a program calls subroutines, it is frequently necessary to preserve the current program status so the calling
program can continue normally when it regains control. Typically, the subroutine performs a PUSH PSW prior to
execution of any instruction that might alter the contents of the accumulator or the condition flag settings.
The subroutine then restores the pre-call system status by executing a POP PSW instruction just before returning
control to the calling program.
ROTATE LEFT THROUGH CARRY
RAL rotates the contents of the accumulator and the carry flag one bit position to the left. The carry flag, which
is treated as though it were part of the accumulator, transfers to the low-order bit of the accumulator. The high-
order bit of the accumulator transfers into the carry flag.
Opcode
RAL
Operand
Operands are not permitted with the RAL instruction.
345
Chapter 3. Instruction S"t
Example:
10 0 0
Cycles:
States:
Flags:
o
1
4
CYonly
Assume that the accumulator contains the value OAAH and the carry flag is zero. The following diagrams illus-
trate the eff, ct of the RAL instruction:
Before Carry
o}--------..,
Accumulator
o o o o
RAR
After:
1
0
Carry
DJ
Accumulator
0 0 0
01
ROTATE RIGHT THROUGH CARRY
RAR r o t a t e ~ the contents of the accumulator and the carry flag one bit position to the right. The carry flag,
which is tre2ted as though it were part of the accumulator. transfers to the high-order bit of the accumulator.
The low-ord"r bit of the accumulator transfers into the carry flag.
Opcode
RAR
Operand
Operands an' not permitted with the RAR instruction.
10 0 0
3-46
Cycles:
States:
Flags:
1
4
CYonly
Chapter 3. Instruction Set
Example:
Assume that the accumulator contains the value OAAH and the carry flag is zero. The following diagrams illus-
trate the effect of the RAR instruction:
Before:
After:
Carry
0
Accumulator
0 0 0 0
Carry
~
Accumulator
1
0
0 0 0
1 I
RC RETURN IF CARRY
The RC instruction tests the carry flag. If the flag is set to one to indicate a carry. the instruction pops two
bytes off the stack and places them in the program counter. Program execution resumes at the new address in
the program counter. If the flag is zero, program execution simply continues with the next sequential instruction.
Opcode
RC
Operand
Operands are not permitted with the RC instruction.
o
o 0 0 I
Example:
Cycles:
States:
Addressing:
Flags:
1 or 3
5 or 11 (6 or 12 on 8085)
register indirect
none
For the sake of brevity. an example is given for the RET instruction but not for each of its closely related
variants.
347
Chapter 3. Instruction Set
RET RETURN FROM SUBROUTINE
The RET irstruction pops two bytes of data off the stack and places them In the program counter register.
Program ex,:cution resumes at the new address In the program counter.
Typically, I:ET instructions are used in conjunction with CALL instructions. (The same IS true of the variants
of these instructions.) In this case, it IS assumed that the data the RET instruction pops off the stack is a
return addr:ss placed there by a previous CALL. This has the effect of returning control to the next Instruction
after the CILL. The user must be certain that the RET instruction finds the address of executable code on the
stack. If th,' instruction finds the address of data, the processor attempts to execute the data as though it were
code.
Opcode
RET
Operand
Operands a'e not permitted with the RET Instruction.
o 0 o 0
Example:
Cycles:
States:
Addressing:
Flags:
3
10
register indirect
none
As mentior ed previously, subroutines can be nested. That is, a subroutine can call a subroutine that calls
another sul,routine. The only practical limit on the number of nested calls is the amount of memory available
for stackin:; return addresses. A nested subroutine can even call the subroutine that called it, as shown In the
follOWing example. (Notice that the program must contain logic that eventually returns control to the main
program. Ctherwlse, the two subroutines will call each other indefinitely.)
MAlt1 PROGRAM
1 SUBA r-- SUBB 1
~ ~ - - - C A L L S U B A
CI\LL SUBA CNZ S U B ~ T
T T - RET
RET ....
RIM (8085 PRO::ESSOR ONLY) READ INTERRUPT MASK
The RIM ilstruction loads eight bits of data into the accumulator. The resulting bit pattern indicates the current
setting of . he interrupt mask, the setting of the interrupt flag, pending interrupts, and one bit of serial input data,
if any.
348
Opcode
RIM
Operand
Chapter 3. Instruction Set
Operands are not permitted with the RIM instruction.
The RIM instruction loads the accumulator with the following information:
I 7
6 5 4 3 2 1 0
I SID 17 16 15 IE 7.5 6.5 5.5
"--v-' "---v---" V '---v----"
L
I LInterrupt Masks:
Llnterrupt Enable Flag:
Pending Interrupts: 1 =pending
'----Serial Input Data Bit. if any
1 = masked
= enabled
RLC
The mask and pending flags refer only to the RST5.5, RST6.5, and RST7.5 hardware interrupts. The IE flag
refers to the entire interrupt system. Thus, the IE flag is identical in function and level to the INTE pin on the
8080. A 1 bit in this flag indicates that the entire interrupt system is enabled.
1
0 0 0 0 0 0
01
Cycles: 1
States: 4
Flags: none
ROTATE ACCUMULATOR LEFT
RLC sets the carry flag equal to the high-order bit of the accumulator, thus overwriting its previous setting. RLC
then rotates the contents of the accumulator one bit position to the left with the high-order bit transferring to
the low-order position of the accumulator.
Opcode
RLC
Operand
Operands are not allowed with the RLC instruction.
10 0 0 0 0
Cycles:
States:
Flags:
1
4
CYonly
349
Chapter 3. Instruction S,t
Example:
Assume that tne accumulator contains the value OAAH and the carry flag is zero. The following diagrams illus-
trate the effect of the RLC instruction.
Before:
After:
Carry
0
Accumulator
0 0 0 0
Carry
Q
Accumulator
1
0 0 0 0
1[
RM RETURN IF MINUS
The RM instr Jction tests the sign flag. If the flag is set to one to indicate negative data in the accumulator, the
instruction pcps two bytes off the stack and places them in the program counter, Program execution resumes at
the new addr,'ss In the program counter. If the flag is set to zero, program execution simply continues with the
next sequentlll instruction.
Opcode
RM
Operand
Operands are not permitted with the RM instruction.
o 0 01
Example:
Cycles:
States:
Addressing:
Flags:
1 or 3
5 or 11 (6 or 12 on 8085)
register indirect
none
3-50
For the sake of brevity, an example is given for the RET instruction but not for each of its closely related
variants.
RNC
Chapter 3. Instruction Set
RETURN IF NO CARRY
The RNC instruction tests the carry flag. If the flag is set to zero to indicate that there has been no carry, the
instruction pops two bytes off the stack and places them in the program counter. Program execution resumes at
the new address in the program counter. If the flag is one, program execution simply continues with the next
sequential instruction.
Opcode
RNC
Operand
Operands are not permitted with the RNC instruction.
Example:
a
Cycles:
States:
Addressing:
Flags:
a a a 01
1 or 3
5 or 11 (6 or 12 on 8085)
register indirect
none
RNZ
For the sake of breVity. an example is given for the RET instruction but not for each of its closely related
variants.
RETURN IF NOT ZERO
The RNZ instruction tests the zero flag. If the flag is set to zero to indicate that the contents of the accumulator
are other than zero. the instruction pops two bytes off the stack and places them in the program counter. Pro-
gram execution resumes at the new address in the program counter. If the flag is set to one. program execution
simply continues with the next sequential instruction.
Opcode
RNZ
Operand
Operands are not permitted with the RNZ instruction.
11 a a a a a 01
Example:
Cycles:
States:
Addressing:
Flags:
1 or 3
501'11 (601' 12 on 8085)
register indirect
none
For the sake of brevity. an example IS given for the RET instruction but not for each of its closely related
variants.
3-51
Chapter 3. Instruction S"t
RP RETURN IF POSITIVE
The RP instnlction tests the sign flag. If the flag is reset to zero to indicate positive data in the accumulator,
the instruction pops two bytes off the stack and places them in the program counter. Program execution
resumes at the new address in the program counter. If the flag is set to one, program execution simply continues
with the next sequential instruction.
Opcode
RP
Operand
Operands are not permitted with the RP instruction.
o 0 0 01
Example:
Cycles:
States:
Addressing:
Flags:
1 or 3
5 or 11 (6 or 12 on 8085)
register indirect
none
RPE
For the sake of brevity, an example is given for the RET instruction but not for each of its closely related
variants.
RETURN IF PARITY EVEN
Parity is ever if the byte in the accumulator has an even number of one bits. The parity flag IS set to one to
indicate this ;ondition. The RPE and RPO instructions are useful for testing the parity of input data. However,
the IN instru;tion does not set any of the condition flags. The flags can be set without altering the data by
adding OOH to the contents of the accumulator.
The RPE ins', ruction tests the parity flag. If the flag is set to one to indicate even parity, the instruction pops
two bytes of' the stack and places them in the program counter. Program execution resumes at the new address
in the program counter. If the flag IS zero. program execution simply continues with the next sequential instruc-
tion.
Opcode
RPE
Operand
Operands are not permitted with the RPE instruction.
o
o 0 01
3-52
Cycles:
States:
Addressing:
Flags:
1 or 3
5 or 11 (6 or 12 on 8085)
register indirect
none
RPO
Chapter 3. Instruction Set
Example:
For the sake of brevity, an example IS given for the RET instruction but not for each of its closely related
variants.
RETURN IF PARITY ODD
Parity is odd if the byte in the accumulator has an odd number of one bits. The parity flag is reset to zero to
indicate this condition. The RPO and RPE instructions are useful for testing the parity of input data. However,
the IN instruction does not set any of the condition flags. The flags can be set without altering the data by
adding OOH to the contents of the accumulator.
The RPO instruction tests the parity flag. If the flag is reset to zero to indicate odd parity, the instruction pops
two bytes off the stack and places them in the program counter. Program execution resumes at the new address
in the program counter. If the flag is set to one, program execution simply continues with the next sequential
instruction.
Opcode
RPO
Operand
Operands are not permitted with the RPO instruction.
o 0 0 0 01
Example:
Cycles:
States:
Addressing:
Flags:
1 or 3
5 or 11 (6 or 12 on 8085)
register Indirect
none
RRC
For the sake of brevity, an example is given for the RET instruction but not for each of its closely related
variants.
ROTATE ACCUMULATOR RIGHT
RRC sets the carry flag equal to the low-order bit of the accumulator, thus overwriting its previous setting. RRC
then rotates the contents of the accumulator one bit position to the right with the low-order bit transferring to
the high order position of the accumulator.
Opcode
RRC
Operand
Operands are not permitted with the RRC instruction.
3-53
Chapter 3. Instruction Set
10 0 0 0
Example:
Cycles:
States:
Flags:
4
CYonly
Assume that the accumulator contains the value OAAH and the carry flag is zero. The folloving diagrams illus-
trate the effect of the RRC instruction:
Before:
After:
Carry
G
Accumulator
0 0 0
Carry
G
Accumulator
1
0 0 0 0
1\
RST
3-54
RESTART
RST IS a special purpose CALL instruction designed primarily for use with interrupts. RST !,ushes the contents
of the program counter onto the stack to provide a return address and then Jumps to one 0 eight predetermined
addresses. A three-bit code carried in the opcode of the RST instruction specifies the Jump ,Iddress.
The restart instruction IS unique because it seldom appears as source code 111 an applications program. More often,
the peripheral devices seekll1g interrupt service pass this one-byte instruction to the processcr,
When a deVice requests interrupt service and lI1terrupts are enabled, the processor acknowlecges the request and
prepares its data lines to accept anyone-byte instruction from the deVice. RST is generally he instruction of
chOice because its special purpose CALL establishes a return to the main program.
The processor moves the three-bit address code from the RST instruction into bits 3, 4, ane 5 of the program
counter. In effect, this multiplies the code by eight. Program execution resumes at the new address where eight
bytes are available for code to service the interrupt. If eight bytes are too few, the program can either Jump to
or call a subroutine.
Chapter 3. Instruction Set
8085 NOTE
The 8085 processor Includes four hardware inputs that generate internal RST
instructions. Rather than send a RST instruction, the interrupting device need
only apply a signal to the RST5.5, RST6.5, RST7.5, or TRAP input pin.
The processor then generates an internal RST instruction. The execution
depends on the input:
INPUT RESTART
NAME ADDRESS
TRAP 24H
RST5.5 2CH
RST6.5 34H
RSn.5 3CH
Notice that these addresses are within the same portion of memory used by the RST instruction, and therefore
allow only four bytes - enough for a call or jump and a return for the interrupt service routine.
If Included in the program code, the RST instruction has the following format:
Opcode
RST
Operand
code
The address code must be a number or expreSSion within the range 0008 through 1118.
Progrdm
Counter
After RST
11
I
C C
r
I
1
11
'"
~
- - ~
15 14 13 12 11 10 9 8 7 6 5 4 3 2 0
10
0 0 0 0 0 0 0 0 0 C C C 0 0
01
RZ
Cycles:
States:
Addressing:
Flags:
3
11 (12 on 8085)
register indirect
none
RETURN IF ZERO
The RZ instruction tests the zero flag. If the flag IS set to one to indicate that the contents of the accumulator are
zero, the instruction pops two bytes of data off the stack and places them in the program counter. Program
execution resumes at the new address in the program counter. If the flag is zero, program execution simply
continues with the next sequential instruction.
3-55
Chapter 3. Instruction Se
Gpcode
RZ
Operand
Operands are not permitted with the RZ instruction.
o 0
Cycles:
States:
Addressing:
Flags:
Example:
o 0 01
1 or 3
5 or 11 (6 or 12 on 8085)
register indirect
none
SBB
For the sake of brevity. an example is given for the RET instruction but oot for each of its closely related
variants.
SUBTRACT WITH BORROW
SBB subtracts one byte of data and the setting of the carry flag from the contents of the accumulator. The
result is stored in the accumulator. SBB then updates the setting of the carry flag to indicate the outcome of
the operation
SBB's use of he carry flag enables the program to subtract nulti-byte strings. SBB incorporates the carry flag by
adding it to tile byte to be subtracted from the accumulator. It then subtracts the result from the accumulator
by using two', complement addition. These preliminary operations occur in the processor's internal work registers
so that the SOJrce data remains unchanged.
Subtract Regl.'ter from Accumulator with Borrow
Opcode
SBB
Operand
reg
The operand nust specify one of the registers A through E, H or L. This instruction subtracts the contents of
the specified I egister and the carry flag from the accumulator and stores the result in the accumulator.
3-56
11 0 0
Cycles:
States:
Addressing:
Flags:
S 5 S I
1
4
register
Z,S,P,CY,AC
Chapter 3. Instruction Set
Subtract Memory from Accumulator with Borrow
Opcode
SBB
Operand
M
This instruction subtracts the carry flag and the contents of the memory location addressed by the Hand L
registers from the accumulator and stores the result in the accumulator.
Example:
Cycles:
States:
Addressing:
Flags:
2
7
register indirect
Z,S,P,CY,AC
Assume that register B contains 2, the accumulator contains 4, and the carry flag is set to 1. The instruction
SBB B operates as follows:
2H + carry = 3H
2's complement of 3H =11111101
Accumulator = 00000100
11111101
00000001 = 1H
Notice that this two's complement addition produces a carry. When SBB complements the carry bit generated
by the addition, the carry flag is reset OFF. The flag settings resulting from the SBB B instruction are as
follows:
SBI
Carry
Sign
Zero
Parity
Aux. Carry
o
o
o
o
1
SUBTRACT IMMEDIATE WITH BORROW
SBI subtracts the contents of the second Instruction byte and the setting of the carry flag from the contents of
the accumulator. The result is stored in the accumulator.
SBI's use of the carry flag enables the program to subtract multi-byte strings. SBI incorporates the carry flag by
adding it to the byte to be subtracted from the accumulator. It then subtracts the result from the accumulator
by using two's complement addition. These preliminary operations occur In the processor's internal work registers
so that the immediate source data remains unchanged.
3-57
Chapter 3. Instruction Se
The assembler s relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbols appears in the operand expression of an immediate instruction, it must be preceded by either the
HIGH or LOlA operator to specify which byte of the address is to be used in the evaluation of the expression.
When neither cJperator is present, the assembler assumes the LOW operator and issues an error message.
Opcode
5BI
Operand
data
The operand must specify the data to be subtracted. This data may be in the form of a number, an ASCII
constant, the Iabel of some perviously defined value, or an expression. The data may not exceed one byte.
Example:
o
Cycles:
States:
Addressing:
Flags:
01
2
7
immediate
Z,5,P,CY.AC
SHLD
The following sequence of instructions enables the program to test the setting of the carry flag:
XRA A
5BI 1
The exclusive OR with the accumulator clears the accumulator to zeros but does not affect the setting of the
carry flag. (Tfe XRA instruction is explained later in this chapter.) When the carry flag is OFF, 5BI 1 yields
a minUS one. Nhen the flag is set ON, 5BI 1 yields a minus two.
NOTE
This example is included for illustrative purposes. In most
cases, the carry flag can be tested more efficiently by using
the JNC instruction (jump if no carry).
STORE HAND L DIRECT
5HLD stores l copy of the L register in the memory location specified in bytes two and three of the SHLD
Instruction. 5-lLD then stores a copy of the H register in the next higher memory location.
Opcode
SHLD
Operand
address
3·58
The address may be stated as a number, a previously defined label. or an expression.
Chapter 3. Instruction Set
SHLD is one of the instructions provided for saving the contents of the Hand L registers. Alternately, the H
and L data can be placed in the D and E registers (XCHG instruction) or placed on the stack (PUSH and XTHL
instructions).
0 0 1 0 0 0 1 0
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
5
16
direct
none
Assume that the Hand L registers contain OAEH and 29H, respectively, The following is an illustration of the
effect of the SHLD lOAH instruction:
Memory Before SHLD
Memory After SH LD
SIM (8085 PROCESSOR ONLY)
MEMORY ADDRESS
109 lOA lOB 10C
00 00 00 00
00 29 AE 00
SET INTERRUPT MASK
SI M is a multi-purpose instruction that uses the current contents of the accumulator to perform the following
functions: Set the interrupt mask for the 8085's RST5.5, RST6.5, and RST7.5 hardware interrupts: reset
RST7.5's edge sensitive input; and output bit 7 of the accumulator to the Serial Output Data latch.
Opcode
SIM
Operand
Operands are not permitted with the SIM instruction. However, you must be certain to load the desired bit
configurations into the accumulator before executing the SIM instruction. SIM interprets the bits in the accumu-
lator as follows:
]-59
Chapter 3. Instruction Set
{
o = available
1 = masked
ignored
If 1, bit 7 is output to Serial Output Data Latch
Serial Output Data: ignored if bit 6 = 0
Accumulator :,its 3 and 6 function as enable switches. If bit 3 IS set ON (set to 1), the set mask function is
enabled. Bits (J through 2 then mask or leave available the corresponding RST interrupt. A 1 bit masks the
interrupt mak ng It unavailable; a 0 bit leaves the interrupt available. If bit 3 is set OFF (reset to 0), bits 0
through 2 h a v ~ no effect. Use this option when you want to send a serial output bit without affecting the
interrupt mas!..
Notice that the DI (Disable Interrupts) instruction overrides the SIM instruction. Whether masked or not, RST5.5,
RST6.5, and IlST7.5 are disabled when the DI instruction IS in effect. Use the RIM (Read Interrupt Mask)
instruction to determine the current settings of the interrupt flag and the interrupt masks.
If bit 6 is set to 1, the serial output data function is enabled. The processor latches accumulator bit 7 into the
SOD output v'here it can be accessed by a peripheral device. If bit 6 IS reset to 0, bit 7 IS ignored.
A 1 in accumiJlator bit 4 resets OFF the RST7.5 input flip flop. Unlike RST5.5 and 6.5, RST7.5 IS sensed via a
processor flip flop that is set when a peripheral device Issues a pulse with a rising edge. This edge triggered Input
supports devices that cannot maintain an interrupt request until serviced. RST7.5 is also useful when a device
does not requ re any explicit hardware service for each interrupt. For example, the program might increment and
test an event ,:ounter for each interrupt rather than service the device directly.
The RST7.5 f ip flop remains set until reset by 1) Issuing a RESET to the 8085, 2) recognizing the interrupt, or
3) setting accLmulator bit 4 and executing a SIM instruction. The Reset RST7.5 feature of the SIM instruction
allows the pre gram to override the interrupt.
The RST7.5 Illput flip flop is not affected by the setting of the interrupt mask or the DI instruction and there-
fore can be set at any time. However, the interrupt cannot be serviced when RST7.5 is masked or a DI instruction
is in effect.
1
0 0 0 0 0
01
Cycles: 1
States: 4
Flags: none
Example 1: <\ssume that the accumulator contains the bit pattern 00011100. The SIM instruction resets the
RST7.5 flip fl)p and sets the RST7.5 interrupt mask. If an RSn.5 interrupt is pending when this SIM instruction
is executed, it is overridden without being serviced. Also, any subsequent RST7.5 Interrupt is masked and cannot
be serviced urtil the interrupt mask is reset.
3-60
SPHL
Chapter 3. Instruction Set
Example 2: Assume that the accumulator contains the bit pattern 11001111. The 51 M instruction masks out the
R5T5.5, R5T6.5, and R5T7.5 level interrupts and latches a 1 bit into the SOD input. By contrast, the bit pattern
10000111 has no effect since the enable bits 3 and 6 are not set to ones.
MOVE H&L TO SP
5PHL loads the contents of the Hand L registers into the SP (Stack Pointer) register.
Opcode
SPHL
Operand
Operands are not permitted with the SPHL instruction.
SP is a special purpose 16·bit register used to address the stack; the stack must be in random access memory
(RAM). Because different applications use different memory configurations, the user program must load the SP
register with the stack's beginning address. The stack is usually assigned to the highest available location in RAM.
The hardware decrements the stack pointer as items are added to the stack and increments the pointer as items
are removed.
The stack pointer must be initialized before any instruction attempts to access the stack. Typically, stack
initialization occurs very early in the program. Once established, the stack pointer should be altered with
caution. Arbitrary use of 5PHL can cause the loss of stack data.
Example:
Cycles:
States:
Addressing:
Flags:
1
5 (6 on 8085)
register
none
STA
Assume that the Hand L registers contain SOH and OFFH, respectively. SPHL loads the stack pointer with the
value 50FFH.
STORE ACCUMULATOR DIRECT
STA stores a copy of the current accumulator contents into the memory location specified in bytes two and
three of the STA instruction.
Opcode
STA
Operand
address
The address may be stated as a number, a previously defined label, or an expression. The assembler inverts the
high and low address bytes when it builds the instruction.
3-61
Chapter 3. Instruction Se.
0 0 1 1 0 0 1 0
lowaddr
high addr
Example:
Cycles:
States:
Addressing:
Flags:
4
13
direct
none
STAX
The following instruction stores a copy of the contents of the accumulator at memory location SB3H:
STA SB3H
When assembl( d. the previous instruction has the hexadecimal value 32 B3 05. Notice that the assembler inverts
the high and I'lw order address bytes for proper storage in memory.
STORE ACCUMULATOR INDIRECT
The STAX ins :ruction stores a copy of the contents of the accumulator into the memory location addressed
by register pai B or register pair D.
Opcode
STAX
Operand
The operand E specifies the Band C register pair; D specifies the D and E register pair. This instruction may
specify only tie B or D register pair.
10 0 oeJo 0 01
'-...,-/
If0 = register pair B
II = register pair D
Example:
CYcles:
States:
Addressing:
Flags:
2
7
register Indirect
none
3-62
If register B c<.ntains 3FH and register C contains 16H. the following instruction stores a copy of the contents
of the accumuiator at memory location 3F16H:
STAX B
STC
Chapter 3. Instruction Set
SET CARRY
STC sets the carry flag to one. No other flags are affected.
Opcode
STC
Operand
Operands are not permitted with the STC instruction.
10 0
Cycles:
States:
Flags:
o
1
4
CY
SUB
When used in combination with the rotate accumulator through the carry flag instructions, STC allows the pro-
gram to modify individual bits.
SUBTRACT
The SUB instruction subtracts one byte of data from the contents of the accumulator. The result IS stored in the
accumulator, SUB uses two's complement representation of data as explained in Chapter 2. Notice that the SUB
Instruction excludes the carry flag (actually a 'borrow' flag for the purposes of subtraction) but sets the flag to
indicate the outcome of the operation.
Subtract Register from Accumulator
Opcode
SUB
Operand
reg
The operands must specify one of the registers A through E, H or L. The instruction subtracts the contents of
the specified register from the contents of the accumulator using two's complement data representation. The
result is stored in the accumulator,
Cycles:
States:
Addressing:
Flags:
Subtract Memory from Accumulator
Opcode
SUB
oIss SI
1
4
register
Z.S,P,CY,AC
Operand
M
3-63
Chapter 3. Instruction Se
This instruction subtracts the contents of the memory location addressed by the Hand L registers from the
contents of th ~ accumulator and stores the result in the accumulator. M is a symbolic reference to the Hand L
registers.
Example:
Cycles:
States:
Addressing:
Flags:
o
01
2
7
register indirect
Z,S,P,CY,AC
Assume that tne accumulator contains 3EH. The instruction SUB A subtracts the contents of the accumulator
from the accumulator and produces a result of zero as follows:
3EH
+(-3EH)
carry out =1
00111110
11000001
1
00000000
one's complement
add one to produce two's complement
result =0
SUI
The conditior flags are set as follows:
Carry 0
Sign 0
Zero 1
Parity 1
Aux. Carry 1
Notice that the SUB instruction complements the carry generated by the two's complement addition to form a
'borrow' flag. The auxiliary carry flag is set because the particular value used in this example causes a carry out
of bit 3.
SUBTRACT IMMEDIATE
SU I subtracts the contents of the second instruction byte from the contents of the accumulator and stores the
result in the •.ccumulator. Notice that the SUI instruction disregards the carry ('borrow') flag during the sub-
traction but ,ets the flag to Indicate the outcome ofthe operation.
Opcode
SUI
Operand
data
3-64
The operand must specify the data to be subtracted. This data may be in the form of a number, an ASCII
constant, the label of some previously defined value, or an expression. The data must not exceed one byte.
The assemble "s relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbol. appears in the operand expression of an immediate instruction, it must be preceded by either the
Chapter 3. Instruction Set
HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression.
When neither operator is present, the assembler assumes the LOW operator and issues an error message.
Example:
a
Cycles:
States:
Addressing:
Flags:
a
01
2
7
immediate
Z,S,P,CY,AC
Assume that the accumulator contains the value 9 when the instruction SUI 1 is executed:
Accumulator
Immediate data (2's comp)
00001001 = 9H
11111111 = -1 H
00001000 = 8H
Notice that this two's complement addition results in a carry, The SUI instruction complements the carry
generated by the addition to form a 'borrow' flag. The flag settings resulting from this operation are as follows:
XCHG
Carry
Sign
Zero
Parity
Aux. Carry
a
a
a
a
1
EXCHANGE HAND L WITH D AND E
XCHG exchanges the contents of the Hand L registers with the contents of the D and E registers.
Opcode
XCHG
Operand
Operands are not allowed with the XCHG instruction.
XCHG both saves the current Hand L and loads a new address into the Hand L registers. Since XCHG is a
register-to-register instruction, it provides the quickest means of saving and/or altering the Hand L registers.
Cycles:
States:
Addressing:
Flags:
a a
1
4
register
none
3-65
Chapter 3. Instruction Set
Example:
Assume that the Hand L registers contain 1234H, and the D and E registers contain OABCDH. Following
execution of tre XCHG instruction, Hand L contain OABCDH, and D and E contain 1234H.
XRA EXCLUSIVE OR WITH ACCUMULATOR
XRA performs an exclusive OR logical operation using the contents of the specified byte and the accumulator,
The result IS pi Iced in the accumulator,
Summary of Lugical Operations
AND produces a one bit in the result only when the corresponding bits in the test data and the mask data are
ones.
OR produces a one bit in the result when the corresponding bits In either the test data or the mask data are
ones.
Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are
different; i.e., 2 one bit in either the test data or the mask data - but not both - produces a one bit in the
resul t.
AND
1010 1010
0000 1111
0000 1010
XRA Register ,lith Accumulator
Opcode
XRA
OR
1010 1010
0000 1111
10101111
Operand
reg
EXCLUSIVE OR
1010 1010
0000 1111
1010 0101
The operand mJst specify one of the registers A through E, H or L. This instruction performs an exclUSive OR
using the contelts of the specified register and the accumulator and stores the result In the accumulator. The
carry and auxil ary carry flags are reset to zero.
3-66
a
Cycles:
States:
AddreSSing:
Flags:
a S S S
1
4
register
Z,S,P,CY,AC
Chapter 3. Instruction Set
XRA Memory with Accumulator
Opcode
XRA
Operand
M
The contents of the memory location specified by the Hand L registers is exclusive-ORed with the contents of
the accumulator. The result is stored in the accumulator. The carry and auxiliary carry flags are reset to zero.
Examples:
o
Cycles:
States:
Addressing:
Flags:
o
o ,
2
7
register indirect
Z,S,P,CY,AC
XRI
Since any bit exclusive-0Red with itself produces zero, XRA is frequently used to zero the accumulator. The
following instructions zero the accumulator and the Band C registers.
XRA A
MOV B,A
MOV C,A
Any bit exclusive-ORed with a one bit is complemented. Thus, if the accumulator contains all ones (OFFH),
the instruction XRA B produces the one's complement of the B register in the accumulator.
EXCLUSIVE OR IMMEDIATE WITH ACCUMULATOR
XRI performs an exclusive OR operation using the contents of the second instruction byte and the contents of
the accumulator. The result is placed in the accumulator. XRI also resets the carry and auxiliary carry flags to
zero.
Opcode
XRI
Operand
data
The operand must specify the data to be used in the OR operation. This data may be in the form of a number,
an ASCII constant, the label of some previously defined value, or an expression. The data may not exceed one
byte.
The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these symbols appears in the operand expression of an immediate instruction, it must be preceded by either the
HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression.
When neither operator IS present, the assembler assumes the LOW operator and issues an error message.
3-67
Chapter 3. Instruction Se',
Summary of LJgica/ Operations
Cycles:
States:
Addressing:
Flags:
o
data
o
2
7
immediate
Z,S,P,CY,AC
AND a one bit in the result only when the corresponding bits in the test data and the mask data are
ones.
OR produces, one bit in the result when the corresponding bits in either the test data or the mask data are
ones.
Exclusive OR Jroduces a one bit only when the corresponding bits in the test data and the mask data are
different; i.e., a one bit in either the test data or the mask data - but not both - produces a one bit in the
result.
Example:
AND
1010 1010
0000 1111
00001010
OR
1010 1010
0000 1111
1010 1111
EXCLUSIVE OR
1010 1010
0000 1111
1010 0101
Assume that a program uses bits 7 and 6 of a byte as flags that control the calling of two subroutines. The
program tests the bits by rotating the contents of the accumulator until the desired bit is in the carry flag; a
CC instructior (Call if Carry) tests the flag and calls the subroutine if required.
Assume that tle control flag byte is positioned normally In the accumulator, and the program must set OFF bit
6 and set bit " ON. The remaining bits, which are status flags used for other purposes, must not be altered.
Since any bit with a one is complemented, and any bit exclusive-oRed with a zero remains
unchanged, following Instruction is used:
3-68
XRI
The Instruction has the follOWing results:
Accumulator
Immediate data
110000008
01001100
11000000
10001100
XTHL
Chapter 3. Instruction Set
EXCHANGE H&L WITH TOP OF STACK
XTHL exchanges two bytes from the top of the stack with the two bytes stored in the Hand L registers. Thus,
XTHL both saves the current contents of the Hand L registers and loads new values into Hand L.
Opcode
XTHL
Operand
Operands are not allowed with the XTHL instruction.
XTHL exchanges the contents of the L register with the contents of the memory location specified by the SP
(Stack Pointer) register. The contents of the H register are exchanged with the contents of SP+1.
000 1 I
Example: •
Cycles:
States:
Addressing:
Flags:
5
18 (16 on 8085)
register indirect
none
Assume that the stack pOinter register contains 10ADH; register H contains OBH and L contains 3CH; and
memory locations 10ADH and 10AEH contain FOH and ODH, respectively. The following is an illustration of
the effect of the XTHL instruction:
Before XTHL
After XTHL
MEMORY ADDRESS
lOAC lOAD 10AE lOAF
FF Fa aD FF
FF 3C OB FF
H L
OB 3C
aD Fa
The stack pointer register remains unchanged following execution of the XTHL instruction.
3 ~ 9
4. ASSEMBLER DIRECTIVES
This chapter describes the assembler directives used to control the 8080/85 assembler in its generation of object
code. This chapter excludes the macro directives, which are discussed as a separate topic in Chapter 5.
Generally, directives have the same format as instructions and can be interspersed throughout your program.
Assembler directives discussed in this chapter are grouped as follows:
GENERAL DIRECTIVES:
• Symbol Definition
EQU
SET
• Data Definition
DB
DW
• Memory Reservation
DS
• Conditional Assembly
IF
ELSE
ENDIF
• Assembler Termination
END
LOCATION COUNTER CONTROL AND RELOCATION:
• Location Counter Control
ASEG
DSEG
CSEG
ORG
• Program Linkage
PUBLIC
EXTRN
NAME
STKLN
4-1
Chapter 4. Assembler Oir ,ctives
Three assembl" directives - EQU, SET, and MACRO - have a slightly different format from assembly
language instnlctions. The EQU, SET. and MACRO directives require a name for the symbol or macro being
defined to be present in the label field. Names differ from labels in that they must not be terminated with a
colon (:) as laJels are. Also, the LOCAL and ENDM directives prohibit the use of the label field.
The MACRO, ENDM, and LOCAL directives are explained in Chapter 5.
SYMBOL DEFINITION
The assembler automatically assigns values to symbols that appear as instruction labels. This value IS the current
setting of the location counter when the instruction IS assembled. (The location counters are explained under
'Address Cont'ol and Relocation,' later in this chapter.)
You may defile other symbols and assign them values by using the EQU and SET directives. Symbols defined
using EQU callnot be redefined during assembly; those defined by SET can be assigned new values by subsequent
SET
The name req Jired in the label field of an EQU or SET directive must not be terminated with a colon.
Symbols defined by EQU and SET have meaning throughout the remainder of the program. This may cause the
symbol to have illegal multiple definitions when the EQU or SET directive appears in a macro definition. Use
the LOCAL d rective (described in Chapter 5) to avoid this problem.
EQU Directive
EQU assigns t le value of 'expression' to the name specified in the label field.
Label
name
Opcode
EQU
Operand
expression
The required lame in the label field may not be terminated with a colon. This name cannot be redefined by a
subsequent EOU or SET directive. The EQU expression cannot contain any external symbol. (External symbols
are explained under 'Location Counter Control and Relocation,' later in this chapter.)
Assembly-tim! evaluation of EQU expressions always generates a modulo 64K address. Thus, the expression
always yields 1 value in the range 0-65,536.
Example:
The following EQU directive enters the name ONES into the symbol table and assigns the binary value
11111111 to t:
4-2
ONES EQU OFFH
Chapter 4. Assembler Directives
The value assigned by the EQU directive can be recalled in subsequent source lines by referring to its assigned
name as in the following IF directive:
IF TYPE EQ ONES
ENDIF
SET Directive
SET assigns the value of 'expression' to the name specified in the label field.
Label
name
Opcode
SET
Operand
expression
The assembler enters the value of 'expression' into the symbol table. Whenever 'name' is encountered sub-
sequently in the assembly, the assembler substitutes its value from the symbol table. This value remains unchanged
until altered by a subsequent SET directive.
The function of the SET directive is identical to EQU except that 'name' can appear in multiple SET directives
in the same program. Therefore, you can alter the value assigned to 'name' throughout the assembly.
Assembly-time evaluation of SET expressions always generates a modulo 64K address. Thus, the expression
always yields a value in the range 0-65,536.
Examples:
Label Opcode Operand Assembled Code
IMMED SET 5
ADI IMMED C605
IMMED SET lOH-6
ADI IMMED C60A
DATA DEFINITION
The DB (define byte) and DW (define word) directives enable you to define data to be stored in your program.
Data can be specified in the form of 8-bit or 16-bit values, or as a string of text characters.
DB Directive
The DB directive stores the specified data in consecutive memory locations starting with the current setting of the
location counter.
4-3
Chapter 4. Assembler Oi, ectives
Label
optional:
Opcode
DB
Operands
expresslon(s) or string(s)
The operand 'ield of the DB directive can contain a list of expressions and/or text strings. The list can contain
up to eight tc tal items: list items must be separated by commas. Because of limited workspace, the assembler
may not be a Jle to handle a total of eight items when the list includes a number of complex expressions. If
you ever haVE this problem, it is easily solved: simply use two or more directives to shorten the list.
Expressions nlust evaluate to l-byte (8-bit) numbers in the range -256 through 255. Text strings may comprise
a maximum of 128 ASCII characters enclosed in quotes.
The assemble,'s relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of
these s y m b o l ~ appears in an operand expression of the DB directive, it must be preceded by either the HIGH or
LOW operato' to specify which byte of the address is to be used in the evaluation of the expression. When
neither opera .or is present, the assembler assumes the LOW operator and issues an error message.
If the option;.! label IS present, it is assigned the starting value of the location counter, and thus references
the first byte stored by the DB directive. Therefore, the label STR in the following examples refers to the letter
T of the stmg TIME.
Examples:
Label Opcode Operands Assembled Code
STR: DB 'TIME' 54494D45
HERE: DB OA3H A3
WORD1: DB -03H,5*2 FDOA
DW Directive
The DW direl tlve stores each 16-blt value from the expression list as an address. The values are stored starting
at the curren setting of the location counter.
Label
optional:
Opcode
DW
Operands
expression list
The least sigr ificant eight bits of the first value in the expression list are stored at the current setting of the
location cour ter: the most significant eight bits are stored at the next higher location. This process is repeated
for each item in the expression list.
Expressions Evaluate to 1-word (16-bit) numbers, typically addresses. If an expression evaluates to a single byte,
it IS assumed to be the low order byte of a 16-bit word where the high order byte is all zeros.
44
Chapter 4. Assembler Directives
List items must be separated by commas. The list can contain up to eight total items. Because of limited work-
space, the assembler may not be able to handle eight complex expressions. If you ever have this problem, simply
use two or more OW directives to shorten the list.
The reversed order for storing the high and low order bytes is the typical format for addresses stored in memory.
Thus, the OW directive is commonly used for storing address constants.
Strings containing one or two ASCII characters enclosed in quotation marks may also appear in the expression
list. When using such strings in your program, remember that the characters are stored in reversed order.
Specifying a string longer than two characters causes an error.
If the optional label is present, it is assigned the starting address of the location counter, and thus references the
first byte stored by the OW directive. (This is the low order byte of the first Item in the expression list.)
Examples:
Assume that COMP and FI LL are labels defined elsewhere in the program. COMP addresses memory location
3B1CH. FILL addresses memory location 3EB4H.
Label
AOOR1:
AOOR2:
STRNG:
FOUR:
MEMORY RESERVATION
OS Directive
Opcode
OW
OW
OW
OW
Operands
COMP
FILL
'A','AB'
4H
Assembled Code
lC3B
B43E
41004241
0400
The OS directive can be used to define a block of storage.
Label
optional:
Opcode
OS
Operand
expression
The value of 'expression' specifies the number of bytes to be reserved for data storage. In theory, this value may
range from OOH through OFFFFH; in practice. you will reserve no more storage than will fit in your available
memory and still leave room for the program.
Any symbol appearing in the operand expression must be defined before the assembler reaches the OS directive.
Unlike the OB and OW directives, OS assembles no data into your program. The contents of the reserved storage
are unpredictable when program execution is initiated.
4-5
Chapter 4. Assembler Dir 'ctives
If the optlona label is present, it is assigned the current value of the location counter, and thus references the
first byte of tle reserved memory block.
If the value 01 the operand expression is zero, no memory is reserved. However, if the optional label is present,
it is assigned 1he current value of the location counter.
The DS directve reserves memory by Incrementing the location counter by the value of the operand expression.
Example:
TTYBUF: DS 72 ;RESERVE 72 BYTES FOR
;A TERMINAL OUTPUT BUFFER
Programming Tips: Data Description and Access
Random Access lersus Read Only Memory
When coding data descriptions, keep in mind the mix of ROM and RAM in your application.
Generally, the DB and DW directives define constants, Items that can be assigned to ROM. You can use these
items In your program, but you cannot modify them. If these items are assigned to RAM, they have an initial
value that YOL r program can modify during execution. Notice, however, that these initial values must be reloaded
Into memory Jrior to each execution of the program.
Variable data n memory must be assigned to RAM.
Data Description
Before coding your program, you must have a thorough understanding of ItS input and output data. But you'll
probably find it more convenient to postpone coding the data descriptions until the remainder of the program is
fairly well de\eloped. This way you will have a better idea of the constants and workareas needed In your program.
Also, the orgalization of a typical program places Instructions in lower memory, followed by the data, followed
by the stack.
Data Access
Accessing dati from memory is typically a two·step process: First you tell the processor where to find the data,
then the processor fetches the data from memory and loads it into a register, usually the accumulator. Therefore,
the following ;ode sequences have the identical effect of loading the ASCII character A into the accumulator.
4-6
AAA: DB
LXI
LDAX
'A'
B,AAA
B
ALPHA: DB
LXI
LDAX
'ABC'
B,ALPHA
B
Chapter 4. Assembler Directives
In the examples, the LXI instructions load the address of the desired data into the Band C registers. The LDAX
instructions then load the accumulator with one byte of data from the address specified in the Band C registers.
The assembler neither knows nor cares that only one character from the three-character field ALPHA has been
accessed. The program must account for the characters at ALPHA+1 and ALPHA+2, as in the following coding
sequence:
ALPHA: DB 'ABC' ;DEFINE ALPHA
LXI B,ALPHA ;LOAD ADDRESS OF ALPHA
LDAX B ;FETCH 1ST ALPHA CHAR
INX B ;SET BTO ALPHA+l
LDAX B ;FETCH 2ND ALPHA CHAR
INX B ;SET B TO ALPHA+2
LDAX B ;FETCH 3RD ALPHA CHAR
The coding above is acceptable for short data fields like ALPHA. For longer fields, you can conserve memory
by setting up an instruction sequence that is executed repeatedly until the source data is exhausted.
Add Symbols for Data Access
The following example was presented earlier as an illustration of the DS directive:
Label
TTYBUF:
Opcode
DS
Operand
72
Comment
;RESERVE TTY BUFFER
To access data in this buffer using only expressions such as TTYBUF+l, TTYBUF+2, ... TTYBUF+72 can be
a laborious and confusing chore, especially when you want only selected fields from the buffer. You can simplify
this task by subdivid.ing the buffer with the EQU directive:
Label Opcode Operand Comment
TTYBUF: DS 72 ;RESERVE TTY BUFFER
ID EQU TTYBUF ;RECORD IDENTIFIER
NAME EQU TTYBUF+6 ;20-CHAR NAME FIELD
NUMBER EQU TTYBUF+26 ;10-CHAR EMPLOYEE NUMBER
DEPT EQU TTYBUF+36 ;5-CHAR DEPARTMENT NUMBER
SSNO EQU TTYBUF+41 ;SOCIAL SEC. NUMBER
DOH EQU TTYBUF+50 ;DATE OF HIRE
DESC EQU TTYBUF+56 ;)OB DESCRIPTION
4-7
Chapter 4. Assembler Dir'ctives
Subdividing d. ta as shown in the example simplifies data access and provides useful documentation throughout
your program. Notice that these EQU directives can be inserted anywhere within the program as you need them,
but coding tht m as shown in the example provides a more useful record description.
CONDITIONAL ASSEMBLY
The IF. ELSE. and ENDIF directives enable you to assemble portions of your program conditionally, that is,
only if certain conditions that you specify are satisfied.
Conditional is especially useful when your application requires custom programs for a number of com-
mon options. As an example, assume that a basic control program requires customlz'ing to accept input from
one of six dif erent sensing devices and to drive one of five different control dev,ices. Rather than code some
!
thirty separat" programs to account for all the possibilities, you can code a single program. The code for the in-
dividual senso's and drivers must be enclosed by the conditional directives. When you need to generate a custom
program, you can insert SET directives near the beginning of the source program to select the desired sensor and
driver routine ..
IF, ELSE. ENDIF [irectives
Because these directives are used in conjunction. they are described together here.
Label
optional:
optional:
optional:
Opcode
IF
ELSE
ENDIF
Operand
expression
The assembler evaluates the expression in the operand field of the IF directive. If bit 0 of the resulting value is
one (TRUE), til Instructions between the IF directive and the next ELSE or ENDIF directive are assembled.
When bit 0 is zero (FALSE) these instructions are ignored. (A TRUE expression evaluates to OFFFFH and
FALSE to OH: only bit zero need be tested.)
All included between an IF directive and its required associated ENDIF directive are defined as an
IF-ENDIF blo;k. The ELSE directive is optional, and only one ELSE directive may appear In an IF-ENDIF
block. When i lcluded. ELSE is the converse of IF. When bit 0 of the expression in the IF directive IS zero, all
statements be:ween ELSE and the next ENDIF are assembled. If bit 0 IS one. these statements are ignored.
Operands are lOt allowed with the ELSE and ENDIF directives.
An IF-ENDIF block may appear within another IF-ENDIF block. These blocks can be nested to eight levels.
Macro definitions (explained in the next chapter) may appear within an IF-ENDIF block. Conversely, IF-ENDIF
blocks may al'pear within macro definitions. In either case, you must be certain to terminate the macro definition
4-8
Chapter 4. Assembler Directives
or IF-ENDIF block so that it can be assembled completely, For example, when a macro definition begins In an
IF block but terminates after an ELSE directive, only a portion of the macro can be assembled. Similarly, an
IF-ENDIF block begun within a macro definition must terminate within that same macro definition.
NOTE
Caution IS required when symbols are defined in IF-ENDIF
blocks and referenced elsewhere within the program. These
symbols are undefined when the evaluation of the IF ex-
pression suppresses the assembly of the IF-ENDIF block.
Example 1. Simple IF-ENDIF Block:
CONDl IF TYPE EQ 0
ENDIF
;ASSEMBLED IF 'TYPE =0'
;IS TRUE
Example 2. IF-ELSE-ENDIF Block:
COND2: IF TYPE EQ 0
ELSE
ENDIF
;ASSEMBLED IF 'TYPE = 0'
;IS TRUE
;ASSEMBLED IF 'TYPE = 0'
:IS FALSE
4-9
Chapter 4. Assembler Directives
Example 3. Nested IF's:
COt ID3: IF TYPE EO 0
;ASSEMBLED IF 'TYPE = 0'
;15 TRUE
IF MODE EO 1
LE\'EL
1
ENDIF
ELSE
LEVEL
2
IF MODE EO 2
LE\EL ELSE
1
ENDIF
ENDIF
ASSEMBLER TERMINATION
END Directive
;ASSEMBLED IF 'TYPE =0'
;AND 'MODE =l' ARE BOTH
;TRUE
;ASSEMBLED IF 'TYPE =0'
;15 FALSE
;ASSEMBLED IF 'TYPE = 0'
;15 FALSE AND 'MODE =2'
;15 TRUE
;ASSEMBLED IF 'TYPE = 0'
;AND 'MODE =2' ARE BOTH
;FALSE
The END identifies the end of the source program and terminates each pass of the assembler.
Label
optional:
Opcode
END
Operand
expression
Only one END statement may appear in a source program, and it must be the last source statement.
If the optioml expression is present, its value is used as the starting address for program execution. If no ex-
pression is gi len, the assembler assumes zero as the starting address.
When a number of separate program modules are to be joined together, only one may specify a program starting
address. The module with a starting address is the main module. When source files are combined using the IN-
CLUDE cont'ol, there are no restrictions on which source file contains the END.
4-10
Chapter 4. Assembler Directives
END-OF-TAPE INDICATION
The EOT directive allows you to specify the physical end of paper tape to simplify assembly of multiple-tape source
programs.
EOT Directive
Label
optional:
Opcode
EOT
Operand
When EOT is recognized by the assembler, the message 'NEXT TAPE' is sent to the console and the assembler pauses.'
After the next tape is loaded, a 'space bar' character received at the console signals continuation of the assembly.
Data in the operand field causes an error.
LOCATION COUNTER CONTROL AND RELOCATION
All the directives discussed in the remainder of this chapter relate directly to program relocation except for the
ASEG and ORG directives. These directives are described first for the convenience of readers who do not use the
relocation feature.
Location Counter Control (Non-Relocatable Mode)
When you elect not to use the relocation feature, an assembler default generates an ASEG directive for you. The
ASEG directive specifies that the program is to be assembled in the non-relocatable mode and establishes a
location counter for the assembly.
The location counter performs the same function for the assembler as the program counter performs during
execution. It tells the assembler the next memory location available for instruction or data assembly.
Initially, the location counter is set to zero. The location counter can be altered by the ORG (origin) directive.
ORG Directive
The ORG directive sets the location counter to the value specified by the operand expression.
Label
optional:
Opcode
ORG
Operand
expression
The location counter is set to the value of the operand expression. Assembly-time evaluation of ORG expressions
always Yields a modulo 64K address. Thus, the expression always yields an address in the range 0 through
65,535. Any symbol In the expression must be preViously defined. The next machine instruction or data item is
assembled at the specified address.
4-11
Chapter 4. Assembler Oi 'ectives
If no ORG di 'ective is included before the first instruction or data byte in your program, assembly begins at
location zero.
Your prograrr can include any number of ORG directives. Multiple ORG's need not specify addresses In
ascending seq Jence, but if you fail to do so, you may instruct the assembler to write over some previously
assembled POI tion of the program.
If the option" label is present, it is assigned the current value of the location counter before it is updated by the
ORG directiv".
Example:
Assume that the current value of the location counter is OFH (decimal 15) when the following ORG directive is
encountered:
ORG OFFH ;ORG ASSEMBLER TO LOCATION
;OFFH (decimal 225)
The symbol FAG1 is assigned the address OFH. The next instruction or data byte is assembled at location
OFFH.
Introduction to Reocatability
A maior feature of this assembler is its system for creating relocatable object code modules. Support for this new
feature includes a number of new directives for the assembler and three new programs included in ISIS-II. The
three new pr<lgrams - LIB, LINK, and LOCATE - are described in the ISIS-II System User's Guide. The new
assembler dir ~ c t i v e s are described later in this chapter.
Relocatabilit, allows the programmer to code programs or sections of programs without worrying about the
final arrangerlent of the object code in memory. This offers developers of microcomputer systems malor ad-
vantages In t",o areas: memory management and modular program development.
Memory ManagEment
When developing, testing, and debugging a system on your Intellec microcomputer development system, your
only concern with locating a program is that it doesn't overlap the resident routines of 1515·11. Because the
Intellec syste 11 has 32K, 48K, or 64K of random access memory, the location of your future program is not a
great concerr. However, the program you are developing will almost certainly use some mix of random access
memory (RAM), read-only memory (ROM), andior programmable read-only memory (PROM). Therefore, the
location of y)ur program affects both cost and performance in your application. The relocatability feature allows
you to deveillp, test, and debug your program on the Intellec development system and then simply relocate the
object code 10 suit your application.
The relocatal dlity feature also has a malor advantage at assembly-time: often, large programs with many symbols
cannot be as,embled because of limited work space for the symbol table. Such a program can be divided Into a
number of rrodules that can be assembled separately and then linked together to form a single object program.
4-12
Chapter 4. Assembler Directives
Modular Program Development
Although 'relocatability' may seem to be a formidable term, what it really means is that you can subdivide a
complex program into a number of smaller, simpler programs. This concept is best illustrated through the use of
an example. Assume that a microcomputer program IS to control the spark advance on an automobile engine.
This requires the program to sample the ambient air temperature, engine air intake temperature, coolant tempera-
ture, manifold vacuum, idle sensor, and throttle sensor.
Let us examine the approaches two different programmers might take to solve this problem. Both programmers
want to calculate the degree of spark advance or retardation that provides the best fuel economy with the lowest
emissions. Programmer A codes a single program that senses all inputs and calculates the correct spark advance.
Programmer B uses a modular approach and codes separate programs for each input plus one program to calculate
spark advance.
Although Programmer A avoids the need to learn to use the relocatability feature, the modular approach used
by Programmer B has a number of advantages you should consider:
• Simplified Program Development
It is generally easier to code, test, and debug several simple programs than one complex program.
• Sharing the Programming Task
If Programmer B finds that he is falling behind schedule, he can assign one or more of his sub-
programs to another programmer. Because of his single program concept, Programmer A will
probably have to complete the program himself.
• Ease of Testing
Programmer B can test and debug most of his modules as soon as they are assembled; Programmer
A must test his program as a whole. Notice that Programmer B has an extra advantage if the
sensors are being developed at the same time as the program. If one of the sensors is behind
schedule, Programmer B can continue developing and testing programs for the sensors that are
ready, Because Programmer A cannot test h is program until all the sensors are developed, his
testing schedule IS dependent on events beyond his control.
• Programming Changes
Given the nature of automotive design, it IS reasonable to expect some changes during system
development. If a change to one of the sensors requires a programming change, Programmer A
must search through his entire program to find and alter the coding for that sensor. Then he must
retest the entire program to be certain that those changes do not affect any of the other sensors.
By contrast, Programmer B need be concerned only with the module for that one sensor. This
advantage continues throughout the life of the program.
4-13
Chapter 4. Assembler Directives
DIRECTIVES USED FOR RELOCATION
Several direc Ives have been added to the assembler to support the relocation feature. These fall into the general
categories of location counter control and program linkage.
Location Counter :ontrol (Relocatable Programs)
Relocatable Jrograms or program modules may use three location counters. The ASEG, DSEG, and CSEG
directives sp"cify which location counter is to be used.
The ASEG c irective specifies an absolute code segment. Even in a relocatable program module, you may want
to assign cer:ain code segments to specific addresses. For example, restart routines invoked by the RST instruc-
tion require specific addresses.
The CSEG c Ifective specifies a relocatable code segment. In general, the CSEG location counter is used for por-
tions of the program that are to be in some form of read-only memory, such as machine instructions and pro-
gram consta ltS.
The DSEG ocation counter specifies a relocatable data segment. This location counter is used for program
elements th It must be located In random access memory.
These direc ives allow you to control program segmentation at assembly time. The LOCATE program, described
In the ISIS-II System User's GUide, gives you control over program segment location. Therefore, the guidelines
given above are only general since they can be overridden by the LOCATE program.
Regardless 'If how many times the ASEG, CSEG, and DSEG directives appear in your program, the assembler
produces a ;ingle, contiguous module. This module comprISes four segments: code, data, stack and memory.
The LINK Ind LOCATE programs are used to combine segments from individual modules and relocate them in
memory. T lese programs are explained in the ISIS-II System User's Guide.
ASEG Directh'e
ASEG dire,;ts the assembler to use the location counter for the absolute program segment.
Label
optional:
Opcode
ASEG
Operand
Operands ere not permitted with the ASEG directive.
All instrucions and data following the ASEG directive are assembled In the absolute mode. The ASEG directive
remains in effect until a CSEG or DSEG directive is encountered.
The ASEG location counter has an initial value of zero. The ORG directive can be used to assign a new value to
the ASEG location counter.
4-14
Chapter 4. Assembler Directives
When assembly begins. the assembler assumes the ASEG directive to be in effect. Therefore. a CSEG or DSEG
must precede the first instruction or data definition in a relocatable module. If neither of these directives
appears in the program. the entire program is assembled in absolute mode and can be executed immediately
after assembly without using the LINK or LOCATE programs.
CSEG Directive
CSEG directs the assembler to assemble subsequent instructions and data In the relocatable mode uSing the code
segment location counter.
Labe!
optional:
Opcode
CSEG
Operand
{
blank }
PAGE
INPAGE
When a program contains multiple CSEG directives. all CSEG directives throughout the program must specify
the same operand. The operand of a CSEG directive has no effect on the current assembly. but is stored with
·the object code to be passed to the LINK and LOCATE programs. (These programs are described in the ISIS-II
System User's Guide.) The LOCATE program uses this information to determine relocation boundaries when it
joins this code segment to code segments from other programs. The meaning of the operand is as follows:
• blank - This code segment may be relocated to the next available byte boundary.
• PAGE - This code segment must begin on a page boundary when relocated. Page boundaries
occur in multiples of 256 bytes beginning with zero (0. 256. 512. etc.).
• INPAGE This code segment must fit within a single page when relocated.
The CSEG directive remains in effect until an ASEG or DSEG directive is encountered.
The code segment location counter has an initial value of zero. The ORG directive can be used to assign a new
value to the CSEG location counter.
DSEG Directive
DSEG directs the assembler to assemble subsequent instructions and data In the relocatable mode using the data
segment location counter.
Labe! Opcode Operand
optional: DSEG
roo' i
PAGE >
INPAGE)
When multiple DSEG directives appear in a program. they must all specify the same operand throughout the
program. The operands for the DSEG directive have the same meaning as for the CSEG directive except that
they apply to the data segment.
4-15
Chapter 4. Assembler Dil ectives
There IS no ir teraction between the operands specified for the DSEG and CSEG directives. Thus. a code segment
can be byte r'locatable while the data segment is page relocatable.
The DSEG diective remains in effect until an ASEG or CSEG directive is encountered.
The data segr,lent location counter has an initial value of zero. The ORG directive can be used to assign a new
value to the [)SEG location counter.
ORG Directive ('?elocatable Mode)
The ORG dirxtive can be used to alter the value of the location counter presently in use.
Label
optional:
Opcode
ORG
Operand
expression
There are t h r ~ e location counters. but only one location counter is in use at any given point in the program.
Which one dEpends on whether the ASEG. CSEG, or DSEG directive is in effect.
Any symboilised in the operand expression must have been previously defined. An exception causes phase
errors for all abels that follow the ORG and a label error if the undefined error is defined later.
When the O ~ G directive appears in a relocatable program segment, the value of its operand expression must be
either absolu'e or relocatable within the current segment. Thus, if the ORG directive appears within a data seg-
ment, the val Je of its expression must be relocatable within the data segment. An error occurs if the expression
evaluates to , n address in the code segment.
If the option 11 label is present, It is assigned the current value of the location counter presently in use before
the ORG din ctive is executed.
Program Linkage [irectives
Modular pro! ramming and the relocation feature enable you to assemble and test a number of separate programs
that are to b; iOlned together and executed as a single program. Eventually, it becomes necessary for these
separate programs to communicate Information among themselves. Establishing such communication is the
function of the program linkage directives.
A program n,ay share its data addresses and instruction addresses with other programs. Only Items having an
entry in the iymbol table can be shared with other programs; therefore. the item must be assigned a name or a
label when it IS defined in the program. Items to be shared with other programs must be declared in a PUBLIC
directive.
Your prograln can directly access data or instructions defined In another program if you know the actual
address of tre item, but this is unlikely when both programs use relocation. Your program can also gain access
to data or Instructions declared as PUBLIC in other programs. Notice, however, that the assembler normally
4-16
Chapter 4. Assembler Directives
flags as an error any reference to a name or label that has not been defined in your program. To avoid this,
you must provide the assembler with a list of items used in your program but defined in some other program.
These items must be declared in an EXTRN directive.
The two remaining program linkage directives, NAME and STKLN, are individually explained later in this chapter.
PUBLIC Directive
The PUBLIC directive makes each of the symbols listed in the operand field available for access by other programs.
Label
optional:
Opcode
PUBLIC
Operands
name-list
Each item in the operand name-list must be the name or label assigned to data or an instruction elsewhere in
this program. When multiple names appear in the list. they must be separated by commas. Each name may be
declared PUBLIC only once in a program module. Reserved words and external symbols (see the EXTRN
directive below) cannot be declared to be PUBLIC symbols.
PUBLIC directives may appear anywhere within a program module.
If an item in the operand name-list has no corresponding entry in· the symbol table (implying that it i5 unde-
fined), it is flagged as an error.
Example:
EXTRN Directive
PUBLIC SIN,COS,TAN,SQRT
The EXTRN directive provides the assembler with a list of symbols referenced in th is program but defined in a
different program. Because of this, the assembler establishes linkage to the other program and does not flag the
undefi ned references as errors.
Label
optional:
Opcode
EXTRN
Operands
name-list
Each item in the name-list identifies a symbol that may be referenced in this program butis defined in another
program. When multiple items appear in the list, they must be separated by commas.
If a symbol in the operand name-list is also defined in this program by the user, or is a reserved symbol. the effect
is the same as defining the same symbol more than once in a program. The assembler flags this error.
EXTRN directives may appear anywhere within a program module.
A symbol may be declared to be external only once in a program module. Symbols declared to be PUBLIC cannot
also be declared to be EXTRN symbols.
4·17
Chapter 4. Assembler Oi, ectives
If you omit a symbol from the name-list but reference it 111 the program, the symbol is undefined. The assembler
flags this erro', You may include symbols in the operand name-list that are not referenced in the program with-
out causing ail error.
Example:
NAME Directive
EXTRN ENTRY,ADDRTN,BEGIN
The NAME directive assigns a name to the object module generated by this assemblY,
Label
optional:
Opcode
NAME
Operand
module-name
The NAME directive requires the presence of a module-name in the operand field. This name must conform to
the rules for jefining symbols.
Module names are necessary so that you can refer to a module and specify the proper sequence of modules
when a numr er of modules are to be bound together.
The NAME directive must precede the first data or instruction coding in the source program, but may follow
comments anj control lines.
If the NAME directive is missing from the program, the assembler supplies a default NAME directive with the
module-name MODULE. This will cause an error if you attempt to bind together several object program
modules and more than one has the name MODULE. Also, if you make an error coding the NAME directive,
the default nime MODULE is assigned.
The module···name assigned by the NAME directive appears as part of the page heading in the assembly listing.
Example:
STKLN Directile
NAME MAIN
Regardless 01 the number of object program modules you may bind together, only one stack is generated. The
STKLN dire' tive allows you to specify the number of bytes to be reserved for the stack for each module.
Label
optional:
Opcode
STKLN
Operand
expression
The operand expression must evaluate to a number which will be used as the maximum size of the stack.
4-18
Chapter 4. Assembler Directives
When the STKLN directive is omitted, the assembler provides a default STKLN of zero. This is useful when
multiple programs are bound together; only one stack will be generated, so only one program module need
specify the stack size. However, you should provide a STKLN if your module is to be tested separately and
uses the stack.
If your program includes more than one STKLN directive, only the last value assigned is retained.
Example:
STKLN 100
STACK and MEMORY Reserved Words
The reserved words STACK and MEMORY are not directives but are of interest to programmers using the
relocation feature. These reserved words are external references whose addresses are supplied by the LOCATE
program.
STACK is the symbolic reference to the stack origin address. You need this address to initialize the stack
pointer register. Also, you can base data structures on this address using svmbolic references such as STACK+1,
STACK+2, etc.
MEMORY is the symbolic reference to the first byte of unused memory past the end of your program. Again,
you can base data structures on this address using symbolic references such as MEMORY, MEMORY+l, etc.
Programming Tips: Testing Relocatable Modules
The ability to test individual program modules is a maior advantage of modular programming. However, many
program modules are not logically self-sufficient and require some modification before they can be tested. The
following is a discussion of some of the more common modifications that may be required.
Initialization Routines
In most complete programs, a number of housekeeping or initialization procedures are performed when execution
first begins. If the program module you are testing relies on initialization procedures aSSigned to a different
module, you must duplicate those procedures in the module to be tested. (Notice, however, that you can link
any number of modules together for testing.)
One of the most important initialization procedures is to set the stack pointer. The LOCATE program determines
the origin of the stack.
Your program should include the following instruction to initialize the stack pointer:
LXI SP,STACK
4-19
Chapter 4. Assembler [irectives
Input/Output
When testing ,rogram modules, it is likely that some input or output procedures appear in other modules. Your
program must simulate any of these procedures it needs to operate. Since your Intellec development system
probably has considerably more random access memory than you need to test a program module, you may be
able to simula:e Input and output data right in memory, The LOCATE program supplies an address for the
reserved word MEMORY; this is the address of the first byte of unused memory past the end of your program.
You can acces, this memory using the symbolic reference MEMORY, MEMORY+l, and so on. This memory
can be used fer storing test data or even for a program that generates test data.
Remove Coding Used for Testing
After testing ~ o u r program, be certain to remove any code you inserted for testing. In particular, make certain
that only one module in the complete program initializes the stack pointer.
4-20
5. MACROS
INTRODUCTION TO MACROS
Why Use Macros?
A macro is essentially a facility for replacing one set of parameters with another. In developing your program,
you will frequently find that many Instruction sequences are repeated several times with only certain parameters
changed.
As an example, suppose that you code a routine that moves five bytes of data from one memory location to
another. A little later, you find yourself coding another routine to move four bytes from a different source
field to a different destination field. If the two routines use the same coding techniques, you will find that
they are identical except for three parameters: the character count, the source field starting address, and the
d:",tiiCatltl:'\ field starting address. Certainly It would be handy if there were some way to regenerate that original
'outine substituting the new parameters rather than rewrite that code yourself. The macro facility provides this
capability and offers several other advantages over writing code repetitiously'
e The tedium of frequent rewrite (and the probability of error) is reduced.
e Symbols used in macros can be restricted so that they have meaning only within the macro itself.
Therefore, as you code your program, you need not worry that you will accidentally duplicate a
symbol used in a macro. Also, a macro can be used any number of times in the same program
without duplicating any of its own symbols.
e An error detected In a macro need be corrected only once regardless of how many times the macro
appears in the program. This reduces debugging time.
e Duplication of effort between programmers can be reduced. Useful functions can be collected In a
library to allow macros to be copied into different programs.
In addition, macros can be used to improve program readability and to create structured programs. USing macros
to segment code blocks provides clear program notation and simplifies tracing the flow of the program.
What Is A Macro?
A macro can be described as a routine defined in a formal sequence of prototype instructions that, when called
within a program, results in the replacement of each such call with a code expansion consisting of the actual
instructions represented.
5-'
Chapter 5. Macros
The concepts c f macro definition, call, and expansion can be illustrated by a tYPical business form letter, where
the prototypenstructions conSISt of preset text. For example, we could define a macro CNFIRM with the text
Air FI ght welcomes you as a passenger.
Your 'Iight number FNO leaves at DTIME and arrives in DEsT at ATIME.
This macro ha, four dummy parameters to be replaced, when the macro is called, by the actual flight number,
departure time destination, and arrival time. Thus the macro call might look like
123, '10:45', 'Ontario', '11 :52'
A second macro, CAR, could be called if the passenger has requested that a rental car be reserved at the desti-
nation airport. This macro might have the text
Your lutomobile reservation has been confirmed with MAKE rent-a-car agency.
Finally, a macro GREET could be defined to specify the passenger name.

The entire tex of the business letter (source file) would then look like
GREET 'Ms. scannel'
123, '10:45', 'Ontario', '11:52'
CAR 'Blotz'
We tr Jst you will enioy your flight.
Since ely,
When this sou,ce file is passed through a macro processor, the macro calls are expanded to produce the following
letter.
Dear 'v1s. scannel:
Air Fight welcomes you as a passenger. Your flight number 123 leaves at 10:45 and arrives
in Ortario at 11 :52. Your automobile reservation has been confirmed with Blotz rent-a-car
agency.
We trust you will enjoy your flight.
Since'ely,
While this exallple illustrates the substitution of parameters in a macro, it overlooks the relationship of the macro
processor and the assembler. The purpose of the macro processor is to generate source code which is then
assembled.
5-2
Chapter 5. Macros
Macros Vs. Subroutines
At this point, you may be wondering how macros differ from subroutines Invoked by the CALL instruction.
Both aid program structuring and reduce the coding of frequently executed routines.
One distinction between the two IS that subroutines necessarily branch to another part of your program while
macros generate in-line code. Thus, a program contains only one version of a given subroutine, but contains as
many versions of a given macro as there are calls for that macro.
Notice the emphasis on 'versions' in the prevIous sentence, for this is a malor difference between macros and
subroutines. A macro does not necessarily generate the same source code each time it is called. By changing the
parameters In a macro call, you can change the source code the macro generates. In addition, macro parameters
can be tested at assembly-time by the conditional assembly directives. These two tools enable a general-purpose
macro definition to generate customized source code for a particular programming situation. Notice that macro
expansion and any code customization occur at assembly-time and at the source code level. By contrast, a
generalized subroutine resides in your program and requires execution time.
It IS usually possible to obtain similar results using either a macro or a subroutine. Determining which of these
facilities to use is not always an obvious decision. In some cases, uSing a single subroutine rather than multiple
In-line macros can reduce the overall program size. In situations involving a large number of parameters, the use
of macros may be more efficient. Also, notice that macros can call subroutines, and subroutines can contain
macros.
USING MACROS
The assembler recognizes the following macro operations:
.. MACRO directive
CI ENDM directive
.. LOCAL directive
CI REPT directive
.. IRP directive
.. IRPC directive
CI EXITM directive
.. Macro call
All of the directives listed above are related to macro definition. The macro call initiates the parameter sub-
stitution (macro expansion) process.
Macro Definition
Macros must be defined in your program before they can be used. A macro definition is Initiated by the MACRO
assembler directive, which lists the name by which the macro can later be called, and the dummy parameters to
be replaced during macro expansion. The macro definition is terminated by the ENDM directive. The prototype
instructions bounded by the MACRO and ENDM directives are called the macro body.
5·3
Chapter 5. Macros
When label sy mbols used in a macro body have 'global' scope, multiply-defined symbol errors result if the macro
is called more than once. A label can be given limited scope using the LOCAL directive. This directive assigns a
unique value :0 the symbol each time the macro is called and expanded. Dummy parameters also have limited
scope.
Occasionally "ou may wish to duplicate a block of code several times, either within a macro or in line with
other source ':ode. This can be accomplished with minimal coding effort using the REPT (repeat block), IRP
(indefinite repeat), and IRPC (indefinite repeat character) directives. Like the MACRO directive, these directives
are terminated by ENDM.
The EXITM c irective provides an alternate exit from a macro. When encountered, it terminates the current macro
just as if EN['M had been encountered.
Macro Definitior, Directives
MACRO Dire:tive
Label
name
Opcode
MACRO
Operand
optional dummy parameter(s)
The name in :he label field specifies the name of the macro body being defined. Any valid user-defined symbol
name can be Jsed as a macro name. Note that this name must be present and must not be terminated by a colon.
A dummy panmeter can be any valid user-defined symbol name or can be null. When multiple parameters are listed,
they must be ,eparated by commas. The scope of a dummy parameter is limited to its specific macro definition. If a
reserved symt 01 is used as a dummy parameter, its reserved value is not recognized. For example, if you code
A,B,C as a dLmmy parameter list, substitutions will occur properly. However, you cannot use the accumulator
or the Band::: registers within the macro. Because of the limited scope of dummy parameters, the use of these
registers is not affected outside the macro definition.
Dummy paralneters in a comment are not recognized. No substitution occurs for such parameters.
Dummy paralneters may appear in a character string. However, the dummy parameter must be adjacent to an
ampersand chlracter (&) as explained later In this chapter.
Any machine Instruction or applicable assembler directive can be included in the macro body. The distinguishing
feature of ma;ro prototype text is that parts of it can be made variable by placing substitutable dummy param-
eters in instrLction fields. These dummy parameters are the same as the symbols in the operand field of the
MACRO dire'tive.
Example:
Define macro MACl with dummy parameters Gl, G2, and G3.
5-4
Chapter 5. Macros
NOTE
The following macro definition contains a potential error
that IS clarified in the description of the LOCAL directive
later in this chapter.
MACl MACRO Gl,G2,G3 ;MACRO DIRECTIVE
MOVES: LHLD Gl ;MACRO BODY
MOV A,M
LHLD G2
MOV B,M
LHLD G3
MOV C,M
ENDM ;ENDM DIRECTIVE
ENDM Directive
Label Opcode
ENDM
Operand
The ENDM directive is required to terminate a macro definition and follows the last prototype instruction. It is
also required to terminate code repetition blocks defined by the REPT, IRP, and IRPC directives.
Any data appearing in the label or operand fields of an ENDM directive causes an error.
NOTE
Because nested macro calls are not expanded during macro
definition, the ENDM directive to close an outer macro can-
not be contained in the expansion of an inner, 'nested'
macro call. (See 'Nested Macro Definitions' later in this
chapter.)
LOCA L Directive
Label Opcode
LOCAL
Operand
label name(s)
The specified label names are defined to have meaning only within the current macro expansion. Each time the
macro is called and expanded, the assembler assigns each local symbol a unique symbol in the form 77nnnn.
The assembler assigns ?7OOO1 to the first local symbol, 770002 to the second, and so on. The most recent symbol
name generated always indicates the total number of symbols created for all macro expansions. The assembler
never duplicates these symbols. The user should avoid coding symbols in the form ??nnnn so that there will not
be a conflict with these assembler-generated symbols.
5-5
Chapter 5. Macros
Dummy parameters included in a macro call cannot be operands of a LOCAL directive. The ~ cope of a dummy
parameter is always local to its own macro definition.
Local symbols can be defined only within a macro definition. Any number of LOCAL directves may appear in
a macro definition, but they must all follow the macro call and must precede the first line 01 prototype code.
A LOCAL directive appearing outside a macro definition causes an error. Also, a name appea-ing in the label
field of a LOCAL directive causes an error.
Example:
The definition of MACl (used as an example in the description of the MACRO directive) cOlltains a potential
error because the symbol MOVES has not been declared local. This is a potential error since no error occurs if
MACl IS called only once in the program, and the program itself does not use MOVES as a ~ y m b o l . However,
if MACl is called more than once, or if the program uses the symbol MOVES, MOVES is a multiply-defined
symbol. This potential error is avoided by naming MOVES in th'eoperand field of a LOCAL directive:
MACl MACRO Gl,G2,G3
LOCAL MOVES
MOVES: LHLD Gl
MOV A,M
LHLD G2
MaY B,M
LHLD G3
MaY C,M
ENDM
Assume that MACl is the only macro in the program and that it is called twice. The first tirle MACl is expanded,
MOVES IS replaced with the symbol 7?OOOl; the second time, MOVES is replaced with 7?0002. Because the
assembler encounters only these special replacement symbols, the program may contain the 'ymbol MOVES
without causing a multiple definition.
REPT Directive
Label
optional:
Opcode
REPT
Operand
expression
The REPT directive causes a sequence of source code lines to be repeated 'expression' times. All lines appeanng
between the REPT directive and a subsequent ENDM directive constitute the block to be repeated.
When 'expression' contains symbolic names, the assembler must encounter the definition of he symbol prior to
encountering the expression.
The insertion of repeat blocks is performed in-line when the assembler encounters the REPl directive. No
explicit call is required to cause the code insertion since the definition is an implied call for expansion.
5-6
Chapter 5. Macros
Example 1:
Rotate accumulator right six times.
ROTR6:
Example 2:
REPT
RRC
ENDM
6
The following REPT directive generates the source code for a routine that fills a five-byte field with the character
stored in the accumulator:
PROGRAM CODE GENERA TED CODING
Example 3:
LHLD
REPT
MOV
INX
ENDM
CNTR1
5
M,A
H
LHLD
MOV
INX
MOV
INX
MOV
INX
MOV
INX
MOV
INX
CNTR1
M,A
H
M,A
H
M,A
H
M,A
H
M,A
H
The following example illustrates the use of REPT to generate a multiplication routine. The multiplication is
accomplished through a series of shifts. If this technique is unfamiliar, refer to the example of multiplication
in Chapter 6. The example in Chapter 6 uses a program loop for the multiplication. This example replaces the
loop with seven repetitions of the four instructions enclosed by the REPT-ENDM directives.
Notice that the expansion specified by this REPT directive causes the label SKIPAD to be generated seven times.
Therefore, SKIPAD must be declared local to this macro.
FSTMUL:
SKIPAD:
MVI
LXI
REPT
LOCAL
RLC
jNC
DAD
DAD
ENDM
RLC
RNC
DAD
RET
D,D
H,D
7
SKIPAD
SKIPAD
D
H
D
;FAST MULTIPLY ROUTINE
;MULTIPLY E*A - 16-BIT RESULT
;IN H&L
;;GET NEXT MULTIPLIER BIT
;;DON'T ADD IF BIT =D
;;ADD MULTIPLICAND INTO ANSWER
5-7
Chapter 5. Macros
This example ilustrates a classic programming trade-off: speed versus memory Although this example executes
more qUickly tlan the example in Chapter 6, it requires more memory.
IRP Directive
Label
optional:
Opcode
IRP
Operand
dummy param, <list>
The operand field for the IRP (indefinite repeat) directive must contain one macro dummy parameter followed
by a list of actual parameters enclosed In angle brackets. IRP expands its associated macro prototype code sub-
stituting the fi 'st actual parameter for each occurrence of the dummy parameter. IRP then expands the proto-
type code agai 1 substituting the second actual parameter from the list. This process continues until the list is
exhausted.
The list of actJal parameters to be substituted for the dummy parameter must be enclosed In angle brackets
« ». Individu, I items in the list must be separated by commas. The number of actual parameters in the list
controls the nilmber of times the macro body is repeated; a list of n Items causes n repetitions. An empty list
(one with no Jarameters coded) specifies a null operand list. IRP generates one copy of the macro body sub-
stituting a nul' for each occurrence of the dummy parameter. Also, two commas with no intervening character
create a null parameter within the list. (See 'Special Operators' later in this chapter for a description of null
operands.)
Example:
The following code sequence gathers bytes of data from different areas of memory and then stores them in
consecutive b ~ tes beginning at the address of STORIT
PROGRAM CODE GENERA TED CODING
IRPC Directhe
LXI
IRP
LOA
MOV
INX
ENOM
H,STORIT
X,<FL01,3E20H,FLD3>
X
M,A
H
LXI
LOA
MOV
INX
LDA
MOV
INX
LOA
MOV
INX
H,STORIT
FLOl
M,A
H
3E20H
M,A
H
FL03
M,A
H
5-8
Label
optional:
Opcode
IRPC
Operand
dummy param,text
Chapter 5. Macros
The IRPC (indefinite repeat character) directive causes a sequence of macro prototype instructions to be repeated
for each text character of the actual parameter specified. If the text string is enclosed in optional angle brackets,
any delimiters appearing in the text string are treated simply as text to be substituted into the prototype code.
The assembler generates one iteration of the prototype code for each character in the text string. For each
Iteration, the assembler substitutes the next character from the string for each occurrence of the dummy param-
eter. A list of n text characters generates n repetitions of the IRPC macro body. An empty string specifies a
null actual operand. IRPC generates one copy of the macro body substituting a null for each occurrence of the
dummy parameter.
Example:
PROGRAM CODE GENERA TED CODING
MVDATE:
LHLD
IRPC
INX
MVI
ENDM
DATE-l
X,1977
H
M,X
LHLD
INX
MVI
INX
MVI
INX
MVI
INX
MVI
DATE-l
H
M,l
H
M,9
H
M,7
H
M,7
IRPC provides the capability to treat each character of a string individually; concatenation (described later in this
chapter) provides the capability for building text strings from Individual characters.
EXITM Directive
Label
optional:
Opcode
EXITM
Operand
EXITM provides an alternate method for terminating a macro expansion or the repetition of a REPT, IRP, or
IRPC code sequence. When EX!TM is encountered, the assembler ignores all macro prototype instructions
located between the EXITM and ENDM directive for this macro. Notice that EXITM may be used in addition
to ENDM, but not in place of ENDM.
When used in nested macros, EXITM causes an exit to the previous level of macro expansion. An EXITM within
a REPT, IRP. or IRPC terminates not only the current expansion, but all subsequent iterations as well.
Any data appearing in the operand field of an EXITM directive causes an error.
Example:
EXITM is typically used to suppress unwanted macro expansion. In the following example, macro expansion is
terminated when the EX1TM directive is assembled because the condition X EQ 0 is true.
5-9
Chapter 5. Macros
Special Macro Op?rators
MAC3 MACRO X,Y
IF X EQ 0
EXITM
ENDM
In certain specal cases, the normal rules for dealing with macros do not work. Assume. for example, that you
want to specif" three actual parameters. and the second parameter happens to be the comma character. To the
assembler, the list PARM1,,,PARM3 appears to be a list of four parameters where the second and third param-
eters are missirg. The list can be passed correctly by enclosing the comma in angle brackets: PARM1,<,>,PARM3.
These special ( perators instruct the assembler to accept the enclosed character (the comma) as an actual param-
eter rather tha'l a del imiter.
The assembler recognizes a number of operators that allow special operations:
5-10
&
<>
Ampersand. Used to concatenate (link) text and dummy parameters. See the further
discussion of ampersands below.
Angle brackets. Used to delimit text, such as lists, that contain other delimiters.
Notice that blanks are usually treated as delimiters. Therefore, when an actual
parameter contains blanks (passing the instruction MOV A,M, for example) the
parameter must be enclosed in angle brackets. This is also true for any other de-
limiter that is to be passed as part of an actual parameter. To pass such text to
nested macro calls, use one set of angle brackets for each level of nesting. (See
'Nested Macro Definitions,' below.)
Double semicolon. Used before a comment in a macro definition to prevent
inclusion of the comment in expansions of the macro and reduce storage
requirements. The comment still appears in the listing of the definition.
Exclamation point (escape character). Placed before a character (usually a
delimiter) to be passed as literalized text in an actual parameter. Used primarily
to pass angle brackets as part of an actual parameter. To pass a literalized
exclamation point, issue!!. Carriage returns cannot be passed as actual parameters.
The 'I' is always preserved while building an actual parameter. It is not
echoed when an actual parameter is substituted for a dummy parameter,
except when the substitution is being used to build another actual parameter.
Chapter 5. Macros
NUL In certain cases it is not necessary to pass a parameter to a macro. It is
necessary, however, to indicate the omission of the parameter. The omitted
(or null) parameter can be represented by two consecutive delimiters as in
the list PARMl "PARM3. A null parameter can also be represented by two
consecutive single quotes: ",PARM2,PARM3. Notice that a null is quite
different from a blank: a blank is an ASCII character with the hexadecimal
representation 20H; a null has no character representation. In the assembly
listing a null looks the same as a blank, but that is only because no substi-
tution has taken place. The programmer must decide the meaning of a null
parameter. Although the mechanism is somewhat different, the defaults taken
for assembler controls provide a good example of what a null parameter can
mean. For example. coding MOD85 as an assembler control specifies that
the assembler is to generate obiect code for the 8085. The absence of this
control (which In effect is a null parameter) specifies that the assembler
is to generate only 8080 object code.
Assembler controls are explained in the 1515-11 8080/8085 Macro Assembler
Operator's Manual, 9800292.
Example:
In a macro with the dummy parameters W,X,Y,Z it is acceptable for either
the X or Y parameter to be null, but not both. The following IF directive
tests for the error condition:
IF NUL X&Y
EXITM
When a macro IS expanded, any ampersand preceding or following a dummy parameter in a macro definition is
removed and the substitution of the actual parameter occurs at that point. When it is not adjacent to a dummy
parameter, the ampersand is not removed and is passed as part of the macro expansion text.
NOTE
The ampersand must be immediately adjacent to the text being
concatenated; Intervening blanks are not allowed.
If nested macro definitions (described below) contain ampersands, the only ampersands removed are those adjacent
to dummy parameters belonging to the macro definition currently being expanded. All ampersands must be reo
moved by the time the expansion of the encompassing macro body is performed. Exceptions force illegal character
errors.
Ampersands placed inside strings are recognized as concatenation delimiters when adjacent to dummy parameters;
similarly, dummy parameters within character strings are recognized only when they are adjacent to ampersands.
Ampersands are not recognized as operators in comments.
5-11
Chapter 5. Macros
Nested Macro Del initions
A macro definition can be contained completely within the body of another macro definition (that is, macro
definitions can be nested). The body of a macro consists of all text (including nested macro definitions)
bounded by mltching MACRO and ENDM directives. The assembler allows any number of macro definitions to
be nested.
When a higher-evel macro is called for expansion, the next lower-level macro is defined and eligible to be called
for expansion. A lower-level macro cannot be called unless all higher-level macro definitions have already been
called and exp;.nded.
A new macro I nay be defined or an existing macro redefined by a nested macro definition depending on whether
the name of the nested macro is a new label or has previously been established as a dummy parameter in a
higher-level ma:ro definition. Therefore, each time a higher-level macro is called, a lower-level definition can be
defined differe ltly if the two contain common dummy parameters. Such redefinition can be costly, however, in
terms of assemoler execution speed.
Since IRP, IRFC, and REPT blocks constitute macro definitions, they also can be nested within another definition
created by IRF, IRPC, REPT, or MACRO directives. In addition, an element in an IRP or IRPC actual parameter
list (enclosed 1,1 angle brackets) may itself be a list of bracketed parameters; that is, lists of parameters can contain
elements that ,.re also lists.
Example:
LISTS MACRO
ENDM
PARAM1,PARAM2
MACRO CALLS
LISTS <A, <B,C»
Once 'a macro las been defined, it can be called any number of times in the program. The call consists of the
macro name alid any actual parameters that are to replace dummy parameters during macro expansion_ During
assembly, each macro call is replaced by the macro definition code; dummy parameters are replaced by actual
parameters.
Macro Call Format
5-12
Label
optional:
Opcode
macro name
Operand
optional actual
parameter(s)
Chapter 5. Macros
The assembler must encounter the macro definition before the first call for that macro. Otherwise. the macro
call is assumed to be an illegal opcode. The assembler inserts the macro body identified by the macro name
each time it encounters a call to a previously defined macro in your program.
The positioning of actual parameters in a macro call is critical since the substitution of parameters is based
solely on position. The first-listed actual parameter replaces each occurrence of the first-listed dummy param-
eter; the second actual parameter replaces the second dummy parameter, and so on. When coding a macro call,
you must be certain to list actual parameters in the appropriate sequence for the macro.
Notice that blanks are usually treated as delimiters. Therefore, when an actual parameter contains blanks
(passing the instruction MOV A,M, for example) the parameter must be enclosed in angle brackets. This is also
true for any other delimiter that is to be passed as part of an actual parameter. Carriage returns cannot be passed
as actual parameters,
If a macro call specifies more actual parameters than are listed in the macro definition, the extra parameters
are ignored. If fewer parameters appear in the call than in the definition, a null replaces each missing parameter.
Example:
The following example shows two calls for the macro LOAD. LOAD is defined as follows:
LOAD MACRO Gl,G2,G3
LOCAL MOVES
MOVES: LHLD Gl
MOV A,M
LHLD G2
MOV B,M
LHLD G3
MOV C,M
ENDM
LOAD simply loads the accumulator with a byte of data from the location specified by the first actual parameter,
the B register with a byte from the second parameter, and the C register with a byte from the third parameter.
The first time LOAD is called, It is used as part of a routine that inverts the order of three bytes in memory.
The second time LOAD is called, it is part of a routine that adds the contents of the B register to the accumu·
lator and then compares the result with the contents of the C register.
5-13
Chapter 5. Macros
MAIN PROGRAM
SUBSTITUTION
JNZ nEXT
LOA[ FLD,FLD+1,FLD+2
MOY M,A ;INYERT BYTES
DCX H
MOY M,B
DCX H
MOY M,C
LOM' 3EOH,BYTE,CHECK
ADD B ;CHECK DIGIT
CMP C
CNZ DGTBAD
Nested Macro Calls
??0001 .
7?0002:
JNZ
LHLD
MOY
LHLD
MOY
LHLD
MOY
MOY
DCX
MOY
DCX
MOY
LHLD
MOY
LHLD
MOY
LHLD
MOY
ADD
CMP
CNZ
NEXT
FLD
A,M
FLD+1
B.M
FLD+2
C,M
M,A ;INYERT BYTES
H
M,B
H
M,C
3EOH
A,M
BYTE
B,M
CHECK
C,M
B ;CHECK DIGIT
C
DGTBAD
Macro calls (in:luding any combination of nested IRP, IRPC, and REPT constructs) can be nested within macro
definitions up to eight levels. The macro being called need not be defined when the enclosing macro is defined;
however, it ml st be defined before the enclosing macro is called.
A macro defin tlon can also contain nested calls to itself (recursIVe macro calls) up to eight levels, as long as the
recursive macr" expansions can be terminated eventually, This operation can be controlled using the conditional
assembly direc:lves described in Chapter 4 (IF, ELSE, ENDIF).
Example:
Have a macro :all itself five times after it is called from elsewhere in the program.
PARAM1
RECALL
SET 5
MACRO
5-14
PARAM1
IF
SET
RECALL
ENDIF
ENDM
PARAM1 NE 0
PARAM1-1
;RECURSIYE CALL
Chapter 5. Macros
Macro Expansion
When a macro is called, the actual parameters to be substituted into the prototype code can be passed in one of
two modes. Normally, the substitution of actual parameters for dummy parameters is simply a text substitution.
The parameters are not evaluated until the macro is expanded.
If a percent sign (%) precedes the actual parameter in the macro call, however, the parameter is evaluated
immediately, before expansion occurs, and is passed as a decimal number representing the value of the param-
eter. In the case of IRPC, a '%' preceding the actual parameter causes the entire text string to be treated as a
single parameter. One IRPC iteration occurs for each digit in the decimal string passed as the result of immediate
evaluation of the text string.
The normal mechanism for passing actual parameters is adequate for most applications. Using the percent sign
to pre-evaluate parameters is necessary only when the value of the parameter is different within the local con-
text of the macro definition as compared to its global value outside the macro definition.
Example:
The macro shown in this example generates a number of rotate instructions. The parameters passed in the macro
call determine the number of positions the accumulator is to be rotated and whether rotate right or rotate left
instructions are to be generated. Some typical calls for this macro are as follows:
SHIFTR
SHIFTR
'R',3
L,%COUNT-l
The second call shows an expression used as a parameter. This expression is to be evaluated immediately rather
than passed simply as text.
The definition of the SHIFTR macro is shown below. This macro uses the conditional IF directive to test the
validity of the first parameter. Also, the REPT macro directive is nested within the SHIFTR macro.
SHIFTR MACRO X,Y
IF X EQ 'R'
REPT Y
RAR
ENDM
ENDIF
IFXNE'L'
EXITM
ELSE
REPT Y
RAL
ENDM
ENDIF
ENDM
The indentation shown in the definition of the SHIFTR macro graphically illustrates the relationships of the IF,
ELSE, ENDIF directives and the REPT. ENDM directives. Such indentation is not required in your program, but
may be desirable as documentation.
5-15
Chapter 5. Macros
The SHI FTRllacro generates nothing if the first parameter is neither R nor L. Therefore, the following calls
produce no c(,de. The result in the object program is as though the SHIFTR macro does not appear in the
source program.
SHIFTR 5
SHIFTR 'B',2
The following call to the SHIFTR macro generates three RAR instructions:
SHIFTR 'R',3
Assume that, SET directive elsewhere in the source program has given COUNT the value 6. The following call
generates five RAL instructions:
SHIFTR 'L',%COUNT-1
The following is a redefinition of the SHIFTR macro. In this definition, notice that concatenation is used to
form the RAf: or RAL operation code. If a call to the SHIFTR macro specifies a character other than R or L,
illegal operati,m codes are generated. The assembler flags all illegal operation codes as errors.
NULL MACROS
SHIFTR MACRO
REPT
RA&X
ENDM
ENDM
X,y
Y
A macro may legally comprise only the MACRO and ENDM directives. Thus, the following is a legal macro
definition:
NADA MACRO
ENDM
P1,P2,P3,P4
A call to thiS macro produces no source code and therefore has no effect on the program.
Although thel e is no reason to write such a macro, the null (or empty) macro body has a practical application.
For example, all the macro prototype instructions might be enclosed With IF-ENDIF conditional directives.
When none 0', the specified conditions IS satisfied. all that remainS of the macro is the MACRO directive and
the ENDM di ·ective.
SAMPLE MACR05
The followin! sample macros further demonstrate the use of macro directives and operators.
5-16
Chapter 5. Macros
Example 1: Nested IRPC
The following macro definition contains a nested IRPC directive. Notice that the third operand of the outer
macro becomes the character string for the IRPC:
MOVE MACRO
IRPC
LHLD
SHLD
ENDM
ENDM
X,Y,l
PARAM,l
X&&PARAM
Y&&PARAM
Assume that the program contains the call MOVE SRC,DST,123. The third parameter of this call IS passed to
the IRPC. This has the same effect as coding IRPC PARAM,123. When expanded, the MOVE macro generates
the following source code:
LHLD SRCl
SHLD DSTl
LHLD SRC2
SHLD DST2
LHLD SRC3
SHLD DSn
Notice the use of concatenation to form labels in this example.
Example 2: Nested Macros Used to Generate DB Directives
This example generates a number of DB 0 directives, each With ItS own label. Two macros are used for this
purpose: INC and BLOCK. The INC macro is defined as follows:
INC MACRO Fl,F2
$ SAVE GEN
Fl&F2: DB 0 ;GENERATE LABELS & DB's
RESTORE
ENDM
The BLOCK macro, which accepts the number of DB's to be generated (NUMB) and a label prefix (PREFIX), is
defi ned as follows:
$
BLOCK MACRO
SAVE NOGEN
COUNT SET
REPT
COUNT SET
INC
ENDM
NUMB,PREFIX
o
NUMB
COUNT+l
PREFIX,%COUNT ;NESTED MACRO CALL
$ RESTORE
ENDM
5-17
Chapter 5. Macros
The macro ca I BLOCK 3.LAB generates the following source code:
LABl:
LAB2:
LAB3:
BLOCK
DB
DB
DB
3.LAB
o
o
o
The assemblet controls specified in these two macros (the lines beginning with $) are used to clean up the
assembly Iistit,g for easier reading. The source code shown for the call BLOCK 3.LAB is what appears in the
assembly listillg when the controls are used. Without the controls. the assembly listing appears as follows:
BLOCK 3.LAB
COUNT SET 0
REPT 3
COUNT SET COUNT+l
INC LAB.%COUNT
ENDM
COUNT SET COUNT+1
INC LAB.%COUNT
LAB1: DB 0
COUNT SET COUNT+l
INC LAB.%COUNT
LAB2: DB 0
COUNT SET COUNT+l
INC LAB.%COUNT
LAB3: DB 0
Example 3: " Macro that Converts Itself into a Subroutine
In some case5. the in-line coding substituted for each macro call imposes an unacceptable memory requirement.
The next thrEe examples show three different methods for converting a macro call into a subroutine call. The
first time the SBMAC macro is called. it generates a full in-line substitution which defines the SUBR subroutine.
Each subsequ;nt call to the SBMAC macro generates only a CALL instruction to the SUBR subroutine.
Within the fo.lowing examples. notice that the label SUBR must be global so that it can be called from outside
the first expa 1sion. This IS possible only when that part of the macro definition containing the global label is
called only Ollce in the entire program.
Method #1: i ~ e s t e d Macro Definitions
Macros can b" redefined during the course of a program. In the following example. the definition of SBMAC
contains its own redefinition as a nested macro. The first time SBMAC is called, it is full expanded. and the
redefinition of SBMAC replaces the original definition. The second time SBMAC IS called. only its redefinition
(a CALL inst"uction) is expanded.
5-18
SBMAC
SBMAC
LINK:
SUBR:
DUN:
MACRO
MACRO
CALL
ENDM
CALL
jMP
RET
ENDM
SUBR
SUBR
DUN
;;REDEFINITION OF SBMAC
Chapter 5. Macros
Notice that both versions of SBMAC contain CALL SUBR instructions. This is necessary to provide a return
address at the end of the SUBR routine. The jump instruction labelled LINK is required to prevent the SUBR
subroutine from executing a return to itself. Notice that the return address for the second CALL SUBR
instruction would be SUBR if the jump instruction were omitted. The j MP DUN instruction simply transfers
control past the end of the subroutine.
NOTE
The assembler allows the use of a source line consisting
only of a label. Such a label IS assigned to the next source
line for which code or data is generated. Notice that
neither code nor data is generated for an ENDM directive,
so the label DUN is assigned to whatever instruction follows
the ENDM directive. This construct is required because the
ENDM directive itself may not be given a label.
Method #2: Conditional Assembly
The second method for altering the expansion of the SBMAC macro uses conditional assembly. In this example,
a switch (FI RST) is set TRUE just before the first call for SBMAC. SBMAC is defined as follows:
TRUE EQU OFFH
FALSE EQU 0
FIRST SET TRUE
SBMAC MACRO
CALL SUBR
IF FIRST
FIRST SET FALSE
LINK: jMP DUN
SUBR:
RET
DUN:
ENDIF
ENDM
5-19
Chapter 5. Macros
The first call 0 SBMAC expands the full definition, including the call to and definition of SUBR:
LINK:
SUBR:
DUN:
SBMAC
CALL
IF
JMP
RET
ENDIF
SUBR
FIRST
DUN
Because FI RS r is TRUE when encountered during the first expansion of SBMAC, all the statements between
IF and ENDI!' are assembled into the program. In subsequent calls, the conditionally-assembled code is skipped
so that the sUJroutine is not regenerated. Only the following expansion is produced:
SBMAC
CALL
IF
Method #3: :onditlonal Assembly with EXITM
SUBR
FIRST
The third met hod for altering the expansion of SBMAC also uses conditional assembly. but uses the EXITM
directive to Sl ppress unwanted macro expansion after the first call. EXITM is effective when FIRST is FALSE,
which it is aft er the first call to SBMAC.
TRUE
FALSE
FIRST
SBMAC
FIRST
EQU OFFH
EQU 0
SET TRUE
MACRO
CALL SUBR
IF NOT FIRST
EXITM
ENDIF
SET FALSE
JMP DUN
SUBR:
RET
DUN:
ENDM
5-20
Chapter 5. Macros
Example 4: Computed GOTO Macro
This sample macro presents an implementation of a computed GOTO for the 8080 or 8085. The computed
GOTO, a common feature of many high level languages, allows the program to jump to one of a number of
different locations depending on the value of a variable. For example, if the variable has the value zero, the
program jumps to the first item In the list; if the variable has the value 3, the program jumps to the fourth
address In the list.
In this example, the variable IS placed in the accumulator. The list of addresses is defined as a series of DW
directives starting at the symbolic address TABLE. This macro (TJUMP) also modifies itself with a nested
definition. Therefore, only the first call to the TJ UMP macro generates the calculated GOTO routine. Subse-
quent calls produce only the jump instruction JMP TJCODE.
TJUMP
TJCODE:
TJUMP
MACRO
ADD
MVI
MOV
DAD
MOV
INX
MOV
XCHG
PCHL
MACRO
JMP
ENDM
ENDM
;JUMP TO A-TH ADDR IN TABLE
A ;MULTIPLY A BY 2
D,O ;CLEAR DREG
E,A ;GET TABLE OFFSET INTO D&E
D ;ADD OFFSET TO TABLE ADDR IN H&L
E,M ;GET 1ST ADDRESS BYTE
H
D,M ;GET 2ND ADDRESS BYTE
;J UMP TO ADDRESS
;REDEFINE TJUMP TO SAVE CODE
TJCODE ;NEXT CALL JUMPS TO ABOVE CODE
Notice that the definition of the TJ UMP macro does not account for loading the address of the address table
into the Hand L registers; the user must load this address just before calling the TJ UMP macro. The following
shows the coding for the address table (TABLE) and a typical call sequence for the TJ UMP macro:
TABLE:
MVI
LXI
TJUMP
DW
DW
DW
A,2
H,TABLE
LOCO
LOC1
LOC2
The call sequence shown above causes a lump to LOC2.
5-21
Chapter 5. Macros
Example 5: Using IRP to Define the Jump Table
The TJ UMP macro becomes even more useful when a second macro (GOTOl IS used to define the jump table,
load the addr"ss of the table Into the Hand L registers, and then call TJ UMP, The GOTO macro is defined as
follows:
INDEX,L1ST
JTABLE
INDEX
H,JTABLE
GOTO
)TABLE:
MACRO
LOCAL
LDA
LXI
TJUMP
IRP
DW
ENDM
ENDM
;LOAD ACCUM WITH INDEX
;LOAD H&L WITH TABLE ADDRESS
;CALL TJUMP MACRO
FORMAL,(L1ST>
FORMAL ;SET UP TABLE
A typical call to the GOTO macro would be as follows:
GOTO CASE,(COUNT,TIMER,DATE,PTDRVR>
This call to He GOTO macro builds a table of DW directives for the labels COUNT, TIMER, DATE, and
PTDRVR. It hen loads the base address of the table into the Hand L registers and calls the Tj UMP macro.
If the value o' the variable CASE is 2 when the GOTO macro is called, the GOTO and TJ UMP macros
together causl a jump to the address of the DATE routine.
Notice that allY number of addresses may be specified in the list for the GOTO routine as long as they all fit
on a single so Jrce line. Also, the GOTO macro may be called any number of times, but only one copy of the
coding for thl TjUMP is generated since the TJUMP macro redefines itself to generate only a jMP TjCODE
instruction.
5-22
6. PROGRAMMING TECHNIQUES
This chapter describes some techniques that may be of help to the programmer.
BRANCH TABLES PSEUDO-SUBROUTINE
Suppose a program consists of several separate routines. any of which may be executed depending upon some
initial condition (such as a number passed In a register). One way to code this would be to check each condition
sequentially and branch to the routines accordingly as follows:
CONDITION =CONDITION ]I
IF YES BRANCH TO ROUTINE 1
CONDITION = CONDITION 2?
IF YES BRANCH TO ROUTINE 2
BRANCH TO ROUTINE N
A sequence as above is inefficient. and can be improved by using a branch table.
The logic at the beginning of the branch table program loads the starting address of the branch table into the H
and L registers. The branch table itself consists of a list of starting addresses for the routines to be branched to.
Using the Hand L registers as a pointer. the branch table program loads the selected routine's starting address
into the program counter. thus effecting a jump to the desired routine. For example. consider a program that
executes one of eight routines depending on which bit of the accumulator is set:
Jump to routine 1 if the accumulator holds 00000001
2 ..
3 ....
4" If
5 II lJ
6 II "
7" "
8 II II
.. 00000010
.. 00000100
.. 00001000
.. 00010000
.. 00100000
.. 01000000
.. 10000000
A program that provides such logic follows. The program is termed a 'pseudo-subroutine' because it IS treated as a
subroutine by the programmer (i.e.• it appears just once in memory), but is entered via a regular JUMP instruction
rather than via a CALL Instruction.
6-1
Chapter 6. Programming Techniques
Main Pre gram
I
normal subroutine return
sequence not followed by
branch table program
6-2
Branch Table
Program
Jump
Routines
Chapter 6. Programming Techniques
Label Code Operand
START: LXI H.BTBL ;REGISTERS HAND L WILL
;POINT TO BRANCH TABLE
GTBIT: RAR
jC GETAD
INX H ;(H.L)=(H,L)+2 TO
INX H ;POINT TO NEXT ADDRESS
;IN BRANCH TABLE
JMP GTBIT
GETAD: MOV E,M ;BIT FOUND
INX H ;LOAD JUMP ADDRESS
;INTO D AND E REGISTERS
MOV D.M
XCHG ;EXCHANGE D AND E
;WITH HAND L
PCHL ;JUMP TO ROUTINE
;ADDRESS
BTBL: DW
DW
DW
DW
DW
DW
DW
DW
ROUTl
ROUT2
ROUTJ
ROUT4
ROUTS
ROUT6
ROUT7
ROUT8
;BRANCH TABLE. EACH
:ENTRY IS A TWO-BYTE
;ADDRESS
;HELD LEAST SIGNIFICANT
;BYTE FIRST
The control routine at START uses the Hand L registers as a pointer into the branch table (BTBL) corresponding
to the bit of the accumulator that is set. The rdutine at GETAD then transfers the address held In the corres-
ponding branch table entry to the Hand L registers via the D and E registers. and then uses a PCH L Instruction.
thus transferring control to the selected routine.
TRANSFERRING DATA TO SUBROUTINES
A subroutine typically requires data to perform its operations. In the simplest case. this data may be transferred
In one or more registers.
Sometimes it is more convenient and economical to let the subroutine load its own registers. One way to do this
is to place a list of the required data (called a parameter list) in some data area of memory. and pass the address
of this list to the subroutine in the Hand L registers.
6-3
Chapter 6. Programming Techniques
For example, the subroutine ADSUB expects the address of a three-byte parameter list in the Hand L registers.
It adds the fiJ st and second bytes of the list, and stores the result in the third byte of the list:
Label
RET1:
'LIST
RET2:
L1ST2:
PDSUB:
Code Operand Comment
LXI H.PLlST ;LOAD HAND L WITH
;ADDRESSES OF THE PARAM-
;ETER LIST
CALL ADSUB ;CALL THE SUBROUTINE
DB 6 ;FIRST,NUMBER TO BE ADDED
DB 8 ;SECOND NUMBER TO BE
;ADDED
DS 1 ;RESULT WILL BE STORED HERE
LXI H.L1ST2 ;LOAD HAND L REGISTERS
CALL ADSUB ;FOR ANOTHER CALL TO ADSUB
DB 10
DB 35
DS 1
MOV A,M ;GET FIRST PARAMETER
INX H ;INCREMENT MEMORY
;ADDRESS
MOV B.M ;GET SECOND PARAMETER
ADD B ;ADD FIRST TO SECOND
INX H ;INCREMENT MEMORY
;ADDRESS
MOV M,A ;STORE RESULTAT THI RD
;PARAMETER STORE
RET ;RETURN UNCONDITIONALLY
The first time ADSUB is called, it loads the A and B registers from PLiST and PLlST+1 respectively, adds them,
and stores tr e result in PLiST+2. Return is then made to the instruction at RET1.
6-4
Chapter 6. Programming Techniques
First call to ADSUB:
06 PLIST
08 PLlST+l
OEH PLlST+2
The second time ADSUB IS called, the Hand L registers POint to the parameter list L1ST2. The A and B
registers are loaded with 10 and 35 respectively, and the sum is stored at L1ST2+2. Return is then made to
the Instruction at RET2.
Note that the parameter lists PLIST and L1ST2 could appear anywhere in memory without altering the results
produced by ADSUB.
This approach does have its limitations, however. As coded, ADSUB must receive a list of two and only two
numbers to be added, and they must be contiguous in memory. Suppose we wanted a subroutine (GENAD)
which would add an arbitrary number of bytes, located anywhere in memory. and leave the sum in the accumu-
lator.
This can be done by passing the subroutine a parameter list which is a list of addresses of parameters, rather
than the parameters themselves. and signifying the end of the parameter list be a number whose first byte is
FFH (assuming that no parameters will be stored above address FFOOH).
Call to GENAD:
GENAD:
D
H L
ADRl
ADR2
ADR3
ADR4
FFFF
PARMl
PARM4
PARM3
PARM2
As implemented below, GENAD saves the current sum (beginning with zero) in the C register. It then loads the
address of the first parameter into the D and E registers. If this address is greater than or equal to FFOOH, it
reloads the accumulator with the sum held in the C register and returns to the calling routine. Otherwise, it
6-5
Chapter 6. Programming Techniques
loads the panmeter into the accumulator and adds the sum in the C register to the accumulator. The routine
then loops b:,ck to pick up the remaining parameters.
Label
PLlST:
PA.RM1 :
PARM4:
FARM3:
Code
LXI
CALL
HALT
DW
DW
DW
DW
DW
DB
DB
DB
Operand
H,PLlST
GENAD
PARM1
PARM2
PARM3
PARM4
OFFFFH
6
16
13
Comment
;LOAD ADDRESS OF
;PARAMETER ADDRESS LIST
;L1ST OF PARAMETER ADDRESSES
;TERMINATOR
6-6
FARM2: DB 82
GENAD: XRA A ;CLEAR ACCUMULATOR
LOOP: MOV C,A ;SAVE CURRENT TOTAL IN C
MOV E,M ;GET LOW ORDER ADDRESS BYTE
;OF FIRST PARAMETER
INX H
MOV A,M ;GET HIGH ORDER ADDRESS BYTE
;OF FIRST PARAMETER
CPI OFFH ;COMPARE TO FFH
jZ BACK ;IF EQUAL, ROUTINE IS COMPLETE
MOV D,A ;D AND E NOW ADDRESS PARAMETER
LDAX D ;LOAD ACCUMULATOR WITH PARAMETER
ADD C ;ADD PREVIOUS TOTAL
INX H ;INCREMENT HAND L TO POINT
;TO NEXT PARAMETER ADDRESS
JMP LOOP ;GET NEXT PARAMETER
BACK: MOV A,C ;ROUTINE DONE - RESTORE TOTAL
RET ;RETURN TO CALLING ROUTINE
END
Chapter 6. Programmmg Techniques
Note that GENAD could add any combination of the parameters with no change to the parameters themselves.
The sequence:
PUST:
LXI
CALL
DW
DW
DW
H,PLlST
GENAD
PARM4
PARMl
OFFFFH
would cause PARMl and PARM4 to be added, no matter where in memory they might be located (excluding
addresses above FFOOH).
Many variations of parameter passing are possible. For example, if it IS necessary to allow parameters to be
stored at any address, a calling program can pass the total number of parameters as the first parameter; the
subroutine then loads this first parameter into a register and uses It as a counter to determine when all param-
eters had been accepted.
SOFTWARE MULTIPLY AND DIVIDE
The multiplication of two unsigned 8-bit data bytes may be accomplished by one of two techniques: repetitive
addition, or use of a register shifting operation.
Repetitive addition provides the simplest, but slowest, form of multiplication. For example, 2AH*74H may be
generated by adding 74H to the (initially zeroed) accumulator 2AH times.
Shift operations provide faster multiplication. Shifting a byte left one bit is equivalent to multiplying by 2, and
shifting a byte right one bit IS equivalent to dividing by 2. The following process will produce the correct 2-byte
result of multiplying a one byte multiplicand by a one byte multiplier:
A. Test the least significant bit of multiplier. If zero, go to step b. If one, add the
multiplicand to the most significant byte of the result.
B. Shift the entire two-byte result right one bit position.
C. Repeat steps a and b until all 8 bits of the multiplier have been tested.
For example, consider the multiplication: 2AH*3CH=9D8H
Step 1:
Step 2:
Step 3:
Test multiplier O-bit; it is 0, so shift 16-bit result right one bit.
Test multiplier l-bit; it is 0, so shift 16-bit result right one bit.
Test multiplier 2-blt; it is 1, so add 2AH to high-order byte of result and shift 16-bit
result right one bit.
6-7
Chapter 6. Programming Techniques
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Test multiplier 3-bit; it is 1, so add 2AH to high-order byte of result and shift 16-bit
result right one bit.
Test multiplier 4-bit; it is 1, so add 2AH to high-order byte of result and shift 16-bit
result right one bit.
Test multiplier 5-bit; it is 1, so add 2AH to high-order byte of result and shift 16-bit
result right one bit.
Test multiplier 6-bit; it is 0, so shift 16-bit result right one bit.
Test multiplier 7-bit; it is 0, so shift 16-bit result right one bit.
The result produced is 09D8.
HIGH-ORDER BYTE LOW-0RDER BYTE
MULTIPLIER MULTIPLICAND OF RESULT OF RESULT
Start 00111100(3C) 00101010(2A) 00000000 00000000
Step 1 a
b 00000000 00000000
Step 2 a
b 00000000 00000000
Step 3 a . '>.,., ..•. , , 00101010 00000000
b 00010101 00000000
Step 4 a . . . . , ... 00111111 00000000
b 00011111 10000000
Step 5 a ".,." . ".' .. "" ,
01001001 10000000
b 00100100 11000000
Step 6 a ..
"""" ..
01001110 11000000
b 00100111 01100000
Step 7 a .
'" 0 .• '··· •• ,
b 00010011 10110000
Step 8 a . ..0 . . .
b 00001001 11 011 000(9D8)
Since the mliitiplication routine described above uses a number of important programming techniques, a sample
program IS g ven with comments.
The prograrr uses the B register to hold the most significant byte of the result. and the C register to hold the
least signific,Lnt byte of the result. The 16-bit right shift of the result is performed in the accumulator by two
rotate-right-! hrough -carry instructions.
6-8
Chapter 6. Programming Techniques
Zero carry and then rotate B:
B
[
I ~ ~ 0
___I
Then rotate C to complete the shift:
C
D
B
D
C
' I ~ b
Register D holds the multiplicand. and register C originally holds the multiplier.
MULT: MVI B.O ;INITIALIZE MOST SIGNIFICANT BYTE
;OF RESULT
MVI E,9 ;BIT COUNTER
MULTO: MOV A,C ;ROTATE LEAST SIGNIFICANT BIT OF
RAR ;MULTIPLIER TO CARRY AND SHIFT
MOV C,A ;LOW-ORDER BYTE OF RESULT
DCR E
JZ DONE ;EXIT IF COMPLETE
MOV A.B
JNC MULT1
ADD D ;ADD MULTIPLICAND TO HIGH-
;ORDER BYTE OF RESULT IF BIT
;WAS A ONE
MULT1: RAR ;CARRY=O HERE SHIFT HIGH-
;ORDER BYTE OF RESULT
MOV BA
JMP MULTO
DONE:
An analogous procedure is used to divide an unsigned 16-bit number by an unsigned 16-bit number. Here, the
process involves subtraction rather than addition, and rotate-left instructions instead of rotate-right instructions.
6-9
Chapter 6. Programming Techniques
The followin: reentrant program uses the Band C registers to hold the dividend and quotient, and the D and E
register to held the divisor and remainder. The Hand L registers are used to store data temporarily.
DIV:
DVO:
DV1:
MOV A,D
CMA
MOV D,A
MOV A,E
CMA
MOV E,A
INX D
LXI H,O
MVI A,17
PUSH H
DAD D
JNC DVl
XTHL
POP H
PUSH PSW
MOV A,C
RAL
MOV C,A
MOV A,B
RAL
MOV BA
MOV A,L
RAL
MOV L,A
MOV A,H
RAL
MOV H,A
POP PSW
DCR A
JNZ DVO
:NEGATE THE DIVISOR
:FOR TWO'S COMPLEMENT
;IN ITIAL VALUE FOR REMAINDER
;INITIALIZE LOOP COUNTER
;SAVE REMAINDER
;SUBTRACT DIVISOR (ADD NEGATIVE)
:UNDER FLOW, RESTORE HL
:SAVE LOOP COUNTER (A)
;4 REGISTER LEFT SHIFT
;WITH CARRY
;CY->C->B->L->H
:RESTORE LOOP COUNTER (A)
;DECREMENT IT
:KEEP LOOPING
;POST·DIVIDE CLEAN UP
:SHIFT REMAINDER RIGHT AND RETURN IN DE
ORA A
MOV A.H
RAR
MOV D,A
MOV A,L
RAR
MOV E,A
RET
END
6·10
Chapter 6. Programming Techniques
MULTI BYTE ADDITION AND SUBTRACTION
The carry flag and the ADC (add with carry) instructions may be used to add unsigned data quantities of
arbitrary length. Consider the following addition of two three-byte unsigned hexadecimal numbers:
32AF8A
+84BA90
B76A1A
To perform this addition, add to the low-order byte uSing an ADD instruction. ADD sets the carry flag for use
in subsequent instructions, but does not Include the carry flag in the addition. Then use ADC to add to all
higher order bytes.
3n
84
B7 I
carry = 1 ...J
~
BA
6A
8A
90
i
1A
carry = 1.J
The following routine will perform this multibyte addition, making these assumptions:
The E register holds the length of each number to be added (in this case, 3).
The numbers to be added are stored from low-order byte to high-order byte beginning at memory locations
FI RST and SECND, respectively.
The result will be stored from low-order byte to high-order byte beginning at memory location FIRST, replacing
the original contents of these locations.
MEMORY
LOCATION before after
FIRST 8A
--+
,.
lA
~ carry
--t
FIRST+l AF
+--
6A
~ carry
FIRSTt2 32 +-liI>- B7
SECND
SECND+l
SECND+2
90
BA
84
90
BA
84
6-11
Chapter 6. Programming Techniques
The followin: routine uses an ADC instruction to add the low-order bytes of the operands. This could cause
the result to be high by one if the carry flag were left set by some previous instruction. This routine avoids
the problem Jy clearing the carry flag with the XRA instruction just before LOOP.
Label
I ~ A D D :
LOOP:
DONE:
FIRST
~ E C N D :
Code Operand Comment
LXI B,FIRST ;B AND C ADDRESS FIRST
LXI H,SECND ;H AND L ADDRESS SECND
XRA A ;CLEAR CARRY FLAG
LDAX B ;LOAD BYTE OF FIRST
ADC M ;ADD BYTE OF SECND
;WITH CARRY
STAX B ;STORE RESULT AT FIRST
DCR E ;DONE IF E = 0
JZ DONE
INX B ;POINT TO NEXT BYTE OF
;FIRST
INX H ;POINT TO NEXT BYTE OF
;SECND
JMP LOOP ;ADD NEXT TWO BYTES
DB 90H
DB OBAH
DB 84H
DB 8AH
DB OAFH
DB 32H
Since none cf the instructions in the program loop affect the carry flag except ADC, the addition with carry will
proceed cornctly.
When locaticn DONE is reached. bytes FIRST through FIRST+2 will contain 1A6AB7, which is the sum shown
at the beginldng of this section arranged from low-order to high-order byte.
In order to (reate a multibyte subtraction routine, it is necessary only to duplicate the multibyte addition routine
of this sectic n, changing the ADC instruction to an SBB instruction. The program will then subtract the number
beginning at SECND from the number beginning at FIRST, placing the result at FIRST.
DECIMAL ADDIlION
Any 4-bit d, ta quantity may be treated as a decimal number as long as it represents one of the decimal digits
from 0 throllgh 9, and does not contain any of the bit patterns representing the hexadecimal digits A through F.
In order to preserve this decimal interpretation when performing addition, the value 6 must be added to the
4-bit quantily whenever the addition produces a result between 10 and 15. This is because each 4-bit data
quantity car hold 6 more combinations of bits than there are decimal digits.
6-12
Chapter 6. Programming Techniques
Decimal addition is performed by letting each 8-bit byte represent two 4-bit decimal digits. The bytes are
summed In the accumulator in standard fashion, and the DAA (decimal adiust accumulator) instruction is then
used to convert the 8-bit binary result to the correct representation of 2 decimal digits. For multibyte strings,
you must perform the decimal adiust before adding the next higher-order bytes. This is because you need the
carry flag setting from the DAA instruction for adding the higher-order bytes.
To perform the decimal addition:
2985
+4936
7921
the process works as follows:
1. Clear the Carry and add the two lowest-order digits of each number (remember that each 2
decimal digits are represented by one byte).
85 = 10000101 B
36 = 00110110B
carry 0
Q]10111011B
Carry = 0 ~ ~ Auxiliary Carry = 0
The accumulator now contains OBBH.
2. Perform a DAA operation. Since the rightmost four bits are greater than 9, a 6 is added to the
accumulator.
Accumulator = 10111011 B
6 = 0110B
11000001 B
Since the leftmost bits are greater than 9. a 6 is added to these bits, thus setting the carry flag_
Accumulator = 11000001 B
6=0110 B
/]00100001B
Carry flag = 1
The accumulator now contains 21 H. Store these two digits.
6-13
Chapter 6. Programming Techniques
3, Add the next group of two digits:
29 = 001 01 001 B
49 = 01001001B
carry
.Q] 0111 0011 B
Carry = 0 Carry = 1
The accumulator now contains 73H.
Perform a DAA operation. Since the auxiliary carry flag is set. 6 is added to the accumulator.
Accumulator = 01110011 B
6 = 0110B
/QlOl111001B
Carry flag = 0
Since the leftmost 4 bits are less than 10 and the carry flag is reset, no further action occurs.
Thus, the correct decimal result 7921 IS generated in two bytes.
A routine wlich adds decimal numbers, then, IS exactly analogous to the multibyte addition routine MADD of
the last sect on, and may be produced by Inserting the instruction DAA after the ADC M instruction of that
example.
Each iteration of the program loop will add two decimal digits (one byte) of the numbers.
DECIMAL SUBTltACTION
DeCimal subtraction is considerably more complicated than decimal addition. In general, the process consists of
generating tle tens complement of the subtrahend digit, and then adding the result to the minuend digit. For
example, to subtract 34 from 56, form the tens complement of 34 (99-34=65+1=66), Then, 56+66=122. By
truncating eff the carry out of the high order digit, we get 22, the correct result.
The problerl of handling borrows arises in multibyte deCimal subtractions. When no borrow occurs from a sub-
tract, you v'ant to use the tens complement of the subtrahend for the next operation. If a borrow does occur,
you want t,. use the nines complement of the subtrahend.
Notice that the meaning of the carry flag IS Inverted because you are dealing with complemented data. Thus, a
one bit in tle carry flag Indicates no borrow: a zero bit In the carry flag indicates a borrow. This inverted carry
flag setting :an be used in an add operation to form either the nines or tens complement of the subtrahend.
6-14
Chapter 6. Programming Techniques
The detailed procedure for subtracting multi-digit decimal numbers is as follows:
1. Set the carry flag = 1 to indicate no borrow.
2. Load the accumulator with 99H, representing the number 99 decimal.
3. Add zero to the accumulator with carry, producing either 99H or 9AH, and resetting the
carry flag.
4. Subtract the subtrahend digits from the accumulator. producing either the nines or tens
complement.
5. Add the minuend digits to the accumulator.
6. Use the DAA instruction to make sure the result In the accumulator is In decimal format, and
to indicate a borrow in the carry flag if one occurred.
7. If there are more digits to subtract, go to step 2. Otherwise. stop.
Example:
Perform the decimal subtraction:
43580
-13620
29960
1. Set carry = 1.
2. Load accumulator with 99H.
3. Add zero with carry to the accumulator, producing 9AH.
Accumulator = 100110018
= 000000008
Carry
100110108 =9AH
4. Subtract the subtrahend digits 62 from the accumulator.
Accumulator =100110108
62 =1001111 08
] 001110008
6-15
Chapter 6. Programming -rechniques
5. Add the minuend digits 58 to the accumulator.
Accumulator =00111 OOOB
58 = 01011 OOOB
Q] 1001 OOOOB =90H
Carry = 0 ~ 'AUXiliarY Carry = 1
6. DAA converts accumulator to 96 (since Auxiliary Carry =1) and leaves carry flag =0
Indicating that a borrow occurred.
7 Load accumulator with 99H.
8. Add zero with carry to accumulator. leaving accumulator = 99H.
9. Subtract the subtrahend digits 13 from the accumulator.
Accumulator = 10011 001 B
13= 11101101B
1] 10000110B
10. Add the minuend digits 43 to the accumulator.
Accumulator = 1000011 OB
43 = 01000011 B
~ ~ 11001001B = C9H
Carry = 0 'AUXiliary Carry = 0
11 DAA converts accumulator to 29 and sets the carry flag = 1. indicating no borrow occurred.
Therefore, the result of subtracting 1362 from 4358 is 2996.
The followinl. subroutine will subtract one 16-digit decimal number from another using the following assumptions:
The minuend IS stored least significant (2) digits first beginning at location MINU.
The subtrahe ld IS stored least significant (2) digits first beginning at location SBTRA.
The result will be stored least significant (2) digits first, replacing the minuend.
6-16
Chapter 6. Programming Techniques
Label Code Operand Comment
DSUB: LXI D,MINU ;D AND E ADDRESS MINUEND
LXI H,SBTRA ;H AND L ADDRESS SUBTRA-
;HEND
MVI C,8 ;EACH LOOP SUBTRACTS 2
;DIGITS (ONE BYTE),
;THEREFORE PROGRAM WILL
;SUBTRACT 16 DIGITS.
STC ;SET CARRY INDICATING
;NO BORROW
LOOP: MVI A,99H ;LOAD ACCUMULATOR
;WITH 99H.
ACI 0 ;ADD ZERO WITH CARRY
SUB M ;PRODUCE COMPLEMENT
;OF SUBTRAHEND
XCHG ;SWITCH D AND E WITH
;H AND L
ADD M ;ADD MINUEND
DAA ;DECIMAL ADJUST
;ACCUMULATOR
MOV M,A ;STORE RESULT
XCHG ;RESWITCH D AND E
;WITH HAND L
DCR C ;DONE IF C = 0
JZ DONE
INX D ;ADDRESS NEXT BYTE
;OF MINUEND
INX H ;ADDRESS NEXT BYTE
;OF SUBTRAHEND
JMP LOOP ;GET NEXT 2 DECIMAL DIGiTS
DONE: NOP
6-17
7. INTERRUPTS
INTERRUPT CONCEPTS
The following is a general description of interrupt handling and applies to both the 8080 and 8085 processors.
However, the 8085 processor has some additional hardware features for interrupt handling. For more infor-
mation on these features, see the description of the 8085 processor in Chapter 1 and the descriptions of the
RIM, SIM, and RST instructions in Chapter 3.
Often, events occur external to the central processing unit which require immediate action by the CPU. For
example, suppose a device is sending a string of 80 characters to the CPU, one at a time, at fixed intervals.
There are two ways to handle such a situation:
A. A program could be written which accepts the first character, waits until the next character is
ready (e.g., executes a timeout by incrementing a sufficiently large counter), then accepts the
next character, and proceeds in this fashion until the entire 80 character string has been received.
This method is referred to as programmed Input/Output.
B. The device controller could interrupt the CPU when a character is ready to be input, forcing a
branch from the executing program to a special interrupt service routine.
The interrupt sequence may be illustrated as follows:
INTERRUPT
Normal
Program
Execution
Interrupt Service
Routine
Program
Execution
Continues
7-1
Chapter 7. Interrupts
The 8080 cor tains a bit named INTE which may be set or reset by the instructions EI and DI described in
Chapter 3. Wilenever INTE is equal to 0, the entire interrupt handling system is disabled, and no interrupts
will be accepl ed.
When the 8010 recognizes an interrupt request from an external device, the following actions occur:
1. The instruction currently being executed is completed.
2. The interrupt enable bit. INTE, is reset = O.
3. The interrupting device supplies. via hardware. one instruction which the CPU executes. This
instruction does not appear anywhere in memory, and the programmer has no control over it,
since it is a function of the interrupting device's controller design. The program counter is not
incremented before this instruction.
The Instruction supplied by the interrupting device is normally an RST instruction (see Chapter 3), since this
is an efficienl one byte call to one of 8 eight-byte subroutines located in the first 64 words of memory. For
instance, the jevice may supply the instruction:
RST OH
with each in, ut interrupt. Then the subroutine which processes data transmitted from the deVice to the CPU
will be called into execution via an eight-byte instruction sequence at memory locations OOOOH to 0007H.
A digital inplt device may supply the instruction:
RST 1H
Then the sub'outine that processes the digital input signals will be called via a sequence of instructions
occupying m"mory locations 0008H to OOOFH.
7-2
d
Transfers
OH c_o_n_t_ro_l_t_o 0000
0007
Device
d
" T_ra_n_s_fe_r_s .-
control to
• 0008
supplie, RST 1H OOOF
}
Beginning of
subroutine for
device 'a'
I Beginning of
J
subroutine for
device 'b'
Chapter 7. Interrupts
Device 'x'
supplies RST 7H
Transfers
control to
0038
003F
}
Beginning of
subroutine for
device 'x'
Note that any of these 8-byte subroutines may in turn call longer subroutines to process the interrupt, if
necessary.
Any device may supply an RST instruction (and indeed may supply anyone-byte 8080 instruction).
The following is an example of an Interrupt sequence:
A
B
C
INSTRUCTION
~ ~ ~ ~ ' 1 ~ {,o",,"p<f,om D,,'ce ,
ARBITRARY
MEMOR Y ADDRESS
Device 1 supplies
RST OH
Program Counter =
3COC pushed onto
Ithe stack.
Control transferred to
.j to 0000
0000 '0"'",';00 ,/
Instruction 2
RET
t
Stack popped into
program counter
3COB
~ 3 C O C
I
Device 1 signals an interrupt as the CPU is executing the instruction at 3COB. This instruction is completed.
The program counter remains set to 3COC. and the instruction RST OH supplied by device 1 is executed.
Since this is a call to location zero. 3COC is pushed onto the stack and program control is transferred to
location OOOOH. (This subroutine may perform jumps, calls, or any other operation.) When the RETURN is
executed, address 3COC is popped off the stack and replaces the contents of the program counter, causing
execution to continue at this point.
7-3
Chapter 7. Interrupts
WRITING INTERRJPT SUBROUTINES
In general, anI registers or condition bits changed by an Interrupt subroutine must be restored before returning
to the interrurted program, or errors will occur.
For example, . uppose a program is interrupted lust prior to the instruction:
JC LOC
and the carry Jlt equals 1, If the interrupt subroutine happens to reset the carry bit before returning to the
Interrupted pngram, the jump to LOC which should have occurred will not, causing the interrupted program
to produce err Jneous results.
Like any othe subroutine then, any interrupt subroutine should save at least the condition bits and restore them
before perfornling a RETURN operation. (The obVIOUS and most convenient way to do this IS to save the data
In the stack, u,lng PUSH and POP operations.)
Further, the II terrupt enable system is automatically disabled whenever an Interrupt is acknowledged. Except in
special cases, 1herefore, an interrupt subroutine should include an EI instruction somewhere to permit detection
and handling (of future interrupts. One instruction after an EI is executed, the interrupt subroutine may itself be
Interrupted. T lis process may continue to any level, but as long as all pertinent data are saved and restored,
correct progra n execution will continue automatically,
A typical intel rupt subroutine, then, could appear as follows:
74
Code
PUSH
EI
POP
RET
Operand
PSW
PSW
Comment
;SAVE CONDITION BITS AND ACCUMULATOR
;RE-ENABLE INTERRUPTS
;PERFORM NECESSARY ACTIONS TO SERVICE
;THE INTERRUPT
;RESTORE MACHINE STATUS
;RETURN TO INTERRUPTED PROGRAM
APPENDIX A. INSTRUCTION SUMMARY
This appendix summarizes the bit patterns and number of time states associated with every 8080 CPU
instruction. The instructions are listed in both mnemonic (alphabetical) and operation code (numerical)
sequence.
When USing this summary, note the following symbology
DDD represents a destination register. SSS represents a source register. Both DDD and SSS are interpreted
as follows:
DDD or SSS
000
001
010
011
100
101
110
111
Interpretation
Register B
Register C
Register D
Register E
Register H
Register L
A memory register or stack pointer or PSW
(flags + accumulator)
The accumulator
Instruction execution time equals number of time periods multiplied by the duration of a time period.
A time period may vary from 480 nanoseconds to 2 microseconds on the 8080 or 320 nanoseconds to 2
microseconds on the 8085. Where two numbers of time periods are shown (eq.5/11), it means that the
smaller number of time periods is required if a condition is not met, and the larger number of time periods
is required if the condition IS met.
NUMBER OF TIME PERIODS
MNEMONIC D
7
D
6
D
5
D
4
D
3
D
2
D
1
DO
8080 8085
CALL 1 1 0 0 1 1 0 1 17 18
I
!
CC 1 1 0 1 1 1 0 0 11/17 9/18
CNC
I
1 I 0 1 0 1 0 0 11/17 9/18
CZ 1 1 0 0 1 1 0 0 11/17 9/18
CNZ 1 1 0 0 0 1 0 0 11/17 9/18
CP 1 1 1 1 0 1 0 0 11/17 9/18
CM 1 1 1 1 1 1 0 0 11/17 9/18
CPE 1 1 1 0 1 1 0 0 11/17 9/17
CPO 1 1 1 0 0 1 0 0 11/17 9/18
RET 1 1 0 0 1 0 0 1 10 10
RC 1 1 0 1 1 0 0 0 5/11 6/12
RNC 1 1 0 1 0 0 0 0 5/11 6/12
RZ 1 1 0 0 1 0 0 0 5/11 6/12
ALL MNEMONICS©7974, 7975, 7976, 7977 INTEL CORPORATION
A-l
Appendix A. Instruction 5ummary
NUMBER OF TIME PERIODS
MNEMONIC D
7
D
6
D
5
D
4
D
3
D
2
D
1
DO
8080 8085
RNZ 1 1 0 0 0 0 0 0 5/11 6/12
RP 1 1 1 1 0 0 0 0
I
5/11 6/12
RM 1 1 1 1 1 0 0 0 5/11 6/12
RPE 1 1 1 0 1 0 0 0 5/11 6/12
RPO 1 1 1 0 0 0 0 0 5/11 6/12
RST 1 1 A A A 1 1 1 11 12
IN 1 1 0 1 1 0 1 1 10 10
OUT 1 1 0 1 0 0 1 1 10 10
LXI B 0 0 0 0 0 0 0 1 10 10
LXI D 0 0 0 1 0 0 0 1 10 10
LXI H 0 0 1 0 0 0 0 1 10 10
LXI SP 0 0 1 1 0 0 0 1 10 10
PUSH B 1 1 0 0 0
I
1 0 1 11 12
PUSH D 1 1 0 1 0 1 0 1 11 12
PUSH H 1 1 1 0 0 1 0 1 11 12
PUSH PSW 1 1 1 1 0
1 0 1 11 12
POP B 1 1 0 0 0 0 0 1 10 10
POP D 1 1 0 1 0 0 0 1 10 10
POP H 1 1 1 0 0 0 0 1 10 10
POP PSW 1 1 1 1 0 0 0 1 10 10
STA 0 0 1 1
I
0 0 1 0 13 13
LDA 0 0 1 1 1 0 1 0 13 13
XCHG 1 1 1 0 1 0 1 1 4 4
XTHL 1 1 1 0 0 0 1 1 18 16
SPHL 1 1 1 1 1 0 0 1 5 6
PCHL 1 1 1 0 1 0 0 1 5 6
DAD B 0 0 0 0 1 0 0 1 10 10
DAD D 0 0 0 1 1 0 0 1 10 10
DAD H 0 0 1 0 1 0 0 1 10 10
DAD SP 0 0 I 1 1 0 0 1 10 10
STAX B 0 0 0 0 0 0 1 0 7 7
STAX D 0 0 0 1 0 0 1 0 7 7
LDAX B 0 0 0 0 1 0 1 0 7 7
LDAX D 0 0 0 1 1 0 1 0 7 7
INX B 0 0 0 0 0 0 1 1 5 6
INX D 0 0 0 1 0 0 1 1 5 6
INX H 0 0 1 0 0 0 1 1 5 6
INX SP 0 0 1 1 0 0 1 1 5 6
MOV r1/2 0 1 D D D S S S 5 4
MOV M,r 0 1 1 1 0 S S S 7 7
MOV r,M 0 1 D D D 1 1 0 7 7
HLT 0 1 1 1 0 1 1 0 7 5
MVI r 0 0 D D D 1 1
I
0 7 7
MVI M 0 0 1 1 0 1 1 0 10 10
INR 0 0 D D D 1 0 0 5 4
DCR 0 0 D D D 1 0 1 5 4
ALL MNEMON/CS© 1974,7975,7976, 7977/NTEL CORPORATION
A-2
Appendix A. Instruction Summary
NUMBER OF TIME PERIODS
MNEMONIC D
7
D
6
D
5
D
4
D
3
D
2
D
1
DO
8080 8085
INR A 0 0 1 1 1 1 0 0 5 4
DCR A 0 0 1 1 1 1 0 1 5 4
INR M 0 0 1 1 0 1 0 0 10 10
DCR M 0 0 1 1 0 1 0 1 10 10
ADD r 1 0 0 0 0 5 5 5 4 4
ADC r 1 0 0 0 1 5 5 5 4 4
SUB r 1 0 0 1 0 5 5 5 4 4
SBB r 1 0 0 1 1 5 5 5 4 4
,AND r 1 0 1 0 0 5 5 5 4 4
XRA r 1 0 1 0 1 5 i 5 5 4 4
ORA r 1
I
0 1 1 0 5 5 5 4 4
CMPr 1 0 1 1 1 5 5 5 4 4
ADD M 1 0 0 0 0 1 1 0 7 7
ADC M 1 0 0 0 1 1 1 0 7 7
SUB M 1 0 0 1 0 1 I 1 0 7 7
5BB M 1 0 0 1 1 1 1 0 7 7
AND M 1 0 1 0 0 1 1 0 7 7
XRA M 1 0 1 0 1 1 1 0 7 7
ORA M 1 0 1 1 0 1 1 0 7 7
CMP M 1 0 1 1 1 1 1 0 7 7
ADI 1 1 0 0 0 1 1 0 7 7
ACI 1 1 0 0 1 1 1 0 7 7
SUI 1 1 0 1 0 1 1 0 7 7
5BI 1 1 0 1 1 1 1 0 7 7
ANI 1 1 1 0 0 1 1 0 7 7
XRI 1 1 1 0 1 1 1 0 7 7
ORI 1 1 1 1 0 1 1 0 7 7
CPI 1 1 1 1 1 1 1 0 7 7
RLC 0 0 0 0 0 1 1 1 4 4
RRC 0 0 0 0 1 1 1 1 4 4
RAL 0 0 0 1 0 1 1 1 4 4
RAR 0 0 0 1 1 1 1 1 4 4
JMP 1 1 0 0 0 0 1 1 10 10
JC
1 1 0 1 1 0 1 0 10 7{10
JNC 1 1 0 1 0 0 1 0 10 7{10
JZ
1 1 0 0 1 0 1 0 10 7{10
JNZ 1 1 0 0 0 0 1 0 10 7{10
JP
1 1 1 1 0 0 1 0 10 7/10
JM
1 1 1 1 1 0 1 0 10 7/10
JPE 1 1 1 0 1 0 1 0 10 7/10
JPO 1 1 1 0 0 0 1 0 10 7{10
DCX B 0 0 0 0 1 0 1 1 5 6
DCX D 0 0 0 1 1 0 1 1 5 6
DCX H 0 0 1 0 1 0 1 1 5 6
DCX 5P 0 0 1 1 1 0 1 1 5 6
ALL MNEMONICS©7974, 7975, 7976, 7977 INTEL CORPORATION
A-3
Appendix A. Instruction S!lmmary
NUMBER OF TIME PERIODS
MNEMONIC D
7
D
6
D
s
D
4
D
3 °2 °1
DO
8080 8085
CMA 0 0 1 0 1 1 1 1 4 4
STC
I 0 0 1 1 0 1 1 1 4 4
CMC 0 0 1 1 1 1 1 1 4 4
OAA 0 0 1 0 0 1 1 1 4 4
SHLD 0 0 1 0 0 0 1 0 16 16
LHLD 0 0 1 0 1 0 1 0 16 16
RIM 0 0 1 0 0 0 0 0 -
4
SIM 0 0 1 1 0 0 0 0 - 4
EI 1 1 1 1 1 0 1 1 4 4
DI 1 1 1 1 0 0 1 1 4 4
NOP 0 0 0 0 0 0 0 0 4 4
ALL MNEMONICS © 7 ~ 74, 7975, 7976. 7977 INTEL CORPORA nON
A4
Appendix A. Instruction Summary
The following is a summary of the instruction set:
8080/85 CPU INSTRUCTIONS IN OPERATION CODE SEQUENCE
OP OP OP OP OP OP
CODE MNEMONIC CODE MNEMONIC CODE MNEMONIC CODE MNEMONIC CODE MNEMONIC CODE MNEMONIC
00 NOP 2B DCX H 56 MOY D,M 81 ADD C AC XRA H D7 RST 2
01 LXI B.D16 2C INR L 57 MOY D,A 82 ADD D AD XRA L D8 RC
02 STAX B 2D DCR L 58 MOY E.B 83 ADD E AE XRA M D9 -
03 INX B 2E MYI L,D8 59 MOY E.C 84 ADD H AF XRA A DA JC
Adr
04 INR B 2F CMA SA MOY E,D 85 ADD L BO ORA B DB IN D8
05 DCR B 30 SIM 5B MOY E,E 86 ADD M B1 ORA C DC CC Adr
06 MYI B,D8 31 LXI SPD16 5C MOY E,H 87 ADD A B2 ORA D DD
07 RLC 32 STA Adr 5D MOY E.L 88 ADC B B3 ORA E DE SBI D8
08 -
33 INX SP 5E MOY E,M 89 ADC C B4 ORA H DF RST 3
09 DAD B 34 INR M SF MOY E,A 8A ADC D B5 ORA L EO RPO
OA LDAXB 35 DCR M 60 MOY H,B 8B ADC E B6 ORA M E1 POP H
OB DCX B 36 MVI M,D8 61 MOV H,C 8C ADC H B7 ORA A E2 jPO Adr
OC INR C 37 STC 62 MOV H,D 8D ADC L B8 CMP B E3 XTHL
OD DCR C 38 -- 63 MOV H,E 8E ADC M B9 CMP C E4 CPO Adr
OE MYI C.08 39 DAD SP 64 MOY H,H 8F ADC A BA CMP D E5 PUSH H
OF RRC 3A LDA Adr 65 MOY H,L 8G SUB B BB CMP E E6 ANI D8
10 --
3B DCX SP 66 MOY H,M 91 SUB C BC CMP H E7 RST 4
11 LXI D,D16 3C INR A 67 MOV H,A 92 SUB D BD CMP L E8 RPE
12 STAX D 3D DCR A 68 MOV L,B 93 SUB E BE CMP M E9 PCHL
13 INX D 3E MYI A,D8 69 MOY L.C 94 SUB H BF CMP A EA IPE Adr
14 INR D 3F CMC 6A MOY L,D 95 SUB L CO RNZ EB XCHG
15 DCR D 40 MOY B.B 6B MOY L,E 96 SUB M C1 POP B EC CPE Adr
16 MYI D,D8 41 MOV B,C 6C MOY L,H 97 SUB A C2 jNZ Adr ED --
17 RAL 42 MOY B.D 6D MOV L,L 98 SBB B C3 IMP Adr EE XRI D8
18 --
43 MOV B,E 6E MOV L,M 99 SBB C C4 CNZ Adr EF RST 5
19 DAD D 44 MOV B.H 6F MOV L,A 9A SBB D C5 PUSH B FO RP
1A LDAXD 45 MOV B,L 70 MOV M.B 9B SBB E C6 ADI D8 F1 POP PSW
1B DCX D 46 MOY B,M 71 MOV M,C 9C SBB H C7 RST 0 F2
JP
Adr
1C INR E 47 MOY B,A 72 MOY M,D 9D SBB L C8 RZ F3 DI
10 DRC E 48 MOY C,B 73 MOV M.E 9E SBB M C9 RET Adr F4 CP Adr
1E MYI E.D8 49 MOY C,C 74 MOV M.H 9F SBB A CA jZ F5 PUSH PSW
1F RAR 4A MOY C.D 75 MOV M.L AO ANA B CB -- F6 ORI D8
20 RIM 4B MOY C,E 76 HLT A1 ANA C CC CZ Adr F7 RST 6
21 LXI H.D16 4C MOV C,H 77 MOY M,A A2 ANA D CD CALL Adr F8 RM
22 SHLD Adr 4D MOY C.L
78 MOV A,B A3 ANA E CE ACI D8 F9 SPHL
23 INX H 4E MOV C,M 79 MOY A.C A4 ANA H CF RST 1 FA jM Adr
24 INR H 4F MOV C.A 7A MOY A.D A5 ANA L DO RNC FB EI
25 DCR H 50 MOV D.B 7B MOV A.E A6 ANA M D1 POP D FC CM Adr
26 MYI H,D8 51 MOV D.C 7C MOV A,H A7 ANA A D2 INC Adr FD --
27 DAA 52 MOY D,D 7D MOV A.L A8 XRA B D3 OUT D8 FE CPI D8
28 -- 53 MOY D.E 7E MOY A.M A9 XRA C D4 CNC Adr FF RST 7
29 DAD H 54 MOY D,H 7F MOY A,A AA XRA D D5 PUSH D
2A LHLD Adr 55 MOY D.L 80 ADD B AB XRA E D6 SUI D8
08 = constant. or logical/arithmetic expressIOn that evaluates 016
to an 8 bit data quantity.
Adr ~ 16-bit address
constant. or logical/arithmetic expression that evaluates
to a 16 bit data quantity
ALL MNEMONICS © 1974, 7975, 1976, 7977 INTEL CORPORA TfON
A-5
Appendix A. Instruction :;ummary
Instruction Sct Guidc
Thc following IS I slIl11l11dry of thc IIlstrllclion sct:
,ADD ADI
,A DC ACI
SUB SUI
S3B
REGM
S
SBI
D
S
,ANA ANI
>RA XRI
eRA ORI
CMP CPI
ISTC CMC
INXi
1DCXJ REG
16

XCHG
I POINTER
RST
RET
RC RNCl
A RZ RNZ
16 RP RM J
RPE RPO
LOW HIGH
CALL
CC CNCl
CZ CNZ
CP CM >
CPE CPO J
STACK
,--------
jMP
jNCi
jNZ I
jM J A
16
jPO
IC
jZ
jP
JPE
RLC RAL RRC
RAR CMA DAA
INR}
DCR REGM
8
rlCCUMULATORI FLAGS
MOV REGM
8
,REGM
S
[ B I C
I [ DIE
LXI REG
16
,D
16
[ H L
--------- PUSH I
STACK I-E-'-- POP j B,D,H,PSW
MEANING
8085 ONLY

LDAX\ BC DE
STAX) ,

STA) A
16
MVI D
8
MOV
CODE
LHLDi
STHDj A
16
MEMORY
INPUT
PORTS
I
OUT P8
OUTPUT
PORTS
CONTROL
INSTRUCTIONS
RST
NOP
HLT
EI
DI
SIMI
RIM]
REGM
8
The operand l11ay specify one of the 8-bit registers A,B,C,D,E,H, or L or M (a l11el11ol-y
reference via the 16-bit address 111 the Hand L registers). The MOV instruction, which
calls for two operands, can specify M for only one of Its operands_
Designates 8·bit Il11mediatc operand.
Designates a 16·bit address.
Designates an 8·bit port number.
Designates a -16·bit register pair (B&C,D&E,H&L,or SP).
Designates a 16 -bit immediate operand.
ALL MNEMONICS © 1:174, 1975, 7976, 1977 INTEL CORPORA nON
A-6
APPENDIX B. ASSEMBLER DIRECTIVE SUMMARY
Assembler directives are summarIZed alphabetically In this appendix. The following terms are used to describe
the contents of directive fields.
NOTATION
Term
Expression
List
Name
Null
Oplab
Parameter
String
Text
Interpretation
Numerical expression evaluated during assembly: must evaluate
to 8 or 16 bits depending on directive issued.
Series of symbolic values or expreSSions, separated by commas.
Symbol name terminated by a space.
Field must be empty or an error results.
Optional label; must be terminated by a colon.
Dummy parameters are symbols holding the place of actual
parameters (symbolic values or expressIOns) specified elsewhere
in the program.
Series of any ASCII characters, surrounded by single quote marks.
Single quote within string is shown as two consecutive single quotes.
Series of ASCII characters.
Macro definitions and calls allow the use of the special characters listed below.
Character
&
%
Function
Ampersand. Used to concatenate symbols.
Angle brackets. Used to delimit text, such as lists, that contain
other delimiters.
Double semicolon. Used before a comment in a macro definition
to prevent inclusion of the comment in each macro expansion.
Exclamation point (escape character). Placed before a delimiter
to be passed as a literal in an actual parameter. To pass a literal
exclamation point, issue'!!.'
Percent sign. Precedes actual parameters to be evaluated immediately
when the macro is called.
ALL MNEMONICS © 7974, 7975, 7976, 7977 INTEL CORPORA nON
8-1
Appendix B. Assembler 0 :rective Summary
SUMMARY OF
FORMAT
Label Jpcode Operand(s)
oplab: )8 exp(sl or string(sl
oplab: )S expression
oplab: )W exp(sl or string(s)
oplab:
"LSE
null
FUNCTION
Define 8-bit data byte(s). Expressions must evaluate
to one byte.
Reserve data storage area of specified length.
Define 16·blt data word(s). Strings limited to 1-2
characters.
Conditional assembly. Code between ELSE and
ENDIF directives is assembled if expression in IF
clause is FALSE. (See IF.)
oplab:
"ND
expression Terminate assembler pass. Must be last statement of
program. Program execution starts at 'exp,' if present;
otherWise, at location O.
oplab: "NDIF null
name
"QU
expression
oplab: iF expression
oplab: )RG expression
name ;ET expression
MACRO DIRECTIV::S
FORMAT
Label Opcode Operand(s)
null I:NDM null
oplab: l:XITM null
oplab: IRP dummy param,<lisO
Terminate conditional assembly block.
Define symbol 'name' with value 'exp.' Symbol is not
redefi nab Ie.
Assemble code between IF and following ELSE or
ENDIF directive if 'exp' is true.
Set location counter to 'expression.'
Define symbol 'name' with value 'expression.'
Symbol can be redefined.
FUNCTION
Terminate macro definition.
Alternate terminator of macro definition. (See ENDM.)
Repeat instruction sequence, substituting one character
form 'list' for 'dummy param' in each iteration.
ALL MNEMONICS©7974, 7975, 7976, 7977 INTEL CORPORATION
8-2
Label
oplab:
FORMAT
Opcode
IRPC
Operand(s)
dummy param,text
Appendix B. Assembler Directive Summary
FUNCTION
Repeat instruction sequence, substituting one
character from 'text' for 'dummy param' in each
iteration.
null LOCAL label name(s)
name MACRO dummy param(s)
oplab: REPT expression
RELOCATION DIRECTIVES
FORMAT
Label Opcode Operand(s)
oplab: ASEG null
oplab: CSEG boundary specification
oplab: DSEG boundary specification
oplab: EXTRN
name(s)
oplab: NAME module-name
oplab: PUBLIC name(s)
oplab: STKLN expression
Specify label(s) in macro definition to have local
scope.
Define macro 'name' and dummy parameter(s) to be
used in macro definition.
Repeat REPT block 'expression' times.
FUNCTION
Assemble subsequent instructions and data in the
absol ute mode.
Assemble subsequent instructions and data In the
relocatable mode using the code location counter.
Assemble subsequent instructions and data in the
relocatable mode using the data location counter.
Identify symbols used in this program module but
defined in a different module.
ASSigns a name to the program module.
Identify symbols defined in this module that are to
be available to other modules.
Specify the number of bytes to be reserved for the
stack for this module.
ALL MNEMONICS©7974, 7975, 7976, 7977 INTEL CORPORA TlON
B-3
APPENDIX C. ASCII CHARACTER SET
ASCII CODES
The 8080 and 8085 usc the seven-bit ASCII code, with the high-order eighth bit
(parity bitl always reset.
, GRAPHIC OR ASCII GRAPHIC OR ASCII
CONTROL (HEXADECIMAL) CONTROL (HEXADECIMAL)
NUL 00 + 2B
SOH 01 2C
STX 02 2D
ETX 03 2E
EaT 04 I 2F
ENQ 05 0 30
ACK 06 1 31
BEL 07 2 32
BS 08 3 33
HT 09 4 34
LF OA 5 35
VT OB 6 36
FF OC 7 37
CR OD 8 38
SO OE 9 39
SI OF 3A
DLE 10 3B
DCl (X-ON) 11
< 3C
DC2 (TAPE) 12 3D
DC3 (X-OFF) 13
>
3E
DC4 (+Afl8 14 3F
NAK 15
@
40
SYN 16 A 41
ETB 17 B 42
CAN 18 C 43
EM 19 D 44
SUB lA E 45
ESC lB F 46
FS lC G 47
GS 10 H 48
RS lE I 49
US IF J 4A
SP 20 K 4B
21 L 4C
22 M 4D
# 23 N 4E
$ 24 a 4F
% 25 P 50
& 26
Q
51
27 R 52
28 S 53
29 T 54
2A U 55
GRAPHIC OR ASCII
CONTROL (HEXADECIMAL)
V 56
W 57
X 58
Y 59
Z 5A
[ 5B
\ 5C
1
5D
i\ (t) 5E
(+-) 5F
,
60
a 61
b 62
c 63
d 64
e 65
f 66
9
67
h 68
I 69
J
6A
I
k 6B
I 6C
m 6D
n 6E
0 6F
P
70
q 71
r 72
s 73
t 74
u 75
v 76
w 77
x 78
v 79
z 7A
I
7B
\
I
7C
,
(ALT MODE) 7D
I
~
7E
DEL (RUB OUT) 7F
C-1
APPENDIX D.
BINARY-DECIMAL-HEXADECIMAL CONVERSION TABLES.
D-l
Appendix D. BinarVMDecinal-Hexadecimal Conversion Tables
P<)WERS OF TWO
2
n ·n
n 2
1 o 1.0
2 1 0.5
4 2 0.25
8 3 0.125
16 4 0.062 5
32 5 0.031 25
64 6 0.015 625
128 7 0.007 812 5
256 8 0.003 906 25
512 9 0.001 953 125
1 024 10 0.000 976 562 5
2 Cl48 11 0.000 488 281 25
4 096 12 0.000 244 140 625
8 192 13 0.000 122 070 312 5
16 384 14 0.000 061 035 156 25
32 768 15 0.000 030 517 578 125
65 536 16 0.000 015 258 789 062 5
131 072 17 0.000 007 629 394 531 25
262 144 18 0.000 003 814 697 265 625
524 288 19 0.000 001 907 348 632 812 5
1 048 576 20 0.000 000 953 674 316 406 25
2 097 152 21 0.000 000 476 837 158 203 125
4 194 304 22 0.000 000 238 418 579 101 5625
8 388 308 23 0.000 000 119 209 289 550 781 25
16 7?7 216 24 0.000 000 059 6Cl4 644 77 5 390 625
33 554 ~ 3 2 25 0.000 000 029 802 322 387 695 312 5
67 108 364 26 0000 000 014 901 161 193 847 656 25
134 217 728 27 0.000 000 007 450 580 596 923 828 125
268 435 ~ 5 6 28 0.000 000 003 725 290 298 461 914 062 5
536 870 :l12 29 0.000 000 001 862 645 149 230 957 031 25
1 073 741 324 30 0.000 000 000 931 322 574 615 478 515 625
2 147 483 548 31 0.000 000 000 465 661 287 307 739 257 812 5
4 294 967 296 32 0000 000 000 232 830 643 653 869 628 906 25
8 589 934 592 33 0000 000 000 116 415 321 826 934 814 453 125
17 179 869 184 34 0000 000 000 058 207 660 913 467 407 226 562 5
34 359 738 368 35 0.000 000 000 029 103 830 456 733 703 613 281 25
68 719 476 736 36 0.000 000 000 014 551 915 228 366 851 806 640 625
137 438 953 ~ 7 2 37 0.000 000 000 007 275 957 614 183 425 903 320 312 5
274 877 906 :l44 38 0.000 000 000 003 637 978 807 091 712 951 660 156 25
549 755 813 388 39 0.000 000 000 001 818 989 403 545 856 475 830 078 125
1 099 511 627 776 40 0.000 000 000 000 909 494 701 772 928 237 915 039 062 5
2 199 023 255 55241 0.000 00.0 000 000 4,,4 747 350 886 464 118957 519531 25
4 398 046 511 104 42 0.000 000 000 000 227 373 675 443 232 059 478 759 765 625
8 796 093 022 208 43 0.000 000 000 000 113 686 837 721 616 029 739 379 882 812 5
17 592 186 044 41644 0.000 000 000 000 056 843 418 860 808 014 869 689 941 406 25
35 184 372 088 332 45 0.000 000 000 000 028 421 709 430 404 007 434 844 970 703 125
70 368 744 177 56446 0.000 000 000 000 014 210 854 715202 003 717 422 485 351 5625
140 737 488 355 328 47 0.000 000 000 000 007 105427 357 601 001 858 711 242675 781 25
281 474 976 710 556 48 0.000 000 000 000 003 552 713 678 800 500 929 355 621 337 890 625
562 949 953 421 312 49 0.000 000 000 000 001 776 356 839 400 250 464 677 810 668 945 312 5
1 125899906842 524 50 0.000 000 000 000 000 888 178419 700 125 232 338 905 3Cl4 472 656 25
2 251 799 813 685 248 51 0.000 000 000 000 000 444 089 209 850 062 616 169 452 667 236 328 125
4 503 599 627 370 496 52 0.000 000 000 000 000 222 044 604 925 031 308 084 726 333 618 164 062 5
9 007 199 254 740 992 53 0.000 000 000 000 000 111 022 302 462 515 654 042 363 166 809 082 031 25
18 014 398 509 481 98454 0.000 000 000 000 000 055511 151 231 257827 021 181 583404 541 015625
36 028 797 018 963 968 55 0.000 000 000 000 000 027 755 575 615 628 913 510 590 791 702 270 507 812 5
72 057 594 037 927 936 56 0.000 000 000 000 000 013 877 787 807 814 456 755 295 395 851 135 253 906 25
144 115 188 075 855 872 57 0.000 000 000 000 000 006 938 893 903 907 228 377 647 697 925 567 676 950 125
288 230 376 151 711 744 58 0.000 000 000 000 000 003 469 446 951 953 614 188 823 848 962 783 813 476 562 5
576 460 752 303 423 488 59 0.000 000 000 000 000 001 734 723 475 976 807 094 411 924 481 391 906 738 281 25
1 152 921 504 606 846 976 60 0000 000 000 000 000 000 867 361 737 988 403 547 205 962 240 695 953 369 140 625
2 305 843 009 213 693 952 61 0.000 000 000 000 000 000 433 680 868 994 201 773 602 981 120 347 976 684 570 312 5
4 611 686 018 427 387 904 62 0.000 000 000 000 000 000 216 840 434 497 100 886 801 490 560 173 988 342 285 156 25
9 223 372 036 854 775 808 63 0.000 000 000 000 000 000 108 420 217 248 550 443 400 745 280 086 994 171 142 578 125
D-2
Appendix D. Conversion Tables
POWERS OF 16 (IN BASE 10)
16"
16'"
1 0 0.10000 00000 00000 00000 X 10
16 1 0.62500 00000 00000 00000 X
10-
1
256 2 0.39062 50000 00000 00000 X
10-
2
4 096 3 0.24414 06250 00000 00000 X
10-
3
65 536 4 0.15258 78906 25000 00000 X
10-
4
1 048 576 5 0.95367 43164 06250 00000
X 10-
6
16 777 216 6 0.59604 64477 53906 25000 X
10-
7
268 435 456 7
0.37252 90298 46191 40625 X
10-
8
4 294 967 296 8 0.23283 06436 53869 62891 x
10-
9
68 719 476 736 9 0.14551 91522 83668 51807 x
10-
10
1 099 511 627 776 10 0.90949 47017 72928 23792 X
10-
12
17 592 186 044 416 11 0.56843 41886 08080 14.870 X
10-
13
281 474 976 710 656 12 0.35527 13678 80050 09294 X
10-
14
4 503 599 627 370 496 13 0.22204 46049 25031 30808 X
10-
15
72 057 594 037 927 936 14 0.13877 78780 78144 56755 X
10-
16
152 921 504 606 846 976 15 0.86736 17379 88403 54721 X
10-
18
POWERS OF 10 (IN BASE 16)
10" 10'"
1 0 1.0000 0000 0000 0000
A 1 0.1999 9999 9999 999A
64 2 0.28F5 C28F 5C28 F5C3 x
16-
1
3E8 3 0.4189 374B e6A7 EF9E x
16 -2
2710 4 0.68oB 8BAC 710C B296 x
16-
3
1 86AO 5 0.A7C5 AC47 lB47 8423 x
16-
4
F 4240 6 0.10C6 F7AO B5EO 8037 x
16-
4
98 9680 7 0.lA07 F29A BCAF 4858 X
16-
5
5F5 El00 8 0.2AF3 lOC4 6118 73BF x
16-
6
3B9A CAOO 9 0.44BB 2FAO 9B5A 52CC x
16-
7
2 540B E400 10 0.6oF3 7F67 SEF6 EAoF x
16-
8
17 4876 E800 11 O.AFEB FFOB CB24 AAFF x
16-
9
E8 o4A5 1000 12 0.1197 9981 20EA 1119 x
16-
9
918 4E72 AOOO 13 0.lC25 C268 4976 81C2 X
16-
10
5AF3 107A 4000 14 0.2009 3700 4257 3604 x
16-
11
3 807E A4C6 8000 15 0.480E BE7B 9058 5660 X
16-
12
23 8652 6FCl 0000 16 0.734A CA5F 6226 FOAE x
16-
13
163 4578 508A 0000 17 0.B877 AA32 36A4 B449 x
16-
14
oEO B6B3 A764 0000 18 0.1272 5001 0243 ABAl X
16-
14
8AC7 2304 89E8 0000 19 0.1083 C94F B602 AC35 X
16-
15
D-3
Appendix D. Binary-Declllal-Hexadecimal ConversIon Tables
HEXADECIMAL-DECIMAL INTEGER CONVERSION
The table below provide! for direct conversions between hexadecimal Integers In the range O-FFF and decimal integers In the
range 0-4095. For conVHSlon of larger Integers, the table values may be added to the following figures:
Hexadecimal Decimal Hexadecimal Decimal
01000 4096 20000 131072
02000 8192 30000 196608
03000 12288 40000 262144
04000 16384 50000 327 680
05000 20480 60000 393216
06000 24576 70000 458752
07000 28672 80000 524288
08000
32768 90000 589824
09000 36864 AO 000 655360
OA 000 40960 80000 720896
OB 000 45056 CO 000 786432
oe 000
49152 DO 000 851 968
OD 000
53248 EO 000 917504
OE 000
57344 FO 000 983040
OF 000
61440 100000 1048576
10000 65536 200000 2097152
11 000
69632 300000 3 145728
12000 73728 400000 4194304
13000
77 824 500000 5242880
14000 81920 600000 6291456
15000 86016 700000 7340032
16000 90112 800000 8388608
17000 94208 900000 9437184
18000 98304 AOO 000 10485760
19000 102400 BOO 000 11 534336
lAOOO 106496 COO 000 12 582912
lB 000 110592 DOO 000 13631488
leOOO 114688 EOO 000 14680064
10 000 118784 FOO 000 15728640
lE 000 122 880 1000000 16777216
1F 000 126976 2000000 33554432
0 1 2 3 4 5 6
7
8 9 A B e D E F
000 0000 0001 0002 0003 0004 0005 0006 0007 OOOB 0009 0010 0011 0012 0013 0014 0015
010 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 0030 0031
020 0032 0033 0034 0035 0036 0037 0038 0039 0040 0041 0042 0043 0044 0045 0046 0047
030 0048 0049 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 0060 0061 0062 0063
040 0064 0065 0066 0067 0068 0069 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079
050 0080 0081 0082 0083 0084 0085 00B6 0087 0088 0089 0090 0091 0092 0093 0094 0095
060 0096 0097 0098 0099 0100 0101 0102 0103 0104 0105 0106 0107 0108 0109 0110 0111
070 0112 0113 o 14 0115 0116 0117 0118 0119 0120 0121 0122 0123 0124 0125 0126 0127
080 0128 0129 030 0131 0132 0133 0134 0135 0136 0137 0138 0139 0140 0141 0142 0143
090 0144 0145 046 0147 0148 0149 0150 0151 0152 0153 0154 0155 0156 0157 0158 0159
OAO 0160 0161 062 0163 0164 0165 0166 0167 0168 0169 0170 0171 0172 0173 0174 0175
OBO 0176 0177 078 0179 0180 0181 0182 0183 0184 0185 0186 0187 0188 0189 0190 0191
oeo 0192 0193 094 0195 0196 0197 0198 0199 0200 0201 0202 0203 0204 0205 0206 0207
ODO 0208 0209 0:!10 0211 0212 0213 0214 0215 0216 0217 0218 0219 0220 0221 0222 0223
OEO 0224 0225 0:!26 0227 0228 0229 0230 0231 0232 0233 0234 0235 0236 0237 0238 0239
OFO 0240 0241 0:!42 0243 0244 0245 0246 0247 0248 0249 0250 0251 0252 0253 0254 0255
D-4
Appendix D. Binary-Decimal-Hexadecimal Conversion Tables
HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cant'dl
0 1 2 3 4 5 6 7 8 9 A B C D E F
100 0256 0257 0258 0259 0260 0261 0262 0263 0264 0265 0266 0267 0268 0269 0270 0271
110 0272 0273 0274 0275 0276 0277 0278 0279 0280 0281 0282 0283 0284 0285 0286 0287
120 0288 0289 0290 0291 0292 0293 0294 0295 0296 0297 0298 0299 0300 0301 0302 0303
130 0304 0305 0306 0307 0308 0309 0310 0311 0312 0313 0314 0315 0316 0317 0318 0319
140
I 0320
0321 0322 0323 0324 0325 0326 0327 0328 0329 0330 0331 0331 0333 0334 0335
150 0336 0337 0338 0339 0340 0341 0342 0343 0344 0345 0346 0347 0348 0349 0350 0351
160 0352 0353 0354 0355 0356 0357 0358 0359 0360 0361 0362 0363 0364 0365 0366 0367
170 0368 0369 0370 0371 0372 0373 0374 0375 0376 0377 0378 0379 0380 0381 0382 0383
180 0384 0385 0386 0387 038l:l 0389 0390 0391 0392 0393 0394 0395 0396 0397 0398 0399
190 0400 0401 0402 0403 0404 0405 0406 0407 0408 0409 0410 0411 0412 0413 0414 0415
lAO 0416 0417 0418 0419 0420 0421 0422 0423 0424 0425 0426 0427 0428 0429 0430 0431
lBO 0432 0433 0434 0435 0436 0437 0438 0439 0440 0441 0442 0443 0444 0445 0446 0447
lCO I0448
0449 0450 0451 0452 0453 0454 0455 0456 0457 0458 0459 0460 0461 0462 0463
lDO 0464 0465 0466 0467 0468 0469 0470 0471 0472 0473 0474 0475 0476 0477 0478 0479
lEO 0480 0481 0482 0483 0484 0485 0486 0487 0488 0489 0490 0491 0492 0493 0494 0495
lFO 0496 0497 0498 0499 0500 0501 0502 0503 0504 0505 0506 050"/ 0508 0509 0510 0511
200 0512 0513 0514 0515 0516 0517 0518 0519 0520 0521 0522 0523 0524 0525 0526 0527
210
I 0528
0529 0530 0531 0532 0533 0534 0535 0536 0537 0538 0539 0540 0541 0542 0543
220 0544 0545 0546 0547 0548 0549 0550 0551 0552 0553 0554 0555 0556 0557 0558 0559
230 0560 0561 0562 0563 0564 0565 0566 0567 0568 0569 0570 0571 0572 0573 0574 0575
240 0576 0577 0578 0579 0580 0581 0582 0583 0584 0585 0586 0587 0588 0589 0590 0591
250 0592 0593 0594 0595 0596 0597 0598 0599 0600 0601 0602 0603 0604 0605 0606 0607
260 0608 0609 0610 0611 0612 0613 0614 0615 0616 0617 0618 0619 0620 0621 0622 0623
270 0624 0625 0626 0627 0628 0629 0630 0631 0632 0633 0634 0635 0636 0637 0638 0639
280 0640 0641 0642 0643 0644 0645 0646 0647 0648 0649 0650 0651 0652 0653 0654 0655
290 0656 0657 0658 0659 0660 0661 0662 0663 0664 0665 0666 0667 0668 0669 0670 0671
2AO 0672 0673 0674 0675 0676 0677 0678 0679 0680 0681 0682 0683 0684 0685 0686 0687
2BO 0688 0689 0690 0691 0692 0693 0694 0695 0696 0697 0698 0699 0700 0701 0702 0703
2CO 0704 0705 0706 0707 0708 0709 0710 0711 0712 0713 0714 0715 0716 0717 0718 0719
2DO 0720 0721 0722 0723 0724 0725 0726 0727 0728 0729 0730 0731 0732 0733 0734 0735
2EO 0736 0737 0738 0739 0740 0741 0742 0743 0744 0745 0746 0747 0748 0749 0750 0751
2FO 0752 0753 0754 0755 0756 0757 0758 0759 0760 0761 0762 0763 0764 0765 0766 0767
300 0768 0769 0770 0771 0772 0773 0774 0775 0776 0777 0778 0779 0780 0781 0782 0783
310 0784 0785 0786 0787 0788 0789 0790 0791 0792 0793 0794 0795 0796 0797 0798 0799
320 0800 0301 0802 0803 0804 0805 0806 0807 0808 0809 0810 0811 0812 0813 0814 0815
330 0816 0817 0818 0819 0820 0821 0822 0823 0824 0825 0826 0827 0828 0829 0830 0831
340 0832 0833 0834 0835 0836 0837 0838 0839 0840 0841 0842 0843 0844 0845 0846 0847
350 0848 0849 0850 0851 0852 0853 0854 0855 0856 0857 0858 0859 0860 0861 0862 0863
360 0864 0865 0866 0867 0868 0869 0870 0871 0872 0873 0874 0875 0876 0877 0878 0879
370 0880 0881 0882 0883 0884 0885 0886 0887 0888 0889 0890 0891 0892 0893 0894 0895
380 0896 0897 0898 0899 0900 0901 0902 0903 0904 0905 0906 0907 0908 0909 0910 0911
390 0212 0913 0914 0915 0916 0917 0918 0919 0920 0921 0922 0923 0924 0925 0926 0927
3AO 0928 0929 0930 0931 0932 0933 0934 0935 0936 0937 0938 0939 0940 0941 0942 0943
3BO 0944 0945 0946 0947 0948 0949 0950 0951 0952 0953 0954 0955 0956 0957 0958 0959
j3CO 0960 0961 0962 0963 0964 0965 0966 0967 0968 0969 0970 0971 0972 0973 0974 0975
1
3DO 0976 0977 0978 0979 0980 0981 0982 0983 0984 0985 0986 0987 0988 0989 0990 0991
3EO 0992 0993 0994 0995 0996 0997 0998 0999 1000 1001 1002 1003 1004 1005 1006 1007
i 3FO 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
D-5
Appendix O. Binarv-Oet Conversion Tables
HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd)
I
2 3 4 5 6 7
8 9 A B C 0 E F 0 1
400 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
410 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
420 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
430 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
440 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
450 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
460 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
470 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
480 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
490 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
4AO 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
4BO 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
4CO 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
400 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
4EO 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
4FO 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
500 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
510 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1'306 1307 1308 1309 1310 1311
520 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
530 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
540 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
550 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
560 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
570 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
580 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
590 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
5AO 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
5BO 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
5CO 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487
500 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503
5EO 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
5FO 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
600 1536 1537 1538 1539 1540 1541 1543 1544 1545 1546 1547 1548 1549 1550 1551
610 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
620 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
630 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
640 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
650 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
660 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647
670 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663
680 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679
690 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
6AO 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
680 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727
6CO 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
600 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759
6EO 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
6FO 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
D-6
Appendix D. Binarv-Decimal-Hexadecimal Conversion Tables
HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd)
0 1 2 3 4 5 6 7 8 9 A B C 0 E F
700 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
710 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823
720 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839
! 730
1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855
I
740 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871
750 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
760 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903
770 1904 1905 1906 1907 1908
1909 1910 1911 1912 1913 1914 1915 1911j 1917 1918 1919
780 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
1
790 1936 1937 1938 1939 1940
1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951
7AO 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967
7BO 1968 1969 1970 1971 1972
1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983
7CO 1984 1985 1986 1987 1988
1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999
700 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
7EO 2016 2017 2018
2019 2020
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031
7FO 2032 2033 2034 2035 2036
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047
800 2048 2049 2050
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063
810 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079
820 2080 2081 2082 2083 2084
2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095
830 2096 2097 2098 2099 2100
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111
840 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127
.850 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143
860 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159
870 2160 2161 2162
2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
880 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191
890 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207
8AO 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223
8BO 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239
8CO 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255
800 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271
8EO 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287
8FO 2288 2289 2290
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303
900 2304 2305
2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319
1
910 2320 2321 2322 2323
2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
920 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351
930 I 2352 2353
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367
940 2368 2369
2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383
950 2384 2385
2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399
960 2400 2401
2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415
970 2416 2417
2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431
980 2432 2433
2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447
990 2448 2449
2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463
9AO 2464 2465
2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479
980 2480 2481
2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495
9CO 2496 2497
2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511
900 2512 2513
2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527
9EO 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543
9FO 2544 2545
2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559
0-7
Appendix D. Binary-Declmal-Hexadeclmal Conversion Tables
HEXADECIMAL·DECIMAL INTEGER CONVERSION (Cont'dl
0 1 2 3 4 5 6 7 8 9 A 8 C D E F
Aoo 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575
Al0 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591
A20 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607
A30 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623
A40 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639
A50 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655
A60 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671
A70 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687
A80 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703
A90 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719
AAO 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735
ABO 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751
ACO 12752
2753 2754 2755 2756 2757 2758 2759 2760 4761 2762 2763 2764 2765 2766 2767
ADO I 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783
AEO 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799
AFO 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815
BOO 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831
Bl0 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847
B20 2848 2849 2850 3851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863
B30 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879
B40 2880 2881 2882 2883 2884 2885 2866 2887 2888 2889 2890 2891 2892 2893 2894 2895
B50 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911
B60 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927
B70 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943
B80 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959
B90 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975
BAO 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991
BBO 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007
BCO 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023
BDO 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039
BEO 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055
BFO 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071
---
COO 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087
Cl0 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103
C20 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119
C30 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131
3132 3133 3134 3135
C40 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147
3148 3149 3150 3151
C50 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163
3164 3165 3166 3167
C60 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177
3178 3179
3180 3181 3182 3183
C70 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195
3196 3197 3198 3199
C80 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211
3212 3213 3214 3215
C90 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227
3228 3229 3230 3231
CAO 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243
3244 3245 3246 3247
CBO 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263
CCO 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279
CDO 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295
CEO 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311
CFO 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327
D-8
Appendix D. Binary-Declmal-Hexadecimal ConverSion Tables
HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd)
0 1 2 3 4 5 6 7 8 9 A B C 0 E F
000 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343
010 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359
020 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375
030 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391
040 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407
050 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423
060 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439
070 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455
080 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471
090 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487
OAO 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503
OBO 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519
OCO 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535
000 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551
OEO 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567
OFO 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583
EOO 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599
El0 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615
E20 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3E528 3629 3630 3631
E30 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647
E40 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663
E50 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679
E60 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695
E70 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711
E80 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727
E90 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743
EAO 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759
EBO 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775
ECO 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791
EOO 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807
EEO 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823
EFO 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839
FOO 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855
FlO 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871
F20 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887
F30 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903
F40 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919
F50 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935
F60 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951
F70 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967
F80 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983
F90 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999
FAO 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015
FBO 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031
FCO 4032 4033 4034 4035 4036 4037 4038 4039 .4040 4041 4042 4043 4044 4045 4046 4047
FOO 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063
FEO 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079
FFO 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095
0-9
INDEX
Absolute symbols
Accumulator
Accumulator Instructions
ACI Instruction
ADC Instruction
ADD Instruction
ADI Instruction
Addressing Modes
Addressing Registers
ANA (AND) Instruction
AND Operator
ANI (AND Immediate) Instruction
Arithmetic Expression Operators
Arithmetic Instructions
ASCII Constant
ASEG (Absolute Segment) Directive
Assembler. Need for
Assembler Character Set
Assembler Compared with PL/M
Assembler Function .
Assembler Termination
Assembly-Time Expression Evaluation
Auxiliary Carry Flag
Auxiliary Carry Flag Setting - 8080/8085 Differences
Binary Data (Coding Rules)
blank (character)
Branching Instructions
Branch Table
Byte Isolation Operations
CALL Instruction
Carry Flag .
CC (Call if Carry) Instruction
CM (Call if Minus) Instruction
CMA (Complement Accumulator) Instruction
CMC (Complement Carry) Instruction
CMP (Compare) Instruction
CNC (Call if no carry) Instruction
CNZ (Call if not Zero) Instruction
Combined Addressing Modes
Comment Field
Compare Operators
Comparing Complemented Data
Comparisons in Expressions
Complement Used for Subtraction
Complemented Data
Concatenation
2-11. 2-16
1-6. 1-7
_/-79
3-2
3-2
3-4
3-5
.7-75
1-7
· 3-6
.2-73
· 3-7
.2-12
.7-77
2-6
,4-74
1-3
2-1
1-3
1-1
.4-70
.2-11
,7-77
./-72
· 2-6
· 2-3
7-78. 7-22
· 6-1
.2-74
3-8
./-/0
.3-70
.3-70
,3-ll
,3-72
.3-72
,3-/4
.3-74
.7-/6
· 2-4
.2-/3
2-8
.2-13
· 2-7
· 2-8
5-10.5-11.5-15.5-16
1-1
1-2
Condition Fla 5S
Conditional /J ssembly
CP (Call if I'ositlve) Instruction
CPE (Call if Parity Even) Instruction
CPI (Compan Immediate) Instruction
CPO (Call if Parity Odd) Instruction
CSEG (Code Segment) Directive
CZ (Call if Instruction .
DAA (Decim; I Adjust Accumulator) Instruction
DAD (DoublE Register Add) Instruction
Data Access Example
Data Definiti<n
Data Descrtpt on Example
Data for Subroutines
Data Label
Data Transfer Instructions
DB (Define Iiyte) Directive
DCR (DecrelT ent) Instruction
DCX (DecrelT ent Register Pair)
Decimal AddiCion Routine
Decimal Data (Coding Rules)
Decimal Subt 'action Routine
Delimiters
DI (Disable Interrupts) Instruction
Direct sing
Divide (Soft',\ are Example)
Division in Expressions
DS (Define torage) Directive
DSEG (Data Segment) Directive
Dummy Paralneters
DW (Define Nord) Directive
EI (Enable I:1terrupts) Instruction
ELSE Directi'e .
END Directlv
ENDIF Direclve
ENDM (End Macro) Directive
EOT Directive
EPROM
EQ Operator
EQU Directlv
EXITM (Exit Macro) DireClive
Expression E' aluatton
Expression O,erators
Expressions
Expressions. I'recedence of Operators
Expressions, of Values
EXTRN Dire, tive . . .
1-9
4-8
3-75
3-76
3-76
3-77
4-75
3-78
3-78
3-20
4-7
4-3
4-6
6-3
2-5
7-76
.4-3
3-20
3-22
6-12
2-5
6-14
2-2
.3-22,3-60
7-75
6-9
2-12
4-5
4-75
5-4
4-4
3-23
4-8
4-70
4-8
5-5,5-6,5-7,5-12
4-77
1-5
2-73
4-2
5-9
2-11
2-11
2-6
2-75
2-75
4-77
GE Operator
General Purpose Registers
GT Operator
Hardware Overview
Hexadecimal Data (Coding Rules)
HIGH Operator
HLT (Halt) Instruction
IF Directive
Immediate Addressing
Implied Addressing
IN (Input) Instruction
INPAGE Reserved Word
Input/Output Ports
INR (I ncrement) Instruction
Instruction Addressing Modes
Instruction Execution
Instruction Fetch
Instructlon Label
Instruction Naming Conventions
Instruction Set GUide
Instruction Summary
Instruction Timing
Instructions as Operands
INTE Pin
Internal Registers
Interrupt Subroutines
Interrupts
Interrupts (8085)
INX (Increment Register Pair) Instructions
IRP (Indefinite Repeat) Directive
IRPC (Indefinite Repeat Character)
)C (J ump if Carry) Instruction
JM (J ump if Minus) Instruction
JMP (J ump) Instruction
JNC (Jump if no carry) Instruction
JNZ (J ump if not zero) Instruction
JP (Jump if Positive) Instruction
JPE (Jump if parity Even)
JPO (J ump if parity Odd)
j Z (J ump if Zero) Instruction
Label Field
Labels
LDA (Load Accumulator Direct) Instruction
LDAX (Load Accumulator Indirect)
2-73
7-7
2-73
1-5
2-5
2-74, 3-2, 3-5, 3-7, 404
...... 3-24
4-8
7-75
7-75
. 7-74, 3-24
·4-74,4-75
7-74
3-25
7-75
1-9
1-8
2-6
1-16
7-23
.1-19,7-23
3-7
2-7
3-49
1-6
7-4
7-1
1-24
3-26
.5-8, 5-12,5-22
.5-8,5-12,5-17
3-26
3-27
3-28
3-28
3-29
3-29
3-30
3-37
3-32
2-3
2-6
3-32
3-33
1-3
1-4
LE OperatOl
LIB Prograrr
LHLD (Load L Direct) Instruction
LINK Progr; m
Linkage
List File
LOCAL Dip-ctive
LOCAL Syrlbols
LOCATE Pr Jgram
Location Counter (Coding Rules)
Location Counter Control (Absolute Mode)
Location Counter Control (Relocatable Mode)
Logical Instr uctions
Logical Instl uctions, Summary
Logical Ope-ators
LOW Opera:or
LT Operato
LXI (Load Register Pair Immediate)
Macros
Macro Calls
Macro Defir Ition
MACRO Dir ective
Macro Expa lSlon
Macro Parar leters
Macros verslls Subroutines
Manual ProFamming
Memory
Memory Management with Relocation
Memory REservation
MEMORY I:eserved Word
MOD Opera tor
Modular Pr<gramming
MODULE [efault Name
MOV (MovE) Instruction
Multibyte Pddition Routines
Multibyte SJbtraction Routine
Multiplicatiol in Expressions
Multiply (Software Example)
MVI (Move Immediate)
NAME Dire;tive
NE Operatcr
Nested Maco Calls
Nested Mac'o Definitions
Nested Sub-outines
Nine's C o m ~ l e m e n t
NOP (No Operation) Instruction
2-13
4-12
3-34
4-12,4-14,4-15
4-16
1-1
5-5
5-6
4-12,4-13,4-14,4-19
2-6
4-77
4-74
7-17
3-6
2-13
2-74, 3-2, 3-5,3-7,4-4
2-13
3-35
5-1
5-12
5-4
5-4
5-15
5-5
5-3
1-3
1-5
4-72
4-5
4-19
2-12
4-72
4-17
3-36
6-11
6-11
2-12
6-7
3-37
4-78
2-13
5-14
5-12
3-48
2-7
3-38
NOP via MOV
NOT Operator
NUL Operator
Null Macros
Null Parameter
Object Code
Object File
Octal Data (Coding Rules)
One's Complement
Opcode
Opcode Field
Operand Field
Operand Field (Coding Rules)
Operands
Operators, Expression
OR Operator
ORG (Origin) Directive (Absolute Mode)
ORG (Origin) Directive (Relocatable Mode)
ORA (Inclusive OR) Instruction
OR! (Inclusive OR Immediate)
OUT Instruction
PAGE Reserved Word
Parity Flag
PCHL (Move H & L to Program Counter) Instruction
Permanent Symbols
PL/M
PL/M Compared with Assembler
POP Instruction
POP PSW instruction
Precedence of Expression Operators
Processor Registers
Program Counter
Program linkage Directives
Program listing
Program Status
Program Status Word (PSW)
Programming the 8085
PROM
PSW
PUBLIC Directive
PUSH Instruction
PUSH PSW Instruction
RAM
RAM versus ROM
RAL (Rotate Left through Carry) Instruction
. , , 3-36
. , 2-73
,2-13.5-77
5-16
5-11
7-2
1-1
2-5
2-7
1-1
2-4
2-4
2-4
2-5
2-11
2-73
4-77
4-76
3-38
3-40
1-14.3-47
. 4
c
74, 4-75
7-77
3-42
2-11
1-3
1-3
3-42
3-43
2-75
1-9
1-6
4-76
1-2
1-13
7-74
1-24
1-5
.7-74, 3-45
4-77
3-44
3-45
1-5
4-6
3-45
1-5
1-6
RAR (Rotte Right through Carry) Instruction
RC (Retum if Carry) Instruction
Redefinable Symbols
Register AddreSSing
Register Injirect Addressing
Register Pc ir Instructions
Register Pc irs
Relocatabili ty Defined
Relocatable Expressions
Relocatable Symbols
Relocation Feature
Reserved 5ymbols
RESET Si
f
nal
RET (Retl rn) Instruction
REPT DirE ctive
RIM (Read Interrupt Mask) 8085 Instruction
RLC (Rot, te Accumulator Left) Instruction
RM (RetUi n if Minus) Instruction
RNC (Retllrn if no Carry) Instruction
RNZ (Retllrn if not Zero) Instruction
ROM
RP (Retur 1 if Positive) Instruction
RPE (Retun if Parity Even) Instruction
RPO (RetiTn if Parity Odd) Instruction
RRC (Rot Ite Accumulator Right) Instruction
RST (Restlrt) Instruction
RST5.5
RST6.5
RST7.5
RZ (Return if Zero) Instruction
Savings Program Status
SBB (Subtract with Borrow) Instruction
SBI (Subtlact Immediate with Borrow) Instruction
Scope of Symbols
SET Direc:ive
Shift Expression Operators
Shift Opel ations in Expressions
SHL Oper.ltor
SHLD (St"re H & L Direct) Instruction
SHR Operltor
Sign Flag
SIM (Set Interrupt Mask) 8085 Instruction
Software Divide Routine
Software I ~ u l t i p l y Routine
Source Coje Format
Source Lilie Fields
Source Program File
SPHL (Mcve H & L to Stack Pointer) Instruction
3-46
3-47
2-11
7-75
7-76
7-27
1-7
4-72
.2-76,2-79
2-11
1-2
2-9
3-24
3-48
5-6,5-12,5-15,5-16,5-17,5-18
3-48
3-49
3-50
3-57
3-57
1-5
3-52
3-52
3-53
3-53
3-54
. 3-49, 3-55, 3-59, 3-60
. 3-49, 3-55, 3-59, 3-60
3-49, 3-55, 3-59, 3-60
3-55
7-73
3-56
3-57
2-10
4-3
2-12
2-12
2-72
3-58
2-72
7-70
3-59
6-7
6-7
2-1
2-1
1-1
3-67
SP (Stack Pointer Register)
STA (Store Accumulator Direct) Instruction
Stack
Stack and Machine Control Instructions
Stack Operations
Stack Pointer
STACK Reserved Word
Start Execution Address
STAX (Store Accumulator Indirect) Instruction
STC (Set Carry) Instruction
STKLN Directive
SUB (Subtract) Instruction
Subroutine Data
Subroutines
Subroutines versus Macros
Subtraction for Comparison
SUI (Subtract Immediate) Instruction
Symbol-Cross-Reference File
Symbol Definition
Symbol Table
Symbol ic Addressing
Symbols
Symbols, Absolute
Symbols (Coding Rules)
Symbols, Global
Symbols, limited
Symbols, Permanent
Symbols, Redefinable
Symbols, Relocatable
Symbols, Reserved
TRAP Interrupt
Ten's Complement
Testing Relocatable Modules
Timing Effects of Addressing Modes
TRAP (8085)
Two's Complement Data
Use of Macros
Using Symbols for Data Access
Val ue of ExpreSSions
What is a Macro?
Word Instructions
Word Storage in Memory
Work Registers
3-35
3-67
7-72
1-19
1-13
1-72
4-79, 3-35
4-10
3-62
3-63
4-18
3-63
6-3
, 1;72, 3-9
5-3
3-12
3-64
1-1,1-3
4-2
2-9
2-9
2-9
2-11
2-9
2-10
2·10
2·11
2-11
2-11
2·9
3-54
2-7
4-19
1·16
3-23
2-7
5-1
4-7
2-15
5·2
7·27
4-4
1-7
\.7
XCHG (Excllange H & L with D & E) Instruction
XOR Operator
XRA (Exclu ;Ive OR) Instruction
XRI (Exclus ve OR Immediate) Instruction
XTHL (Exciange H & L with Top of Stack) Instruction
Zero Flag
3-65
2-73
3-66
3-67
3-69
7-77
&
<>
CR
HT
*
( )
+
??nnnn
space
(ampepand)
(angle brackets)
(carriag = return character)
(colon)
(comm.)
(doubk semicolon)
(divlslo 1) Operator
(excian ation pOint)
(horizo ltal tab character)
(minus) Operator
(multiplication) Operator
(parent 1eses)
(plus) Operator
Svmbo s
(semic( Ion)
(single quote)
(charac .er)
5-10
5-10
2-2
2-2
2-2
5-10
2-12
5-10
2-2
2-12
2-12
2-2
2-12
5-5
2-2
2-2
2-2
1-8
8080/8085 !)ifferences
8085 Featul es
8085 Proces ;or
8085 Programming
7-24
1-24
7-24
1-24
NOTES
NOTES

The inforrm.tion in this document is subje<;t to

~nge

without notK:e.

Intel Corpor<ltion rm.kes no wuunty of <lny kind with reprd to this rm.teri.lJ, includi,., but not limited to, the implMld varnnttes of merch<lnubility <lnd fitness for <l ~rticul .... purpose. Intel Corpor<ltion HSUrnes no responsibWity for <lny errors that ma.y <lppur in this doc::ument. Intel Corpor<ltion rNkes no c.ornmitment to upd<t.te nor to keep current the inforrm.tion conuined in this document. The softwMe described in this document is furnished under <l Ik.ense ';lOd rNy be the terms of such lK:enst.
u~

or copied only in iGCOrcRnu with

Intel Cofporiltion <lSsurnes no responsibility for the use or reli<lbility of its softw<lre on equipment tNt is not suppUed by Intel.
No p<lrt of this doc::ument rm.y be copied or reproduud in any form or by ilny muns without the prklr written consent of Intel Corpoutt<m.

The

f~lowing

<lre trademMks of Intel Corpoution <lnd rm.y be used only to desc.ribe Intel products:
ICE-30 ICE-48 ICE-SO ICE-8S INSITE INTEL INTEllEC LIBRARY MANAGER

MCS
MEGACHASSIS MICROMAP MUlTIBUS PROMPT UPI

I ---------------,1
r-I

8080/8085 ASSEMBLY LANGUAGE

PROGRAMMING MANUAL

Copyright © 1977,1978 Intel Corporation Intel Corporation, 3065 Bowers Avenue, Santa Clara, California 95051

Although this manual is designed primarily for reference. refer to the appropriate information in Chapter 3 or 4. It will not teach you how to program a computer. The manual is organized as follows: Chapter 1. As these examples raise questions. ASSEMBLY LANGUAGE AND PROCESSORS Description of the assembler Overview of 8080 hardware and instruction set Description of 8080(8085 differences Chapter 2. you will need to read Chapter 4. PROGRAMMING TECHNIQUES Programming examples Chapter 7. iii . Before writing a program.PREFACE This manual describes programming with Intel's assembly language. INSTRUCTION SET Descriptions of each instruction (these are listed alphabetically for quick reference) Chapter 4. Use the table of contents or the index to locate information quickly. Chapters 3 and 4 will fill most of the experienced programmer's reference requirements. ASSEMBLER DIRECTIVES Data definition Conditional assembly Relocation Chapter 5. INTERRUPTS Description of the Interrupt system. The beginning programmer should read Chapters 1 and 2 and then skip to the examples in Chapter 6. It also contains some instructional matenal to help the beginning programmer. ASSEMBLY LANGUAGE CONCEPTS General assembly language coding rules Chapter 3. The 'Programming Tips' in Chapter 4 are intended especially for the beginning programmer. MACROS Macro directives Macro examples Chapter 6.

9800306 User program. you should be familiar with the following Intel publications: ISIS-II 8080/8085 IAACRO ASSEMBLER OPERATOR'S MANUAL. 9800292 When you activate the assembler.ER'S GUIDE. refer to the appropriate User's Manual: 8080 MICROCOMPUTER SYSTEMS USER'S MANU. ISIS-II SYSTEM U~. The manual also describes the procedures for linking and locating reloc Itable program modules.A. are commonly stored on diskette files.RELATED PUBLICATIONS To use your Intellec development system effectively. The operator's manual descriJes the activation sequence for the assembler. 9800153 8085 MICROCOMPUTER SYSTEMS USER'S MANUAL. you have the option of specifying a number of controls. 9800366 iv . The manual also describes the debugging tools and the error messages supplied by the assembler. Hardware Referenc~s For addition21 information about processors and their related components.L. The ISIS-II User's GUide describes the use of the text editor for entering and maintaining programs.

I/O. ASSEMBLY LANGUAGE AND PROCESSORS Introduction What Is An Assembler? What the Assembler Does Oblect Code Program Listing Symbol-Cross-Reference Listing Do You Need the Assembler? Overview of 8080/8085 Hardware Memory ROM RAM Program Counter Work Registers Internal Work Registers Condition Flags Carry Flag Sign Flag Zero Flag Parity Flag Auxiliary Carry Flag Stack and Stack Pointer Stack Operations Saving Program Status Input/Output Ports . and Machine Control Instructions Hardware/Instruction Summary Accumulator Instructions Register Pair (Word) Instructions Branching Instructions Instruction Set Guide 1-1 1-1 1-1 1-1 1-2 1-2 1-3 1-3 1-5 1-5 1-5 1-5 1-6 1-7 1-9 1-9 1-10 1-10 1-11 1-11 1-11 1-12 1-13 1-13 1-14 1-15 1-15 1-15 1-15 1-15 1-15 1-16 1-16 1-16 1-16 1-16 1-17 1-17 1-18 1-19 1-19 1-19 1-21 1-22 1-23 v . Instruction Set Addressing Modes Implied Addressing Register Addressll1g Immediate Addressll1g Direct Addressll1g Register Indirect Addressing Combined Addressing Modes Ti mll1g Effects of Addressll1g Modes Instruction Namll1g Conventions Data Transfer Group Arithmetic Group Logical Group Branch Group Stack.TABLE OF CONTENTS Chapter 1.

and Assembler-Generated Symbols Global and Limited Symbols Permanent and Redefinable Symbols Absolute and Relocatable Symbols Assembl I-Time Expression Evaluation Or erators Arithmetic Operators Shift Operators Logical Operators Compare Operators Byte Isolation Operators Pe 'missible Range of Values Pr"cedence of Operators Rdocatable Expressions . Cllaining of Symbol Definitions Chapter 3.CII Constant Labels Assigned Values Labels of Instruction or Data E> pressions In .tructions are listed in alphabetical order vi 1-24 1-24 1-25 2-1 2-1 2-1 2-1 2-2 2-3 2-4 2-4 2-4 2-4 2-5 2-5 2-5 2-5 2-6 2-6 2-6 2-6 2-6 2-7 2-7 2-7 2-9 2-9 2-9 2-9 2-10 2-11 2-11 2-11 2-11 2-12 2-12 2-13 2-13 2-14 2-15 2-15 2-16 2-18 3-1 3-1 3-1 . INSTRlCTION SET How tc Use this Chapter Timing Information In .tructions as Operands R( gister-Type Operands Two's Complement Representation of Data Symbol~ and Symbol Tables Sy mbol ic Addressing Sy mbolic Characteristics Reserved. ASSEMIIL Y LANGUAGE CONCEPTS Introdu( tion Source Line Format Garacter Set Delimiters Label/Name Field Ol'code Field Or'erand Field Cc mment Field Coding Operand Field Information He xadecimal Data Decimal Data O( tal Data Bilary Data Lc cation Counter A~. User-Defined.8085 Proc ~ssor Differences Pr )gramming for the 8085 Cc nditional Instructions Chapter 2.

ELSE. Subroutines vii . ta Access Add Symbols for DaLli Access Conditional Assembly IF.s Versus ReAd Only Memory Dua Desuiption O.. ASSEMBLER DIRECTIVES Symbol Definition EQU Directive 4-1 4-2 4-2 4·3 4-3 4·3 44 4-5 4-5 4-6 4-6 4-6 4-6 4-7 4-8 4-8 4-10 4-10 4-11 4-11 4-11 4-12 4-12 4-12 4-14 4-14 4-14 4-15 4-15 4-16 4-16 4-17 4-17 4-18 4-18 4-19 4-19 4-19 4-20 4-20 5·1 5·1 5-1 5-1 5-3 SET Directive Data Definition DB Directive OW Directive Memory Reservuion OS Directive D..mdom Acee. MACROS Introduction to Macros Why Us. R.table Programs) ASEG Directive CSEG Directive OSEG Directi"e ORG Directive (Relocatable Mode) Program linkage Directives PUBLIC Directive EXTRN Directive NAME Directive STKLN Directive STACK and MEMORY Reserved Words Programming Tips: Testing Relocatable Modules Init~1ilation Routines Input/Output Remove Coding Used for Testing Chapter S.Ha Description and Access Programming Til».Oupter 4. ENDIF Directives Assembler Termination END Directive Location Counter Control and Relocation location Counter Control (Non·Rcloc.e Macros? Wha t Is A Macro! Macros Vs.aubic Mode) ORG Directive Introduction to Rdocatability Memory Management Modular ProgrOlm Development Directives Used for Relocation location Counter Conlrol (Reloc<l.

p4n.ue Multiply lind Di"i~ Multibyte Addition ..cros s.Lking M. 0 INSTRUCTIO SUMMARY ASSEMBLER DIRECTIVE SUMMARY ASCII CHARACTE R SET BINARY·DECIMAL·HEXADECIMAL CONVERSION TABLES· A·\ B·I C..iun Null M.ru E).6·7 6-11 6·\2 6-14 7·\ 7·\ 7·4 Ap~ndix A Appcndi).. 8 Appendix C Appendi).livc REPT Dircllive IRP Directive IRPC Directive EXITM Directive Sp«i~1 M~CfO (Jpft.I 0·1 viii . oles P~udo·Subroutine lr.nd SublrliCiion DecirTldl Addition Oecimal SubU..cro Ddinition MACRO 5-3 S·) Directi~s Directj~ S4 S4 ENOM Oirectiw: LOCAL Oirel. mlt'rrinl DOll.:tlon Ch .cros MUfo Definition M..u.. pter 7. 6·) .ample Macros Ch.t. [0 Subroutine Soflw.ators Nested "bero Definitions MOlCr~ S-5 S·S S~ S·8 S-8 S·9 S·IO S·12 5·12 S·12 DU\ Muro DII fOflTWt Nested M~uo ulls M.1·16 6·\ 6-\ . PRCXiRAMMING TECHNIQUES Brlinch T.INTERRUPTS Interrupt ConcepH Writing Interrupt Subroutint's S·I' S·IS S·16 .tptt'r 6.

LIST OF ILLUSTRATIONS Figure 1-1 1-2 1-3 ASSEMBLER OUTPUTS COMPARISON OF ASSEMBLY LANGUAGE WITH PL/M 8080{8085 INTERNAL REGISTERS INSTRUCTION FETCH EXECUTION OF MOV M.C INSTRUCTION 1-2 1-4 1-6 1-8 1-9 1-4 1-5 ix .

.

If your program contains a set of instructions used as a timing loop (a set of instructions executed repeatedly until a specific amount of time has passed). You can then pass the resulting source program fife to the assembler. The Intellec development system includes a text editor that will help you maintain source programs as paper tape files or diskette files. the assembly language programmer must be familiar with both the assembly language and the processor for which he is programming. Programming diffel'ences between the 8080 and the 8085 microprocessors are relatively minor. You can also symbolically express addresses and values referenced in the operand field of instructions. ' The first part of this chapter describes the assembler. and the symbol-crass-reference file. Assembly language operation codes (opcodes) are easily remembered (MOY for move instructions.) The assembler program performs the clerical task of translating symbolic code into ob/ect code which can be executed by the 8080 and 8085 microprocessors. Assembly language source programs must be in a machine-readable form when passed to the assembler.deSigned to simplify the task of Writing computer programs. WHAT IS AN ASSEMBLER? An assembler IS a software tool . you will appreciate the advantages of programming in a symbolic assembly language. These instructions are written using mnemonic opcodes and labels as described previously. Therefore. if your program nust manipulate a date as data. The source program consists of programmer-written assembly language instructions. Since you assign these names.1. Assembler output consists of three possible files: the object fife containing your program translated into object code. (The text editor is described in the ISIS-II System User's GUide. What the Assembler Does To use the assembler. you first need a source program. If you have ever written a computer program directly in a machine-recognizable form such as binary or hexadecimal code. These differences are described in a short section at the end of this chapter. and the symbol table. the list file printout of your source code. ASSEMBLY LANGUAGE AND PROCESSORS INTRODUCTION Almost every line of source coding in an assembly language source program translates directly into a machine instruction for a particular processor. 1-1 . The second part describes the features of the 8080 microprocessor from a programmer's point of view. you can make them as meaningful as the mnemonics for the instructions. For example. JMP for jump). you can assign it the symbolic name DATE. a listing of the symbol-crossreference records.a program . the assemblergenerated object code. you can name the instruction group TIMER.

A special featu. Assembly Lan)~uage and Processors OBJECT FILE SOU<.Chapter 1. the assembler tells you that the value exceeds the pe'missible range. See Chapter 4 of this manual for a more thorough description of the advantages of the relocation feature. For example. if you specify al6-bl value for an InstruclJon that can use only an 8-blt value. do not forget that the Intellec development system IS an 8080 microcomputer system with raldom access memory. Assembler Outputs Oblect Code CROSS REFERENCE LISTING For most mlcrxomputer applications. a lal'ge progranl can be broken Into a number of separately assembled modules. The assembler also provides diagnostic messages for common programming errors in the program listing. Program Listing The program liitlng prOVides a permanent record of both the source program and the object code.E ASSEMBLER PROGRAM PROGRAM ~ LISTING ~ Figure 1-1. This frees the programm( r from worrYing about the eventual mix of read only and random access memory In the application system. you probably will eventually load the oblect program into some form of read only men ory. TIllS allows you to test your program before your prototype application sys:em IS fully developed.'e of this assembler IS that it allows you to request oblect code In a relocatable format. In most cases you can load and execute your oblCct program on the development s"stem for teSlJng and debugging. Also.t. indivicual porlJons of the program can be relocated as needed when the application design is final. Such modules are both easier to code and to te.CE PROGRAM FIl. 1-2 . However.

If most of the factors listed preViously apply to you. you may be able to provide customers with custom features through program changes. allows you to enter programs directly Into programmable read only memory. for example. You enter the program manually as a string of hexadeCimal digits. program support frequently subrect to stringent time constraints. Assume. Your need for programming support II1creases if you 15 agree to correct such errors for YOUI" customers. • The level of support for eXisting programs: Sometimes programming errors are not discovered until the program has been 111 use for quite a while. the more you need development support. TIllS allows you to write programs much more qUickly than a hardware· oriented language such as assembly language. 1-3 . o The time allowed for programming: As the time allowed for programmll1g decreases. Also. When your application has access to the power of a microprocessor. you may be able to add features through programming. It must be pOinted out that there can be penalties for not wl"lting programs. Do You Need the Assembler? The assembler IS but one of several tools available for developing microprocessor programs. hobbyists. Also. the reqUired level of performance depends on a number of variables: • The number of programs to be written: The greater the number of programs to be written. and that testing reveals a program logic error In the handling of this data. the asscmbly language instructions arc rcprescn ted by a flowchart. PL/M IS Intel's high-level language for program development. that your program manipulates a data field named DATE. choosing the most suitable tool IS based on cost restraints versus the required level of performance. Manual systems may be SUitable for limited applications. The symbol-crass-reference listing simplifies debugging this error because it POints you to each instruction that I"eferences the symbol DATE. for example. assume that a program must move five characters from one location 111 memory to anothcr. Intel's PROMPT-80. However. Such manual programming IS relatively slow and more prone to human error than computer-assisted programmll1g. and those who want to explol"e possible applications for microprocessors. you should explore the advantages of PL(M. Thc following cxample illustratcs the coding differences between assembly language and PL/M. If none of the factors described above apply to your Situation. Assembly Language and Processors Symbol-Crass-Reference Listing The symbol-crass-reference listing is another of the diagnostic tools provided by the assembler. you may be able to get along without the assembler. Since II1structions have not yet been described.Chapter 1. As an example. You or your company must determine cost restraints. manual systems are one of the least expensive tools available for mlcmprocessor programming. The number of supported programs In use can multiply this requirement. Typically. A high-level language is directed more to problem solVing than to a particular microprocessor. the need for programmll1g support II1creases. Also.

\CCUMULATOR WITH 1 BYTE FROM SOURCE FIELD I MOVE :HARACTER FROM ACCUIV ULATOR TO DESTINATION FIELD I I INCREMENT SOURCE ADDRESS CALL MOVE(S. Assembly Lan 5uage and Processors ASSEI ~BL Y LANGUAGE CODING PL/MCODING I I LOAD .ENT CHARACTER COUNT NO IS CHARACTER COUNT =O? YES ( CONTINUE Figure 1-2. I INCRHIENT DESTINATION ADDRESS ~ I I DECRE .FLD2. Comparison of Assembly Language with PL/M 1-4 .Chapter 1.FLD1).<EGISTER WITH NUMBER OF CHARACTERS TO BE MOVED I LOAD .<EGISTER PAIR B WITH ADDRE SS OF SOURCE (FLD1) I LOAD I~EGISTER PAIR D WITH ADDRESS OF DESTINATION (FLD2) I LOAD .

Normally. if your program uses the stack. those instructions must reside in RAM. With ROM you can be certain that the program is ready for execution when power is applied to the system. but is of interest to the programmer. you need RAM. however. If your program modifies any of its own instructions (this procedure is discouraged). Assembly Language and Processors OVERVIEW OF 8080/8085 HARDWARE To the programmer. the processor can both read from and write to RAM. Any time your program attempts to write any data to memory. RAM Even if your program resides entirely in ROM. these special memories are usually replaced by less expensive ROM's. Memory Since the program required to drive a microprocessor resides'in memory. it cannot alter the contents of ROM. There are two general types of memory: read only memory (ROM) and random access memory (RAM). These memories are useful during Read Only Memory) program development since they can be altered by a special PROM programmer. Also. the processor can only read instructions and data from ROM. that memory must be RAM. Instructions and unchanging data are permanently fixed into ROM and remain intact whether or not power is applied to the system. The mix of ROM and RAM In an application IS important to both the system designer and the programmer. By contrast. the programmer must know the physical addresses of the RAM in the system so that data variables 1-5 . ROM is typically used for program storage in single-purpose microprocessor applications. all microprocessor applications require some memory. ROM As the name Implies. your application is likely to require some random access memory. In high-volume commercial applications. Notice. memory is not part of the processor. the computer comprises the following parts: • • • • • • • Memory The program cou nter Work registers Condition flags The stack and stack pointer Input/output ports The instruction set Of the components listed above. For this reason.Chapter 1. that storing programs in RAM allows a multi-purpose system since different programs can be loaded to serve different needs. Two special types of ROM PROM (Programmable Read Only Memory) and EPROM (Eraseable Programmable are frequently used during program development. With RAM a program must be loaded into memory each time power is applied to the processor.

The program CJunter keeps track of the next instruction byte to be fetched from memory (which may be either ROM or RAM:. To alter the flow of program execution as with a iump irstruction or a call to a subroutine. these program elements can be repositioned aLer the program has been tested and after the system's memory layout IS final. 8080/8085 Internal Registers 1-6 . the processor overwrites the current contents of the program counter with t le address of the new Instruction. the Information in this chapter applies equally to the 8080 and the 8085. NOTE Except for the differences listed at the end of this chapter. Assembly Lang Jage and Processors can be assignee within those addresses. This process continues as Ie ng as program instructions are executed sequentially. Inal data b JS o 16-bit address bus u .Chapter 1. However. ROM INSTRUCTIONS CONSTANT DATA RAM INSTRUCTIONS VARIABLE DATA STACK INPUT PORTS OUTPUT PORTS Figure 1-3. The relocation feature is fully explained in Chapter 4 of this manual. Each time It fetches an instruction byte from memory. we reach the first of the 8080's Internal registers illustrated in Figure 1-3.--------. the processor increments the program counter by on". the relocation feature of this assembler allows you to code a program witho!lt concern for the ultimate placement of data and instructions. the program counter always indicates the next byte to be fetched. Therefore. Program Counter With the progr 1m counter. The next instruction fetch occurs from the new address. IACCUMULATORI FLAGS HIGH LOW POINTER COUNTER BUS LATCH C E L 8080 8085 STACK PROGRAM ADDRESS INSTRUC~ DECOD::R B D H IDATA BUS_ATCH I 8-bit bidirecti.

Notice that tillS location must be in RAM since data is to be written to memory. The choice of which to use depends on the instruction. H. The general purpose registers B. The accumulator also acts as a general-purpose register. Use M when an instruction addresses memory via the Hand L registers as in ADD M (add the contents of the memory location specified by the Hand L registers to the contents of the accumulator). Use H when an instruction acts upon the Hand L register pair as In INX H (increment the contents of Hand L by one). ADD B is an 8-blt operation. it is usually possible to achieve a common result with any of several different instructions. E. it is generally desirable to select a register-to-register instruction such as ADD B. C. as shown in Figure 1-3. The Instruction to be executed determines how the processor interprets the reference. For example. Thus. Some instructions reference a pair of registers as shown in the following: Symbolic Reference B D Registers Referenced Band C D and E Hand L Hand L (as a memory reference) A and condition flags (explained later In this section) H M PSW The symbolic reference for a single register IS often the same as for a register pair. Programs reference these registers by the letters A (for the accumulator). When possible. D. 1-7 .Chapter 1. and storing 16-bit address pointers. and L. Also.e moves a copy of the contents of register C to the memory location specified by the Hand L registers. B. but It has some special capabilities not shared with the other registers. Because of the 8080's extensive instruction set. Example: The following figures illustrate the execution of a move instruction. For example. Notice that the letters Hand M both refer to the Hand L register pair. The MOV M. These instructions tYPically I'equire only one byte of program storage. storing intermediate results In arithmetic operations. using data already present in a register eliminates a memory access and thus reduces the time required for the operation. A Simple add to the accumulator. many operations involving the accumulator affect the condition flags as explained In the next section. H. can be accomplished by more than half a dozen different Instructions. for example. Assembly Language and Processors Work Registers The 8080 provides an 8-bit accumulator and six other general purpose work registers. the Input/output instructions IN and OUT transfer data only between the accumulator and external I/O deVices. Also. D. By contrast PUSH B (which pushes the contents of the Band C registers onto the stack) is a 16-blt operation. C. the Instruction ADD B may be interpreted as 'add the contents of the B register to the contents of the accumulator. E. and L can proVide a wide variety of functions such as storing 8-bit data values.

NOTE The following description of the execution of the MOV M. 1-8 . When the memory respc nds. but does not account for normal bus control. refer to the User's Manual for your processor. the Instruction is decoded into the series of actions shown in Figure 1-5. Assembly Lanl uage and Processors IACCUMULATORI FLAGS e E L + INSTRU(~ DECOUER I HIGH STACK PROGRAM ADDRESS LOW 8080 8085 I B D H I I I I II II I I ! i I POINTER COUNTER BUS LATCH I Y DATA BUS LATCH f I I L l ROM • RAM Figure 1-4. For details concerning memory interface.Chapter 1.e instruction is conceptually correct. and then incrEments the program counter by one to Indicate the address of the next Instruction byte. Instruction Fetch The processor initiates the instruction fetch by latching the contents of the program counter on the address bus.

a zero result indicates that the opreands are equal. auxiliary carry. for example. the processor terminates execution of this instruction and initiates the next instruction fetch. Certain arithmetic and logical instructions alter one or more of these flags to indicate the result of an operation. Condition Flags The 8080 provides five flip flops used as condition flags. When the memory accepts the data. Your program can test the setting of four of these flags (carry.. Internal Work Registers Certain operations are destructive. zero. These registers are used for internal data transfers and for preserving operands in destructive operations. Assume.Chapter 1. a different instruction set if parity is odd. Assembly Language and Processors 8080 8085 IACCUMULATORI FLAGS C I INSTRUCTION DECODER B I I I I I I I HIGH STACK PROGRAM ADDRESS LOW ! POINTER COUNTER BUS LATCH I I I DATA BUS LATCH I f. Execution of MOY M.I D H E L ! I I + ROM + RAM + Figure 1-5. This allows you to alter the flow of program execution based on the outcome of a previous operation. The programmer cannot access these registers. is reserved for the use of the DAA instruction. The fifth flag. or return Instructions. the processor includes several work registers reserved for its own use.C Instruction To execute the MOY M. call. and parity) using one of the conditional iump. the processor latches the contents of the C register on the data bus and the contents of the Hand L registers on the address bus. It is important for the programmer to know which flags are set by a particular instruction. that your program is to test the parity of an input byte and then execute one instruction sequence if parity is even. Since it is unacceptable to destroy either of the operands. a compare is actually a subtract operation. For example. as will be explained later in this section. Coding a J PE (jump if parity is even) or J PO (jump if parity is 1-9 .C instruction. sign.

when a flag IS 'reset' it IS reset OFF (has the value zero). ORA. Assembly Lanfuage and Processors odd) instructl.y each Instruction are detailed in the IndiVidual Instruction descriptions In Chapter 3 of this manual. XRA. RLC. Example: Addition of ['vo one-byte numbers can produce a carry out of the high-order bit: Bit Number: AE= +74= 7654 3210 1010 1110 0111 01 00 0010 001 0 = 22 carry flag = 1 An addition t lat causes a carry out of the high order bit sets the carry flag to 1. The carry flag is also affected by the logical AND. but before the lump Instruction. treat the carry bit as trough it were a III nth bit of the accumulatol' See the deSCrIptions of the RAL. bit 7 of a result in the accumulator can be Interpletcd as a sign. For the operation to work correctly. Instructlolls that affect the sign flag set the flag equal to bit 7. Sign Flag As explained mder 'Two's Complement Representation of Data' In Chapter 2. OR. NOTE When a flag is 'set' It IS set ON (has the value one). and RRC instructions II' Chapter 3 of thiS manual. ANI. The carry flag IS also used as a 'borrow' flag In subtractions. The flags set I. you must be certain that the Intervening instructions do not affect the Carry Flag As ItS name it Wlies. ani exclUSive OR Instructions. In these cases. The jump executed by your program reflects the outcome of some previous operation unrdated to the IN instruction. and XRI instructions in Chapter 3. ORI. which move the contents of the accumulator one position to the left or right. yJU use It. A zero In bit 7 1·10 . but then have a number of intervel1lng instructions before desired flag. See the descrJJtlons of the ANA. For example. In other cases you wiii want to set a flag With one instruction. you must include some instruction that alter. you can add zero to tl e accumulator. the parity flag after the IN instruction. an addition that does not cause a carry resets the flag to zero. These instructions set ON or OFF particular bits of the accumulator.Chapter 1. The rotate In'truCtions. the carry flag IS commonly used to Indicate whether an addition causes a 'carry' into the next higher 01 del' digit. RAR.m Immediately foiiowing the IN (input) Instruction produces false results since the IN instruction does not affect the condition flags. as explallled under 'Two's Complement :~epresentatlon of Data' In Chapter 2 of thiS manual. ThiS sets the parity flag without altering the data In the accumulator.

Auxiliary Carry Flag The auxiliary carry flag indicates a carry out of bit 3 of the accumulator. Instructions that affect the parity flag set the flag to one for even parity and reset the flag to zero to indicate odd parity. call. Assembly Language and Processors indicates a positive value. that adding one to this value produces a non-decimal result: 0001 1001 +00000001 0001 1010 = lA The DAA instruction converts hexadecimal values such as the A in the preceding example back into binary coded decimal (BCD) format. and return instructions can test for positive and negative values. the value 0001 1001 is equivalent to 19. The DAA performs the following addition to correct the preceding example: 0001 1010 +00000110 0001 0000 +0001 0000 (auxiliary carry) 0010 0000 = 20 1-11 . The DAA instruction requires the auxiliary carry flag since the BCD format makes it possible for arithmetic operations to generate a carry from the low-order 4-bit digit Into the high-order 4-bit digit. Thus. a one indicates a negative value.Chapter 1. A result that has a carry and a zero result also sets the zero bit as shown below: 1010 0111 +0101 1001 0000 0000 Carry Flag = 1 Zero Flag = 1 Parity Flag Parity IS determined by counting the number of one bits set in the result in the accumulator. it has the value 25.) Notice. The auxiliary carry flag and the DAA instruction allow you to treat the value in the accumulator as two 4-bit binary coded decimal numbers. however. You cannot test this flag directly in your program. This value is duplicated in the sign flag so that conditional iump. it is present to enable the DAA (Decimal Adiust Accumulator) to perform its function. (If this value is interpreted as a binary number. Zero Flag Certain Instructions set the zero flag to one to indicate that the result in the accumulator contains all zeros. These instructions reset the flag to zero if the result in the accumulator is other than zero.

increment. Stack and Stack Po inter To understan j the purpose and effectiveness of the stack. the address of th. YOiJr program must initialize the stack pointer. The mechani. the staok. OR. As items are 1-12 .) There is some difference in the handling of the auxiliary carry flag by the logical AND instructions In the 8080 processor and the 8085 pro . a return instruction pops that previously-stored address off the stack and puts it back into the program counter. compare. subtract. Assume that !our program requires a multiplication routine. and all logical AND. You can recode this routine inline each time it is needed. This means that your program must load the base address of the stack into the stack pointer. next instruction (the contents of the program counter) IS pushed onto the stack. (Sinoe the 8080 has no multiply instruotions.m that makes this possible IS. and excl Jsive OR instructions. The stack pointer IS a hardware register maintained by the processor. The base address of the stack is commonly assigned to the highest available add'ess in RAM.Chapter 1. decrement.t the flag to reflect the logical OR of bit 3 of the values involved in the AND operation. subroutine The 8080 provides instruotions that call and return from a subroutine. This is because the stack expands by decrementing the stack pointer. Program exe( ution then continues as though the subroutine had been coded inline. When the call instruction is executed.essor. 3x4 is equivalent to 3+3+3+3. For example. Or. At the end of the subroutine. The 8085 logical AND instructions always set the auxiliary flag ON. However. The contents of the program :ounter are replaced by the address of the desired subroutine. it is useful to understand the concept of a subroutine. The 8080 logical AND instructions s. (See the descriptions of these Instructions In Chapter 3. you can code a subroutine: nline Coding Subroutine nline routine nline routine nline routine 1 I I I CALL CALL CALL 1 I I I . The stack is simply an area of random access memory addi essed by the stack pointer.) Assume further that your progralT needs this multiply routine several times. this oan be performed through repetitive addition. of course. but this can lise a great deal of memory. AssemblY Lan5uage and Processors The auxiliary carry flag is affected by all add.

you must count up all instructions that add data to the stack. for any IIlstruction that adds to the stack. Notice that you must be sure to remove data your program adds to the stack. of course. However. To be more precise. the subroutine must remove that data before executing a return instruction. As general rule. Savll7g Program Status It is likely that a subroutine requires the use of one or more of the working registers.' Stack is still a most descriptive term because you can always put something else on top of the stack. it IS equally likely that the main program has data stored in the registers that it needs when control returns to the main program. Ultimately. you must be certain that the stack will not expand into areas reserved for other data. a subroutine can call a subroutine. The most critical factor is the maximum size of the stack. it expands into memory locations with lower addresses. As you write your program. 1-13 . A return instruction pops sixteen bits off the stack and places them in the program counter. The results are unpredictable. Nonetheless. the stack pointer is incremented back toward Its base address. which adds data to the stack. but probably not what you want.Chapter 1. A call Instruction pushes the contents of the program counter (which contains the address of the next instruction) onto the stack and then transfers control to the desired subroutine by placing its address in the program counter. The only limitation to the number of items that can be added to the stack is the amount of RAM available for the stack. a subroutine should save the contents of a register before using it and then restore the contents of that register before returning control to the main program. Otherwise. For most applications. Otherwise. The two basIc operations are PUSH. if you call a subroutine and the subroutine pushes data onto the stack. The subroutine can do this by pushing the contents of the registers onto the stack and then popping the data back into the registers before executing a return. and POP. this means that you must assign data that requires RAM to the lowest RAM addresses available. Therefore. any left-over items on the stack may cause the stack to grow into portions of RAM you intend for other data. In terms of programming. you can subtract any intervening instruction that removes an Item from the stack. Stack Operations Stack operations transfer sixteen bits of data between memory and a pair of processor registers. the most recent item on the stack is known as the 'top of the stack. Notice that the POP instructions must be in the opposite order of the PUSH instructions if the data is to be restored to its original location. which removes data from the stack. The amount of RAM allocated to the stack is important to the programmer. The following instruction sequence saves and restores all the working registers. Assembly Language and Processors added to the stack. your program should remove from the stack any data it places on the stack. For example. the return IIlstructlon pops data from the stack and places It in the program counter. This requires the programmer to keep track of what is in the stack. As Items are removed from the stack. and so on.

0 and E. EI. a discussion of design techniques IS beyond the scope of t liS manual. The IN rnstrw tion latches the number of the desired port onto the address bus. respectively. Thus. The IN and OUT instructl<lns initiate data transfers. Notice that the IN and OUT instructions Simply Initiate a data transfer It is the responsibility of the peripheral device to dete~t that It has been addressed. As 500n as a byte of data returned to the data bus latch. 01. 0. for example.) 1-14 . (PUSH PSW adds three bits of filler to expand the condition flags into a full byte. (The RIM and SIM instructions apply only to the 8085. and Hand L register pairs. The program status wOl'd IS a 16-blt word comprising the contents of the accumulator and the five c.jnpitlon flags. refer to the 8080 or 8085 Microcomputer Systems User's Manual. OUT. For related prJgrammlng rnformation. and RIM and SIM Instructions In Chapter 3 of this manual. and H refer to the Band C. the instruction IN 5 latches the bit configura- tion 0000 01 (1 0000 0101 onto the address bus. RST. hera I device.) Input/Output Ports The 256 rnpul/output ports provide communication with the outside world of perrpheral devices. Assembly langJage and Processors SUBRTN: PUSH PUSH PUSH PUSH PSW B o H subroutine coding POP POP POP POP H 0 B PSW RETURN The letters B.Chapter 1. The specified )ort number 15 15 duplicated on the address bus. For additional hardware Information. see the descriptions of the IN. Notice also that it is possible to dedicate any number of ports to the same perr. You might use a number of ports as control signals. it is transferred into the accumulator. PSW refers to the program s atus word. Because input and output are almost totally application dependent. POP PSII strrps out these filler bits. The OUT inst: uetion latches the number of the desired port onto the address bus and latches the data in the accumulator onto the data bus.

Jump Instructions include al6-bit address as part of the instruction. For example. For example. the name of an add instruction is ADD. the accumulator IS implied as a second operand. The addressing mode of certain Instructions is implied by the instruction's function. the Instruction MVI D. For example. Thus. the DAA (decimal adjust accumulator) instruction deals with the accumulator. the PCHL Instruction exchanges the contents of the program counter with the contents of the Hand L registers. a few of these Instructions deal with 16-bit register pairs. Addressing Modes Instructions can be categorized according to their method of addressing the hardware registers and/or memory. For example. as in the CPI instruction shown previously The MV! (move Immediate) Instruction can move its immediate data to any of the working registers. H or L as well as the operation code. All but two of the Immediate instructions use the accumulator as an Implied operand. you must specify one of the registers A through E. The processor fetches the next byte Into one of its internal registers and then performs the compare operation. QUite a large set of instructions call for register addressing. Implied AddresslI1g. With these instructions. With these instructions. including the accumulator. For example. The LXI Instruction (load register pair immediate) is even more unusual in that ItS Immediate data IS a 16-bit value. This instruction is commonly used to load addresses Into a register pair. the instruction CMP E may be Interpreted as 'compare the contents of the E register with the contents of the accumulator. the name of an add Immediate Instruction is AD!. For example. Immediate AddresslI1g. LXI IS the instruction most commonly used for this purpose. Assembly Language and Processors Instruction Set The 8080 incorporates a powerful array of Instructions. Hexadecimal 43 IS the Internal representation for the letter C. the Instruction CPI 'C' may be Interpreted as 'compare the contents of the accumulator with the letter c.Chapter 1. When this instruction IS executed. Register AddresslI1g. However. This section provides a general overview of the Instruction set.' Most of the Instructions that use register addressing deal with 8-bit values. the instruction LXI SP.OFFH moves the hexadecimal value FF to the D register. this instruction has the hexadecimal value FE43. The detailed operation of each instruction is described In Chapter 3 of tillS manual. Instructions that use Immediate addressing have data assembled as a part of the instruction Itself. the STC (set carry flag) instruction deals only with the carry flag. Notice that the names of the Immediate instructions indicate that they use immediate data. YOUl' program must initialize the stack pointer. Thus. 1-15 . the processor fetches the first instruction byte and determines that it must fetch one more byte. or to memory.30FFH loads the stack pointer with the hexadecimal value 30FF Direct AddresslI1g. As mentioned previously.' When assembled. the Instruction J MP 1000H causes a jump to the hexadecimal address 1000 by replacing the current contents of the program counter with the new value 1000.

for example. 7976. however. MOV MVI LDA STA LHLD SHLD Move Move Load Store Load Store Immediate Accumulator Directly from Memory Accumulator Directly in Memory Hand L Registers Directly from Memory Hand L Registers Directly in Memory ALL MNEMONICS © 7974. Combmed Ad. combines direct addressing and register Indirect addressing. (The Injividual instruction descriptions in Chapter 3 specify the number of cycles and states required for each Instructic n. for example. Register IndirEct Addressing.) Instruction Nam/ilg Conventions The mnemonl<s assigned to the instructions are designed to indicate the function of the instruction.he stack. For example. Addressing modes affect both the amount of time required for executing an Instruction and the amount of memory reqUired for ItS storage. the timing of a four state instruction may range from 1. and two for the 16-bit lddress.C moves the contents of the C register into the memory address stored in the Hand L register pair. The processor can access memory once during each processor cycle. The Instruc· tions fall into the following functional categories: Data Tral1Sfer Group. More important.) The length of a state depends on the clock frequency specified for your system. Assemblv Lang Jage and Processors Instructions that include a direct address require three bytes of storage: one for the Instruction code. More memory accesses require more execution time. The CALL instruction pu. instructions that use implied or register addres. 1 he instruction LDAX B loads the accumulator with the byte of data specified by the address In the Band C register pair. The data transfer instructions move data between registers or between memory and registers. Each cycle comprises a variable number of states. Thus. A CALL instruction. 7977 INTEL CORPORA nON 1-16 . Thus.ing execute very qUickly since they deal directly with the processor hardware or with data already present in hardware I·egisters. and two more to push the contents of the program counter onto '.hes the current contents of the program counter into the memory location specified by the stack pointer Timmg Effect~ of Addressmg Modes. is that the entire instruction can be fetched with a single memory access. requires five memory accesses: three to access the entire Instruction.920 microse:onds through 8 microseconds. The direct address in a CALL instruction specifies the address of the deSIred subroutine. Some instructions use a combination of addressing modes. A CALL instruction. The number of memory accesses required is the single greatest factor in determining execution timing. the Instruction MC>V M. 7975. (The 8085 has a maximum clock frequency of 320 nanoseconds and therefore :an execute instructions about 50% faster than the 8080. the register indirect address IS the stack pointer.Chapter 1.lressmg Modes. Register indirect instructions reference memory via a register pair. and may range from 48) nanoseconds to 2 microseconds.

7975. ANA ANI ORA ORI XRA XRI Logical AND with Accumulator Logical AND with Accumulator Using Immediate Data Logical OR with Accumulator Logical OR with Accumulator Using Immediate Data Exclusive Logical OR with Accumulator Exclusive OR Using Immediate Data The compare instructions compare the contents of an 8·blt value with the contents of the accumulator: CMP CPI Compare Compare Using Immediate Data ALL MNEMONICS © 7974. or decrement data in registers or memory. and Exclusive OR instructions enable you to set specific bits in the accumulator ON or OFF. AND.Chapter 1. 7976. The logical. Assembly Language and Processors An 'X' In the name of a data transfer instruction implies that it deals with a register pair: LXI LDAX STAX XCHG XTHL Load Register Pair with Immediate data Load Accumulator from Address in Register Pair Store Accumulator in Address in Register Pair Exchange Hand L with D and E Exchange Top of Stack with Hand L Arithmetic Group. 7977 INTEL CORPORA nON '-17 . This group performs logical (Boolean) operations on data in registers and memory and on condition flags. ADD ADI ADC ACI SUB SUI SBB SBI INR DCR INX DCX DAD Add to Accumulator Add Immediate Data to Accumulator Add to Accumulator Using Carry Flag Add Immediate Data to Accumulator Using Carry Flag Subtract from Accumulator Subtract Immediate Data from Accumulator Subtract from Accumulator Using Borrow (Carry) Flag Subtract Immediate from Accumulator Using Borrow Increment Specified Byte by One Decrement Specified Byte by One Increment Register Pair by One Decrement Register Pair by One Double Register Add: Add Contents of Register Pair to Hand L Register Pair Logical Group. increment. The arithmetic instructions add. OR. subtract.

either unconditionally or conditionallY. 7976. 1977 INTEL CORPORA TlON 1-18 . 7975. fhe unconditional branching instructions are as follows: jMP CALL RET Jump Call Return Conditional bnnching Instructions examine the status of one of four condition flags to determine whether the specified brant h IS to be executed. Assembly Lang1lage and Processors The rotate instructions shift the contents of the accumulator one bit position to the left or right: RLC RRC RAL RAR Rotate Rotate Rotate Rotate Accumulator Left Accumulator Right Left Through Carry Right Through Carry Complement ald carry flag instructions: CMA CMC STC Complement Accumulator Complement Carry Flag Set Carry Flag Branch Group. the conditional branching Instructions are specified as follows: Jumps Calls Returns jC jNC jZ jNZ jP jM jPE jPO CC CNC CZ CNZ CP CM CPE CPO RC RNC RZ RNZ RP RM RPE RPO (Carry) (No Carry) (Zero) (Not Zero) (Plus) (Minus) (Parity Even) (Parity Odd) Two other instructions can effect a branch by replacing the contents of the program counter: PCHL RST Move Hand L to Program Counter Special Restart Instruction Used with Interrupts ALL MNEMONICS © 1974. The branching instructions alter normal sequential program flow. The conditions that may be specified are as follows: NZ Z NC C PO PE P M Not Zero (Z = 0) Zero (Z = 1) No Carry (C = 0) Carry (C = 1) Parity Odd (P = 0) Parity Even (P = 1) Plus (5 = 0) Minus (5 1) Thus.Chapter 1.

The STC (set carry) and CMC (complement carry) instructions are also shown hel'e.H. but do not affect condition flags. ALL MNEMONICS © 7974.Chapter 1. The instructions listed below the accumulator move data Into or out of the accumulator. Code Meaning REGM S The opel'and may specify one of the S-bit registers A. 7976. The instructions listed above the accumulator all act on the data in the accumulator.D&E. which calls for two operands. and Machine Contra/Instructions. //0.D.E. Accumulator Instructions The following illustration shows the Instructions that can affect the accumulator. The type of operand allowed for each Instruction IS Indicated through the use of a code.C. Assembly Language and Processors Stack. The following instructions affect the stack and/or stack pOinter' PUSH POP XTHL SPHL The I/O instructions are as follows: IN OUT Push Two Bytes of Data onto the Stack Pop Two Bytes of Data off the Stack Exchange Top of Stack with Hand L Move contents of Hand L to Stack Pointer Initiate Input Operation Initiate Output Operation The machine control Instructions are as follows: EI DI HLT NOP Enable Interrupt System Disable Interrupt System Halt No Opel'ation HARDWARE/INSTRUCTION SUMMARY The following illustrations graphically summarize the instruction set by showing the hardware acted upon by specific instructions.H&L. 7977 INTEL CORPORA TlON 1-19 . Designates S-bit immediate operand. or L or M (a memory reference via the 16-blt address in the Hand L registers). The MOV Instruction. Designates an S-bit port number Designates a 16-blt register pair (B&C. or SP). 7975. Designates a 16-blt immediate operand. the Instruction does not allow operands. Designates a 16-bit address.B. When no code is given. can specify M for only one of its operands. and all except CMA (complement accumulator) affect one or more of the condition flags.

Assembly Lan .-1 I MOV REGM S: REC Msi ACCUMULATORI FLAGS I B D C I_ _ ---l I I I STC CMC HIGH STACK LOW POINTER COUNTER I E L J~ LDAX} STAX EC.Chapter 1. 7975.REG S ALL MNEMONICS © 7974.uage and Processors ADD ADC SUB SBB ANA XRA ORA CMP RLC RAR REGM S RAL CMA INR} DCR ADI ACI SUI SBI ANI XRI ORI CPI RRC DAA REGM S D S .EGMS. 7976. 7977 INTEL CORPORA TlON 1·20 .DE LDA I STA} MVI MOV 1'16 [J J I PROGRAM I HI MEMORY STACK S F.

D.". none of these instructions affect the condition flags. DAD affects only the carry flag.PSW ALL MNEMONICS © 7974. 7977 INTEL CORPORA TlON 1-21 . 7975. 7976.- _I PROGRAM! COUNTER I ! POINTER XTHL LHLD SHLD I MEMORY STACK PUSH } POP B.H..Chapter 1.- DCX DAD INX} HIGH REG 16 LOW fSPH' -I STACK PCHL D H I"""xcHG L . Except for DAD (which adds thecontents of the B&C or D&E register pair to H&L).. Assembly Language and Processors Register Pair (Word) Instructions The following instructions all deal with 16-bit words. IACCUMULATORI B FLAGS C E ..

7976.7977 INTEL CORPORATION 1-22 .7975. stack pointer. and stacK. Call and Return Instructions affect the program coullter. Jump instructions affect only the program counter. ~CUMjLATORI FLAGS C E L I HIGH LOW POINTER ~i ~) I I I PCHL COUNTER RST ~I ~ JMP JC JZ IP CALL RET RNcl RNZ A RM J> 16 JNC CC JNZ (> A CZ 1M I 16 CP 1 J CNC} RC CNZ A RZ CM 16 RP JPE JPO CPE CPO RPE RPO MEMORY CONTROL INSTRUCTIONS RST Nap HLT EI STACK 01 SIM} 8085 only RIM ALL MNEMONICS'~ 7974. thereby altering the normal sequential execution flew. Assembly Lalguage and Processors Branching Instructions The followin~ Instructions can alter the contents of the program counter.Chapter 1.

7977 INTEL CORPORA nON 1-23 . s OUTPUT PORTS CONTROL INSTRUCTIONS RST NOP HLT EI DI SIMI RIM] MYI DS MOY REGMS.Chapter 1. ALL MNEMONICS © 7974.H& L.or SP).REGM S LXI REG 16 . or l or M (a memory reference via the 16-bit address in the Hand L registers). 7976.D.C. Designates an S-bit port number. POINT. 7975.:~~H} B. Designates a '16-bit register pair (B&C.H.D&E.PSW SOS5 ONLY REGM S The operand may specify one of the S-bit registers A. can specify M for only one of its operands. Designates a 16-bit address. which calls for two operands.D.E.REGM S CODE --STAC"K--MEANING ~. The MOY instruction. Assembly language and Processors Instruction Set Guide The following is a summary of the instruction set: ADDl ADC SUB SBB ANA XRA ORA CMP ADI ACI SUI SBI ANI XRI ORI CPI REGM S DS RLC RAL RRC RAR CMA DAA INR} DCR REGM S "ACCUMULATORI MOY REGMS.D 16 1 FLAGS C E L ISTC CMC INX} IDCX REG 16 HIGH STACK LOW . Designates S-bit immediate operand.ER RST ! I B D H I I ~ XCHG jMP jC jNC1 jZ jNZ A jP jM 16 jPE jPO CALL CC CZ CP CPE CNCl CNZ A CM 16 CPO RET J J RC RZ RP RPE RNCi RNZ ~ A RM 16 RPO J ~ LHLD} STHD A16 MEMORY INPUT PORTS OUT P LDAX\ BC DE STAX) . Designates a 16 -bit immediate operand.B.H.

the 8085 i"~truction set is identical to and fully compatible with the 8080 instruction set. Assemblv Lalguage and Processors 8085 PROCESSOR DIFFERENCES The differences between the 8080 processor and the 8085 processor will be more obvious to the system designer than to the programmer. Except for two additional instructions. the TRAP interrupt Input is non-maskable and cannot be di . 1-24 .5 interrupt. however. that 8085 hardware interrupt RESTART addresses fall between the eXisting 8080 RESTART addresses. the higher system speed of the 8085 may alter the time values of such routines. A non-maskable TRAP interrupt for handling serious problems such as power failures. programming for interrupts is little changed. the processor always recognizes the higher priority Interrupt first. the new features of the 8085 are summarized In the two new Instructions SIM and RIM. Program routines that service interrupts h. These instructions differ from the 8080 instructions in that each has multiple functions. Details of these instructions are cov"red in Chapter 3. These priorii ies apply only to the sequence in which interrupts are recognized. The RIM Instruction reads a bit 0 serial data if one is present and the Interrupt mask Into the accumulator.ve no special priority. Thus.5 interrupt can Interrupt the service routine for an RST7. The SIM instruction sets the interrupt mask and/or writes out a bit of serial data. The programmer must place the deSIred interrupt mask and/or serial output In the accumulator prior to execution of the SIM instruction. If you want to protect a service routine from interruption. Most programs written for the 8680 should operate on the 8085 without modifica1ion. only four bytes are available for certain RST instructions. either disable the interrupt system (01 instruction).5 RST5. Despite the Ilew Interrupt features of the 8085. Execution speeds approximately 50% faster than the 8080. Incorporation in the processor of the features of the 8224 Clock Generator and Driver and the 8228 System Controller and Bus Driver. Input/output lines for serial data transfer Programming for tile 8085 For the prog ·ammer. The only programs that may require changes are those with critical timing routines. The interrup:s have the following priority: TRAP RSn.5 RST6. or mask out other potential interrupts (SIM instruction). be certain to provide an interrupt routine for it. an RST5. Three separately maskable interrupts that generate internal RST instructions. Notice.Chapter 1.abled. Therefore. Also. If your application uses this input.5 INTR highest lowest When more han one interrupt is pending. A partial listing of 8085 design features Includes the following: • • • • • • A single 5 volt power supply.

the 8085 skips over the third instruction byte and immediately fetches the next Instruction. 1-25 . Skipping the unnecessary byte allows for faster execution.Chapter 1. The 8085 evaluates the condition while it fetches the second instruction byte. The 8080 fetches all three instruction bytes whether or not the condition is satisfied. Assembly Language and Processors Conditional Instructions Execution of conditional instructions on the 8085 differs from the 8080. If the specified condition is not satisfied.

.

Comment Thc fields may be separated by any numbe[. but the characters are printed exactly as they were Input in the assembly listing. the assemblc[. Both upper. Controls are dcscribed [n the operator's manual for your version of the assembler.of blanks. directives. The following speCial characters: 2-1 . Specific instructions (see Chapter 3) and directives (see Chapters 4 and 5) may have specific coding rules.and lower-case letters are allowed. the coding of such Instructions and SOURCE LINE FORMAT Assembly language [nstructlons and asscmblcr directives may consist of up to four fields. A through Z. ASSEMBLY LANGUAGE CONCEPTS INTRODUCTION Just as the English languagc has its [-ulcs of grammar. Character Set The following characters are Icgal In asscmbly languagc source statements: • Thc lctters of the alphabet. • • The digits 0 through 9. but must be separated by at least one delimlter_ Each IIlstruction and directive must be entered on a single line term lila ted by a carriage return and a line fced. [5 Th[s assembler recognizcs three types of source lines: IIlstruct[ons. 50. Internally. This manual describes instructions and dircctlves. Th[s chapter dcscribes thc general rules for coding sourcc lincs. Even directives must conform to thc gencral rules in this chapter. assembly language has certalll coding rules. No continuation lines are possiblc. as follows: Label:) { Name Opcodc Operand . The source line the assembly language equivalent of a sentencc. and controls. but you may havc lines conSisting enti[-ely of commcnts.2.trcats all letters as though they wcre upper-casc.

any ASCII character may appear in a string enclosed single quotes or in a comment. Assembly Lan luage Concepts Character + Meaning Plus sign Minus sign Asterisk Slash Comma Left parenthesis Right parenthesis Single quote Ampersand Colon Dollar sign Commercial 'at' sign Question mark Equal sign Less than sign Greater than sign Percent sign Exclamation point Blank or space Semicolon Period Carnage return Form feed Horizontal tab In * & $ @ < % > blank CR FF HT .ter 5 for a description of macros.Chapter 2. Notice that many delimiters are related to the macro feature explained In Chapter 5.. In addition. Delimiters Certain chara<:ters have special meaning to the assembler in that they function as delimiters. The following list defines the delimiters recognized by the assembler. a field.ource statement. or a component of a field. Delimiters Jsed for macros are shown here so that you will not accidentally use a delimiter improperly Refer to Chal. Delimiters define the end of a . 2-2 .

also used to delimit a parameter list delimit a macro parameter that is to be evaluated prior to substitution an escape character used to pass the following character as part of a macro parameter when the character might otherwise be interpreted as a delimiter delimiter for comments in macro definitions when the comment is to be suppressed when the macro is expanded & ampersand <.Chapter 2.• J pair of parentheses carriage return horizontal tab semicolon colon delimit an expression CR HT statement terminator field separator or symbol terminator comment field delimiter delimiter for symbols used as labels delimit macro prototype text or formal parameters for concatenation delimit macro parameter text which contains commas or embedded blanks. but the first character must be alphabetic or the special characters '7' or '@' The label name must be terminated with a colon. A label may contain from one to SIX alphanumeric characters. including macro parameters delimit a character string pair of single quote characters (. A symbol used as a label can be defined only once in your program.. (See 'Symbols and Symbol Tables' later in this chapter... Assembly Language Concepts Charaeter(s) blank Meaning one or more blanks comma Use field separator or symbol terminator separate operands in the operands field. > % pair of angle brackets percent sign exclamation point double semicolon Label/Name Field Labels are always optional.) 2-3 . An instruction label is a symbol name whose value is the location where the instruction is assembled.

and MACRO directives.Chapter 2. the question mark character.MOVE B TO ACCUMULATOR Comment Field The optiona comment field may contain any information you deem useful for annotating your program. you should use them lib. Operand Field The operand field identifies the data to be operated on by the specified opcode. Opcode Field This required field contains the mnemonic operation code for the 8080/8085 instruction or assembler directive to be perforned. each of which is described below. 2-4 .rally since it is easier to debug and maintain a well documented program. Names follow the same coding rules as labels. there IS no reed to separate the comment from the previous field with one or more spaces. the first operand identifies the destination (or target) of the operation's result. spaces are commonly Lsed to improve the readability of the comment. and the decimal digits 0 throl gh 9. The only coding requirement for this field is that it be preceded by a semicolon. CODING OPERAI~D FIELD INFORMATION There are feur types of information (a through d in the following list) that may be requested as items in the operand field. Examples: MOil MV A. However. Some instructions require no operands. EQU. Although comments are always optional. and tlie second operand specifies the source data.MOVE CONTENTS OF REG C TO ACCUMULATOR . The label/name field must be empty for the LOCAL ind ENDM directives. Otners require one or two operands. except that t ley must be terminated with a blank rather than a colon. As a general rule. the information may be specified in nine ways. when two operands are required (as in data transfer and lrithmetic operations). Assemblv Lallguage Concepts Alphanumerit: characters include the letters of the alphabet.C A:B' . A name is required for the SET. Because the semicolon is a delimiter.

Each binary number must be followed by the letter B.OBAH . Label Opcode Operand Comment NOW: MVI D.15 E.Chapter 2. Label Opcode Operand Comment LABEL: MVI A.nQ . Thus. Assembly language Concepts OPERAND FIELD INFORMATION Information reqUIred Ways of specitying (a) (b) (c) (d) Register Register Pair Immediate Data 16-bit Address (1) (2) (3) (4) (5) (6) (7) (8) (9) Hexadecimal Data Decimal Data Octal Data Binary Data Location Counter ($) ASCII Constant Labels assigned values Labels of instructions or data Expressions Hexadecimal Data.LOAD REG C WITH HEX BA Each decimal number may be identified by the letter D immediately after its last digit or may stand alone. or binary is assumed to be decimal.LOAD OCTAL 72 INTO ACCUM Binary Data. Each octal number must be followed by the letter 0 or the letter Q.l1l1 011 OB . octal.LOAD E WITH 15 DECIMAL Octal Data. the following statements are equivalent: Label Opcode Operand E. MVI C. Any number not specifically identified as hexadecimal.LOAD REGISTER D . Each hexadecimal number must begin with a numeric digit (0 through 9) and must be followed by the letter H.15D Comment ABC: MVI MVI . Label Opcode Operand Comment HERE: DecImal Data.WITH OF6H 2-5 .

The $ character refers to the current location counter.LOAD E REG WITH 8-BIT ASCII . The location counter contains the address wher~ the current instruction or data statement will be assembled. 2-6 . The label assigned to an IIlstructlon or a data definition has as its value the address of tile first byte of the instruction or data. All of the operand types discussed previously can be combined by operators to form an expression.jUMP TO INSTRUCTION AT THERE fHERE.9FH D.j UMP TO ADDRESS 6 BYTES BEYOND . Instructions elsewhere in the program can refer to this address by I:S symbolic label name. \2: Operand Comment MYI MYI D. The SET and EQU directives can assign values to labels. nguage Concepts Location Counter.REPRESENTATION OF * TODAY"S DATE' Labels Assig led Values.truction or Data. In fact. assume that VALUE has been assigned the value 9FH. Opcode Operand Comments -jERE: jMP THERE .YALUE Labels of In. MVI D.9FH Expressions. label Opcode Operand $+6 Comment co: jMP .THE FIRST BYTE OF THIS . the two statements are equivalent: Opcode \1. Assemblv L. In the following example. One or more ASCII characters enclosed in single quotes define an ASCII constant.abel Opcode Operand Comment MYI DATE: DB E '*' .Chapter 2. further discussion of expressions is deferred until later in this chapter. i.INSTRUCTION ASCII Const1t7t. Because the rules for coding expressions are rather extensive. Two successive sillgle quotes must be used to represent one slllgie quote Within an ASCII constant. the example given for the location counter ($+6) IS an expression that combines the location counter with the decimal number 6.

To form the ten's complement of a decimal number. the decimal value 31. the ten's complement of 12. Such coding is typically used where the object program modifies itself during execution. TWO'S COMPLEMENT REPRESENTATION OF DATA Any 8-bit byte contains one of the 256 possible combinations of zeros and ones. an instruction like JMP A is flagged as an illegal use of a register. which simplifies matters even more. 87+1=88. The only assembler directives that may contain register-type operands are EQU. Assembly Language Concepts Instructions as Operands. or simply the bit pattern 00011111. Register-Type Operands. then add one to the result to form the ten's complement. let us first examine two examples of decimal arithmetic: 35 -12 23 35 +88 123 Notice that the results of the two examples are equal if we disregard the carry out of the high order position in the second example. For example. arithmetic operations within the computer are binary. The second example illustrates subtraction performed by adding the ten's complement of the subtrahend (the bottom number) to the minuend (the top number). One operand type was intentionally omitted from the list of operand field information: Instructions enclosed in parentheses may appear in the operands field. the code 1 FH may be interpreted as an instruction (Rotate Accumuiator Right Through Carry). Arithmetic instructions assume that the data bytes upon which they operate are in the 'two's complement' format. Registers can be assigned alternate names only by EQU or SET. Expressions containing register-type operands are flagged as errors. a technique that is strongly discouraged. Thus. The operand has the value of the left-most byte of the assembled instruction. The ability to perform subtraction with a form of addition is a great advantage in a computer since fewer circuits are required. Also. 99-12=87. as the hexadecimal value 1 F. 2-7 . and actual parameters in macro calls. To understand why. Only instructions that allow registers as operands may have register-type operands. Any particular combination may be interpreted in a number of ways. SET.Chapter 2. Thus. Label INS: Opcode Operand (ADD C) DB The statement above defines a byte with the value 81 H (the object code for an ADD C instruction). first subtract each digit of the subtrahend from 9 to form the nine's complement.

a negative two's complement number always compares higher than a positive number. This is because the processors complement the carry flag at the end of a subtract operation so :hat it can be used as a 'borrow' flag in multibyte subtractions. Thus. As an examp. the high ordu bit indicates the sign. When a byte IS Interpreted as a signed two's complement number. you must again form its two's complement: 111 0 1001 = 0001 + 0001 011 0 1 0111 = 23 Two's compl·'ment numbers may also be signed. It must also be stated that the proper interpretation of data is a r r.ogramming responsibility. 0111 1111 equals +127 At the beglnlling of this description of two's complement arithmetic. consider the compare instruction. St> the carry flag IS set OFF. the carry flag IS set ON if we subtract 35 from 12: 12 = 000011 00 -35 = 0010 0011 00001100 +1101 1101 1110 1001 = 11 01 + 11 00 -----'- = 233 or --105 1101 1101 In this case. By contrast. Thus.use the negative number's high order bit IS always ON. The compare logiC considers only the raw bit values of the Items being compared. if this operation were performed by the 8080 or [he 8085. Notice also that the result is stored In a complemented form. Your program must account for this condition. the subtraction IS performed through a form of addition. if any Therefore. 2-8 .e. he absence of a carry indicates that a borrow IS reqUired from the next higher order byte. th 0 processor sets the carry flag ON. no borrow IS reqUired. Assembly Lalguage Concepts The processol forms the two's complement of a binary value simply by reversing the value of each bit and then adding one tc the result. bec. As a result. Any carry out of the high order bit is ignored when the complement is formed. Therefore. the meanings of the flags set by the compare instruction are reversed. In the example shown. If you want 0 Interpret this result as a deCimal value. by dis 'egarding the carry out of the high order position. A zero In thiS bit indicates a positive number.Chapter 2. a one a negative number. the subtractic n shown previously is performed as follows: 35 -12 23 = 001 0 = 0000 0011 1100 = 1111 + 0011 00100011 +11110100 1 0001 0111 = 23 1111 01 00 Again. HO\/ever. it was stated that any 8-blt byte may contain one of tile 256 possible combinations of zeros and ones. the carry flag would be set OFF at the end of the subtraction. The seven low order bits provide the magnitude of the number.

The assembler performs the same function. Symbols of the form '??nnn' are generated by the assembler to uniquely name symbols local to macros. global or limited. It tells the assembler where the next instruction or operand is to be placed in memory.Chapter 2. Suppose Richard Roe rents box 500 for two months. The mnemonic names for machine instructions and the assembler directives are all reserved symbols. The assembler references its location counter during the assembly process to calculate these addresses for you. variable name. and Assembler-Generated Symbols Reserved symbols are those that already have special meaning to the assembler and therefore cannot appear as user-defined symbols. keeping track of symbols and their values in a symbol table. Note that you do not have to assign values to symbolic addresses. The postal clerk correlates the symbolic names and their absolute values In hiS log book. absolute address (500) or by a symbolic. The assembler regards symbols as haVing the following attributes: reserved or user-defined. the command jMP $+6 forces a jump to the instruction residing six memory locations higher than the JMP instruction. He can then ask for his letters by saying 'Give me the mail in box 500: or 'Give me the mail for Roe. he too can ask for his mail by either box number 500 or by his name. and absolute or relocatable. the following analogy may help clarify the distinction between a symbolic and an absolute address. User-Defined. The content of the post office box can be accessed by a fixed.' If Donald Smith later rents box 500. 2-9 .) Symbol Characteristics A symbol can contain one to six alphabetic (A-Z) or numeric (0-9) characters (with the first character alphabetic) or the special character '7' or '@'. permanent or redefinable. Assembly Language Concepts SYMBOLS AND SYMBOL TABLES Symbolic Addressing If you have never done symbolic programming before. The locations in program memory can be compared to a cluster of post office boxes. Reserved. (The location counter does for the assembler what the program counter does for the microcomputer. A dollar sign can be used as a symbol to denote the value currently in the location counter For example.

for additional information about macros. 2·10 .. for example. If you assign the symbolic name RTN to a second routine. Certain symbJls have meaning only within a macro definition or within a calJ to that macro. or MACRO directives (see Chapters 4 and 5). finition. User-defined' ymbols are symbols you create to reference Instruction and data addresses. SET. If tile symbolic names within macros were global. Assembler-ger erated symbols are created by the assembler to replace user-defined symbols whose scope is limited to a macro d. See Chapter .:uage Concepts The following instruction operand symbols are also reserved: Symbol Meaning $ A B C D E H L SP PSW M STACK MEMORY Location counter reference Accumulator register Register B or register pair Band C Register C Register D or register pair D and E Register E Register H or register pair Hand L Register L Stack pointer register Program status word (Contents of A and status flags) Memory reference code using address in Hand L Special relocatability feature Special relocatability feature NOTE The STACK and MEMORY symbols are fully discussed in Chapter 4. an error results since you have given ml i1tiple definitions to the same name. are global. each use of the macro (except the first) would cause multiple defililtlons for those symbolic names. Assume.Chapter 2. that you assifn the symbolic name RTN to a routine. these symbols are 'local' to the macro. Assembly Lan. These symbols are defined when they appear in the label field of an instruction or In the name field of EQU. Macros require local symbols because the same macro may be used many times in the program. You may then code a iump or a calJ to RTN from any POlllt in your program. Global and Um/'ed Symbols Most symbol. This means that they have meaning throughout your program.

shift operations. and M are absolute since they refer to hardware locations. L1ST+l the second. Assembly Language Concepts Permanent and Redefinable Symbols Most symbols are permanent since their value cannot change during the assembly operation. absolute expressions are described first. PSW. users of relocation should read all the following. and operators. Absolute and relocatable symbols may both appear in a relocatable module. and so on. Hand L. Such symbols must appear in an EXTRN statement. but defined In another module. PUBLIC symbols are defined in the current program module. like symbols. Only symbols defined with the SET and MACRO assembler directives are redefinable. Assume. It is important to keep in mind that these are all assembly-time operations. compare operations. These programs are later relocated to some other set of memory locations. Symbols with addresses that change dUring relocation are relocatable symbols. These symbols are required to establish program linkage when several relocatable program modules are bound together to form a single application program. Once the assembler has evaluated an expression. Each element of an expression is a term. Symbols with addl-esses that do not change during relocation are absolute symbols. it becomes a permanent part of your program. But these references are valid in any module. and byte Isolation operations. External and public symbols are special types of relocatable symbols. Expressions. or the assembler will flag them as undefined. symbols. The addresses for these symbols are resolved when the modules are bound together. External symbols are those used in the current program module. for example. References to any of the assemblerdefined registers A through E. SP. This distinction becomes important when the symbols are used within expressions. the following instruction loads the address of the seventh item in the list Into the Hand L registers: LXI H. 2-11 . may be absolute or relocatable.Chapter 2. Relocatable programs are assembled relative to memory location zero. that your program defines a list of ten constants starting at the label LIST. logical operations. Absolute and Relocatable Symbols An important attribute of symbols with this assembler is that of relocatability. but may be accessed by other modules. For the sake of readers who do not require the relocation feature. Conversely. as will be explained later.L1ST+6 Notice that LIST addresses the first item. Operators The assembler Includes five groups of operators which permit the following assembly-time operations: arithmetic operations. ASSEMBLY-TIME EXPRESSION EVALUATION An expression IS a combination of numbers. However.

Any remainder is discarded (7/2=3). NUMBR has the value 25. the previous expression evaluates to the value Shift Operators The shift ope'atars are as !"ollows: Operator y SHR x y SHL x Meol7lf7g Shift operand 'y' to the nght 'x' bit posItions. Assembly Lan ~uage Concepts Arithmetic Open tors The anthmeti. operators are as follows: Operator + Meaf7/1lg Unary or binary addition Unary or blllary subtraction Multiplication Division. The effects of the shift operators is as follows: NUMBR NUMBR SHR SHL 0001 0101 1010 1010 2-12 . The shift operators do not wraparound any bits shihed out of the byte. Example: Assume that NUMBR has the value 0101 0101.Chapter 2. Bit positions vacated by the shift operation are zero·filled. Result is the remainder caused by a division operation. * MOD Modulo. Division by zero causes an error. Notice that the shift operatar must be separated from ItS operands by spaces. 5+30*2 (25/5)+30*2 5+( -30*·2) Notice that tLe MOD operdtor must be separdted from ItS operands by spaces: NUMBR MOD 8 Assuming tha. (7 MOD 3=1) Examples: The follOWing expressions generate the bit pattern for the ASCII character A. Shift operand 'y' to the le!"t 'x' bit positions.

These directives are fully explained in Chapter 4. Assembly Language Concepts Notice that a shift one bit position to the left has the effect of multiplying a value by two. these operators are commonly used In conditional IF directives. This means that all three fields must have a one bit in the least significant bit position. a shift one bit position to the right has the effect of dividing a value by two. Also.Chapter 2. The assembly language code that follows the IF is assembled only if the condition IS TRUE. Logical Operators The logical operators are as follows. Operator NOT AND OR XOR Meaning Logical one's complement Logical AND (=1 if both ANDed bits are 1) Logical OR (=1 if either ORed bit is 1) Logical EXCLUSIVE OR (=1 if bits are different) The logical operators act only upon the least significant bit of values involved in the operation. IF FLDI AND FLD2 AND FLD3 Compare Operators The compare operators are as follows: Operator EQ NE LT LE GT GE NUL Meaning Equal Not equal Less than Less than or equal Greater than Greater than or equal Special operator used to test for null (missing) macro parameters 2-13 . Example: The following IF directive tests the least significant bit of three Items.

the value of the result is all zeros. Using PAGE ensures that this flag is 0_ 2-14 . Otherwise. Relational operations are based strictly on magnitude comparisons of bit values. Carries are not propagated from the low-order byte when the assembler object code is relocated and the carry flag will be lost. Thus.treats expressions as 16-blt addresses. Thus. The compare operators are commonly used in conditional IF directives. the aSiembly language coding following the IF directive IS assembled. This IS the function of the HIGH and LOW operators. In certain cases. The assemble. NOTE Any program segment containing a symbol used as the argument of a HIGH operator should be located only on a page boundary.e compare operator must be separated from its operands by spaces. the code is skipped over. This is done using the PAGE option with the CSEG or DSEG directives described in Chapter 4. the assembler assumes the LOW operator and Issues an error message. If false. or Y<lU need to generate an 8-bit value. a two's complement negative number (which always has a one in its high order bit) is g'eater than a two's complement positive number (which always has a zero in its high order bit). If the result of the comparison is TRUE. Example: The following IF directive tests the values of FLDl and FLD2 for equality. you need to deal only with a part of an address. When one of these symbol.uage Concepts The compare )perators Yield a yes-no result.Chapter 2. if the evaluation of the relation is TRUE. NUL is described in Chapter 5. Assembly Lan . Notice that tl. It must be preceded by either the HIGH or LON operator to specify which byte of the address IS to be used In the evaluation of the expression. When neithel operator is present. the value of the result is all ores. IF FLDl EQ FLD2 Byte Isolation Ooerators The byte isolltion operators are as follows: Operator Meaning HIGH LOW Isolate hlgh·order 8 bits of 16-bit value Isolate low-order 8 bits of 16-blt value. appears in the operand expression of an Immediate instruction. The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. These directives are fully explained in Chapter 4. Since the NU'_ operator applies only to the macro feature.

Expressions containing register-type operands are flagged as errors. Thus. Registers can be assigned alternate names only by EQU or SET. NOTE Only instructions that allow registers as operands may have register-type operands. The assembler performs no overflow detection for two-byte values. 15/3 + 18/9 15/(3 + 18/9) =5+2=7 = 15/(3 + 2) = 15/5 = 3 2-15 .Chapter 2. Operators with higher precedence are evaluated before other operators that immediately precede or follow them. The part of an expression enclosed In parentheses is evaluated first. Precedence of Operators Expressions are evaluated left to right. The only assembler directives that may contain register-type operands are EQU. The assembler generates an error message if an expression for one of these instructions yields an out-of-range value. Parentheses can be used to override normal rules of precedence. the left-most is evaluated first. thus indicating that the address is still less than 256: IF HIGH ADRS EQ 0 Permissible Range of Values Internally. Expressions for these instructions must yield values in the range -256 through +255. the assembler treats each term of an expression as a two-byte. All arithmetic operations are performed using unsigned two's complement arithmetic. 16-bit value. The following IF directive determines whether the high-order byte of ADRS is zero. If parentheses are nested. When two operators have equal precedence. SET. the Innermost are evaluated first. and actual parameters in macro calls. Certain Instructions require that their operands be an eight-bit value. Assembly Language Concepts Examples: Assume that ADRS is an address manipulated at assembly-time for building tables or lists of items that must all be below address 255 in memory. so these values are evaluated modulo 64K. the maximum range of values is OH through OFFFFH.

MOD. Relocatable Express ions Determining t le relocatability of an expression requires that you understand the relocatability of each term used in the express on. Assembly Lan :uage Concepts The following list describes the classes of operators in order of precedence: • • • • • • • • Parenthesized expressions NUL HIGH. logical. NE Logical NOT Logical AND Logical OR. SHR Addition{Subtraction: +. Assume that ABS IS an ab~olute symbol and RELOC IS a relocatable symbol: ABS + RELOC RELOC + ABS RELOC . . E.ternal symbols are considered relocatable. The expressions shown in the following list are the only expressions that yield a relocatable result. Tile special assembler symbols STACK and MEMORY are relocatable.(unary and binary) Relational Operators: EQ. LT. A reference to the location counter (specified by the $ character) IS relocatable when the CSEG or o .Chapter 2.EG directive is in effect. SHL. GT. XOR The relational. A symbol defined as equivalent to a relocatable expression using the SET or EQU directive is reocatable. LOW Multiplication/Division: *.ABS fHIGH'( RELOC+ABS \ LOW ) [ HIGH ~ RELOC _ ABS ~LOW ) HIGH} RELOC + ~ LOW ABS RELOC 2-16 r \ f HIGH '1 LOW } ABS . and HIGH{LOW operators must be separated from their operands by at least one blank. This is easier than it sounds since the number of allowable operators is substantially reduced. Absolute symJols can be defined two ways: • • A symbol that appears in a label field when the ASEG directive is in effect IS an absolute symbol. /. GE. Relocatable s"mbols can be defined a number of ways: • • • • • A symbol that appears in a label field when the DSEG or CSEG directive IS in effect is a relocatable symbol. LE. But first it is lecessary to know what determines whether a symbol is absolute or relocatable. A symbol defined as equivalent to an absolute expression using the SET or EQU directive is an absolute symbol.

An A in the table indicates that the resulting address is absolute: an R indicates a relocatable address. Thus the expression RELOC .RELOC2 EQ LT RELOCl LE GT GE NE RELOC2 Relocatable symbols may not appear In expressions with any other operators. both are relative to the DSEG location counter.Chapter 2.100 is legal. they may appear In certain expressions that yield an absolute result. Assemblv Language Concepts Remember that numbers are absolute terms. When two relocatable symbols have both been defined with the same type of relocatability. Notice that only one term may appear with the last five operators in the list. an I Indicates an illegal combination. The following expressions are val id and produce absolute results: RELOCl . both are relative to MEMORY. Symbols have the same type of relocatability when both are relative to the CSEG location counter. but 100 . Operator X absolute Y absolute Y Y y A A A A X absolute Y relocatable R I I I I I I I I I I I I I I I - X relocatable Y absolute R R I I I I I I I I I I I I I I I R R R I X relocatable Y reloca table I A I I I I I A A A A A A I I I X + X X X X X X X X X X X X X X X * / MOD SHL SHR EQ LT LE GT GE NE AND OR XOR NOT HIGH LOW unary+ unary- y y Y Y Y Y Y Y Y Y y y Y X X X X X A A A A A A A A A A A A A A A A A - 2-17 . or both are relative to STACK. The following list shows all possible combinations of operators with absolute and relocatable terms.RELOC is not.

x y is legal. 2-18 . Assemblv Larguage Concepts Chaining of Symbol Definitions The ISIS-II 81180/808S Macro Assembler is essentially a 2-pass assembler. Therefore. All symbol table entries must be resolvable in . wo passes. but iii the series EQU EQU y 1 x y Z EQU EQU EQU y Z 1 the first line s illegal as X cannot be resolved in two passes and remains undefined.Chapter 2.

When you know the length of a state In your system. This reference format necessarily requires repetitive information. In applications with critical timing requirements. the processor must wait for the memory to deliver the desired instruction or data. 3·1 . Refer to the appropriate manufacturer's literature for memory timing data. This basic timing factor can be affected by the operating speed of the memory in your system. Each description is complete so that you are seldom required to look elsewhere for additional information. depending on the clock frequency. INSTRUCTION SET HOW TO USE THIS CHAPTER This chapter is a dictionary of 8080 and 8085 Instructions. read the description of the processor and instruction set in Chapter 1 and the programming examples in Chapter 6. i. In this case. With a fast clock cycle and a slow memory. Notice that two sets of cycle/state specifications are given for 8085 conditional call and jump instructions. you can determine an instruction's basic execution time by multiplying that figure by the number of states required for the instruction. the processor can outrun the memory. When you begin to have questions about particular instructions. A state may range from 480 nanoseconds (Cl20 nanoseconds on the 8085) to 2 microseconds. The 'state' IS the basic unit of time measurement for the processor. This is because the 8085 fetches the third instruction byte only if it is actually needed.e. look them up in this chapter. This is because the basic operating speed of your processor depends on the clock frequency used in your system. Instead. do not try to read this chapter from ACI (add immediate with Carry) to XTHL (exchange top of stack with Hand L registers).. this wait can be significant. the specified condition is satisfied. If you are reading this manual to learn about the 8080 or the 8085. The instruction descriptions are listed alphabetically for quick reference.3. TIMING INFORMATION The instruction descriptions in this manual do not explicitly state execution timings.

The instruction ACI 66 has the follol' ing effect: Accumulator Immediate data = 14H = 42H Carry 00010100 01000010 1 01010111 57H ADC ADD WITH CARRY The ADC inst ruction adds one byte of data plus the setting of the carry flag to the contents of the accumulator. an ASCII constant. It must be preceded by either the HIGH or LO\A operator to specify which byte of the address is to be used in the evaluation of the expression. The data may not exceed one byte.AC Assume that the accumulator contains the value 14H and that the carry bit is set to one. Data may be in the form of a number. When one of these symbols appears in the operand expression of an immediate instruction. or an expression. The ADC innuction's use of the carry bit enables the program to add multi-byte numeric strings. of course. for the carry bit. Instruction Se· ACI ADD IMMEDIATE WITH CARRY ACI adds the :ontents of the second instruction byte and the carry bit to the contents of the accumulator and stores the result in the accumulator. o 0 data o Cycles: States: AddreSSing: Flags: Example: 2 7 Immediate Z.CY.Chapter 3. When neither )perator is present. 3-2 .S. the label of a previously defined value. Opcode ACI Operand data The operand SJecifies the actual data to be added to the accumulator except. the assembler assumes the LOW operator and issues an error message. The assemblers relocation feature treats all external and relocatable symbols as 16-bit addresses.P. The result istored in the accumulator ADC then updates the setting of the carry flag to indicate the outcome of the operaton.

P. Carry 0 0 0 0 0 3-3 .-1_ _ 0_0 _ _ 0_ _1 S S S I CYcles: States: Addressings: Flags: 1 4 register Z. H or L. This instruction adds the contents of the specified register and the carry bit to the accumulator and stores the result in the accumulator.CY. CYcles: States: AddreSSing: Flags: Example: 2 7 register indirect Z.AC Add Memory to Accumulator with Carry Opcode ADC Operand M This instruction adds the contents of the memory location addressed by the Hand L registers and the carry bit to the accumulator and stores the result in the accumulator.AC Assume that register C contains 3DH. Instruction Set Add RegIster to Accumulator with Carry Opccde ADC Operand reg The operand must specify one of the registers A through E. '. the accumulator contains 42H. The instruction ADC C performs the addition as follows: 3DH 42H CARRY 00111101 01000010 o 01111111 = 7 FH The condition flags are set as follows: Carry Sign Zero ParitY Aux.S.s. and the carry bit is set to zero. M is a symbolic reference to the Hand L registers.P.CY.Chapter 3.

H or L.AC Cycles: States: Addressing: Flags: Add From Memory Opcode ADD Operand M This InstruCilon adds the contents of the memory location addressed by the Hand L registers to the contents of the accumulltor and stores the result in the accumulator.Chapter 3. Instruction Set If the carry !>it IS set to one. 11 0 0 0 0 2 7 register Indirect Z.CY.AC Cycles: States: Addressing: Flags: 34 . Carry o 1 o o 1 ADD ADD The ADD In. the instruction has the following results: 3DH 42H CARRY 00111101 01000010 1 10000000 SOH Carry Sign Zero ParitY Aux.P. M is a symbolic reference to the Hand L registers.CY. 11 0 0 0 0 Iss sl 1 4 register Z.P.truction adds one byte of data to the contents of the accumulatoL The result is stored in the accumulator Notice that the ADD instruction excludes the carry flag from the addition but sets the flag to indicate the Jutcome of the operation. The instruction adds the contents of the specified reg ster to the contents of the accumulator and stores the result in the accumulator.S. Add Regtstet to Register Opcode ADD Operand reg The operand must specify one of the registers A through E.S.

Instruction Set Examples: Assume that the accumulator contains 6CH and register D contains 2EH. an ASCII constant. or an expression. When neither operator is present. The Instruction ADD D performs the addition as follows: 2EH 6CH 9AH 0010111 0 011011 00 10011010 The accumulator contains the value 9AH following execution of the ADD D instruction.S. Opcode Operand ADI data The operand specifies the actual data to be added to the accumulator This data may be In the form of a number. ' l Cycles: States: 000 data 2 7 immediate Z. Carry 0 1 0 1 1 The following instruction doubles the contents of the accumulator: ADD A ADI ADD IMMEDIATE ADI adds the contents of the second instruction byte of the contents of the accumulator and stores the result in the accumulator. the label of a previously defined value. The condition flags are set as follows: Carry Sign Zero Parity Aux.Chapter 3. The data may not exceed one byte. The contents of the D register remain unchanged.CY.AC Addressing: Flags: 3-5 . When one of these symbols appears in the operand expression of an immediate instruction. it must be preceded by either the HIGH or LOW operator to specify which byte of the address is to be used In the evaluation of the expression. The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses.P. the assembler assumes the LOW operator and Issues an error message.

The result IS placed in tlie accumulator.-~_O Cycles: States: Addressing: Flags: O_O_I S S S I 1 4 register Z.P.AC 3-6 . OR produces a one bit In the result when the corresponding bits in either the test data or the mask data are ones. The Instruction ADI 66 has the following effect: Accumulator Immediate data 14H 42H 00010100 01000010 01010110 = 56H Notice that ti. AND OR EXCLUSIVE OR 1010 1010 0000 1111 0000 1010 AND Registe. ANA LOGICAL AND WITH ACCUMULATOR ANA perforrrs a logical AND operation using the contents of the specified byte and the accumulator. a one bit in either the test data or the mask data . The carry flag is reset to zero.CY.Chapter 3. with Accumulator Opcode ANA 1010 1010 0000 1111 1010 1111 1010 0000 1010 1010 1111 0101 Operand reg The operand must specify one of the registers A through E. I. ThiS instruction ANDs the contents of the specified regi iter with the accumulator and stores the result in the accumulator. Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are different.e.S. H or L.produces a one bit In the result. Instruction Se Example: Assume that he accumulator contains the value 14H. SummGlY of ~oglcal Operations AN D product s a one bit In the result only when the corresponding bits In the test data and the mask data are ones. I.but not both .e assembler converts the decimal value 66 into the hexadecimal value 42.

Chapter 3. Instruction Set

AND Memory with Accumulator

Opcode

Operand

ANA

M

This Instruction ANDs the contents of the specified memory location with the accumulator and stores the result in the accumulator. The carry flag is reset to zero.

o
Cycles: States: Addressing: Flags: Example:

o 0
2
7

register Indirect Z,S,P,CY.AC

Since any bit ANDed with a zero produces a zero and any bit ANDed with a one remains unchanged, AND is frequently used to zero particular groups of bits. The following example ensures that the high-order four bits of the accumulator are zero, and the low·order four bits are unchanged. Assume that the C register contains OFH: Accumulator C Register 1 1 1 1

o

0

000 000 0

o

1 1

o 0

OFCH OFH OCH

ANI

AND IMMEDIATE WITH ACCUMULATOR
ANI performs a logical AND operation using the contents of the second byte of the Instruction and the accumulator. The result is placed In the accumulator. AN I also resets the carry flag to zero.
Opcode Operand

ANI

data

The operand must specify the data to be used In the AND operation. This data may be in the form of a number, an ASCII constant, the label of some previously defined value, or an expression. The data may not exceed one byte. The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. When one of these symbols appears in the operand expression of an immediate instruction, it must be preceded by either the HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression. When neither operator is present, the assembler assumes the LOW operator and issues an error message.

3-7

Chapter 3. Instruction Se:

' l
Cycles: States: Addressing: Flags:
Summary of
~oglcal

o

0

data
2 7 immediate Z.S.P.CY,AC

Operations

AND prodUCt s a one bit in the result only when the corresponding bits In the test data and the mask data are ones. OR produces a one bit in the result when the corresponding bits In either the test data or the mask data are ones. Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are different; i.e. a one bit in either the test data or the mask data - but not both - produces a one bit in the result. AND
1010 1010 0000 1111 00001010

OR
1010 1010 0000 1111 1010 1111

EXCLUSIVE OR
1010 1010 0000 1111 1010 0101

Example: The followin;. instruction IS used to reset OFF bit SIX of the byte In the accumulator: ANI
1011111IB

Since any bit ANDed with a one remains unchanged and a bit ANDed with a zero is rest to zero, the ANI instruction srown above sets bit six OFF and leaves the others unchanged. This technique IS useful when a program uses individual bits as status flags.

CALL

CALL
The CALL Irstructlon combines functions of the PUSH and I MP Instructions. CALL pushes the contents of the program coullter (the address of the next sequential instruction) onto the stack and then iumps to the address specified in t le CALL instruction. Each CALL Instruction or one of ItS variants implies the use of a subsequent RET (return) Instruction. When a call has no cllrresponding return. excess addresses are built up in the stack.

3-8

Chapter 3. Instruction Set

Opcode
CALL

Operand
address

The address may be specified as a number, a label, or an expression. (The label is most common.) The assembler inverts the high and low address bytes when it assembles the instruction.

1

1

0

0

1

1

0

1

low addr high addr Cycles: States: Addressing: Flags: Example: When a given coding sequence is required several times in a program, you can usually conserve memory by coding the sequence as a subroutine invoked by the CALL instruction or one of its variants. For example, assume that an application drives a six-digit LED display; the display is updated as a result of an operator input or because of two different calculations that occur in the program. The coding required to drive the display can be included in-line at each of the three points where it is needed, or it can be coded as a subroutine. If the label DISPL Y is assigned to the first instruction of the display driver, the following CALL instruction is used to invoke the display subroutine: CALL DISPLY

5
17 (18 on 8085) immediate/register indirect none

This CALL instruction pushes the address of the next program instruction onto the stack and then transfers control to the DISPLY subroutine. The DISPLY subroutine must execute a return instruction or one of its variants to resume normal program flow. The following is a graphic illustration of the effect of CALL and return instructions: CALL

CALL

~

--------- --DISPL Y DISPL Y - - - - -

_

~

DISPLY

- -RET

CALL

Consideration for Using Subroutines
The larger the code segment to be repeated and the greater the number of repetitions, the greater the potential memory savings of using a subroutine. Thus, if the display driver in the previous example requires one hundred

3-9

Chapter 3. Instruction Se:

bytes, coding it In-line would require three hundred bytes. Coded as a subroutine, it requires one hundred bytes plus nine bytls for the three CALL instructions. Notice that slJbroutines require the use of the stack. This requires the application to include random access memory for 1 he stack. When an application has no other need for random access memory, the system designer might elect to) avoid the use of subroutines.

CC

CALL IF CARRY
The CC instnlction combines functions of the JC and PUSH instructions. CC tests the setting of the carry flag. If the flag is ,et to one, CC pushes the contents of the program counter onto the stack and then jumps to the address sped"ied in bytes two and three of the CC instruction. If the flag is reset to zero, program execution continues whh the next sequential instruction.

Opcode
CC

Operand
address

Although thE use of a label is most common, the address may also be specified as a number or expression.

1

1

0

1

1

1

0

0

lowaddr high addr Cycles: States: AddreSSing: Flags: Example: For the sake of brevity, an example IS given for the CALL instruction but not for each of its closely related variants.
3 or 5 (2 or 5 on 8085) 11 or 17 (9 or 18 on 8085) immediate/register indirect none

CM

CALL IF MINUS
The CM inst-uction combines functions of the J M and PUSH instructions. CM tests the setting of the sign flag. If the flag is set to one (indicating that the contents of the accumulator are minus), CM pushes the contents of the progr,lm counter onto the stack and then jumps to the address specified by the CM instruction. If the flag is set to zero, program execution simply continues with the next sequential instruction.

Opcode
CM

Operand
address

3-10

All condition flags remain unchanged. 3 or 5 (2 or 5 on 8085) 11 or 17 (9 or 18 on 8085) immediate/register indirect none CMA COMPLEMENT ACCUMULATOR CMA complements each bit of the accumulator to produce the one's complement. an example is given for the CALL instruction but not for each of ItS closely related variants. the address may also be specified as a number or an expression. 1 1 1 1 1 1 0 0 lowaddr high addr Cycles: States: Addressing: Flags: Example: For the sake of brevity. Opcode CMA Operand Operands are not permitted with the CMA instruction. it becomes OAEH: 51H OAEH 01010001 10101110 3-11 . Example: Assume that the accumulator contains the value 51H.Chapter 3. when complemented by CMA. 10 0 Cycles: States: Flags: o 1 4 none To produce the two's complement. Instruction Set Although the use of a label is most common. add one to the contents of the accumulator after the CMA instructions has been executed.

CMC sets it to one. 10 0 Cycles: States: Flags: Example: Assume that a program uses bit 7 of a byte to control whether a subroutine is called. All other flags remain unch. rotates bit 7 into the carry flag. a carry indicaus that the accumulator IS less than the byte. which IS why the zero and carry flags indicate the result. the meaning of the carry flag is reversed when the values have different signs or one of the values is complemented. The zero flal indicates equality. However. Instruction S. No carry indicates that the accumulator is greater than the specified byte. t CMC COMPLEMENT CARRY If the carry flag equals zero. For example. The values being compared remain unchanged. Call. If the carry flag is one.ROTATE BIT 7 INTO ACCUMULATOR . the program loads ti. Because subtraction uses two's complement addition. l:efore returning to the calling program. J Z (J ump if Zero l tests for equality Functnnal Description: Comparisons are performed by subtracting the specified byte from the contents of the accumulator. CMC resets it to zero.nged. This subtraction uses the processor's internal registers so that source data is preserved.e byte into the accumulator. Opcode CMC Operand Operands are not permitted with the CMC instruction. 3-12 .SET BIT 7 OFF . the subroutine reinitializes the flag byte using the following code: CMC RAR RET . The program tests the condition flags using one of the conditional Jump. or Return instructions. To test the bit.RETURN 1 4 CYonly CMP COMPARE WITH ACCUMULATOR CMP compar. and executes a CC (Call if Carry) instruction.Chapter 3.s the specified byte with the contents of the accumulator and Indicates the result by setting the carry and zelo flags. the CMP instruction recoml'lements the carry flag generated by the sUbtraction.

Chapter 3. Instruction Set Compare Register with Accumulator Opcode CMP Operand reg The operand must name one of the registers A through E. Cycles: States: Addressing: Flags: Example 1: 2 7 register indirect Z. Example 2: Assume that the accumulator contains the value -1 BH and register E contains OSH: Accumulator +(-E Register) 11100101 11111011 111 00000 +(-carry) 3-13 .AC Compare Memory with Accumulator Opcode CMP Operand M This instruction compares the contents of the memory location addressed by the Hand L registers with the contents of the accumulator.S.P.AC Assume that the accumulator contains the value OAH and register E contains the value OSH. both the zero and carry bits are zero. thus indicating A greater than E.CY. H or L. M is a symbolic reference to the Hand L register pair.CY.S. S Cycles: States: Addressing: Flags: s sl 1 4 register Z.P. The instruction CMP E performs the following internal subtraction (remember that subtraction is actually two's complement addition): Accumulator +( -E Register) 00001010 11111011 00000101 +(-carry) After the carry is complemented to account for the subtract operation.

If the fag is off (indicating that the contents of the accumulator are other than zero). use of a label is most common. If the flag IS set to one. truction combines functions of the JNC and PUSH instructions. tructlon combines functions of the J NZ and PUSH Instructions. Opcode Operand CNZ address Although th. Opcode Operand CNC address Although th. IS 3 or 5 (2 or 5 on 8085) 11 or 17 (9 or 18 on 8085) immediate/register Indirect none given for the CALL instruction but not for each of its closely related CNZ CALL IF NOT ZERO The CNZ In. If the fag is set to zero. CNC CALL IF NO CARRY The CNC in. the address may also be specified as a number or an expression. an example vanants. program execution simply continues with the next sequential instruction. 3-14 . 1 1 0 1 0 1 0 0 low addr high addr Cycles: States: Addressing: Flags: Example: For the sake of brevity. Normally this indicate. CNZ pushes the contents of :he program counter onto the stack and then jumps to the address specified in the Instruction's second and hiI'd bytes. both the carry flag and zero flag are zero. If the flag is set to one. the address may also be specified as a number or an expression. the meaning of the carry flag IS reversed since the val Jes have different signs.Chapter 3.t After the 01P Instruction recomplements the carry flag. The user program is responsible for proper interpretation of the carry flag. CNC pushes the contents of the program counter onto the stack and theniumps to the addre.s specified by the CNC instruction. CNZ tests the setting of the zero flag. CNC tests the setting of the carry flag. that the accumulator is greater than register E. However. Instruction S . program execution simply continues with the ne> t sequential instruction.: use of a label is most common.

3 or 5 (2 or 5 on 8085) 1. CP pushes the contents of the program counter onto the stack and theniumps to the address specified by the CP Instruction. 1 1 1 1 0 1 0 0 low address high addr Cycles: States: Addressing: Flags: Example: For the sake of brevity. program execution simply continues with the next sequential instruction. If the flag is set to one. 3 or 5 (2 or 5 on 8085) 11 or 17 (9 or 18 on 8085) immediate/register indirect none 3-15 . an example is given for the CALL instruction but not for each of its closely related variants.1 or 17 (9 or 18 on 8085) immediate/register indirect none CP CALL IF POSITIVE The CP instruction combines features of the J P and PUSH instructions. CP tests the setting of the sign flag. Instruction Set 1 1 0 0 0 1 0 0 lowaddr high addr Cycles: States: Addressing: Flags: Example: For the sake of breVity.Chapter 3. Opcode CP Operand address Although the use of a label is more common. an example is given for the CALL instruction but not for each of its closely related variants. the address may also be specified as a number or an expression. If the flag is set to zero (indicating that the contents of the accumulator are positive).

No carry indicates that the contents of the accumulator are greater than the immediate da :a. The ePE instI uction combines functions of the JPE and PUSH instructions. Instruction Se.Chapter 3. If the flog is set to one. CPE pushes the contents of the program counter onto the stack and then jumps to the addres' specified by the CPE instruction. the IN instruc tion does not set any of the condition flags. CPE CALL IF PARITY EVEN Parity is even if the byte in the accumulator has an even number of one bits. a carry Indicates that the accumulator is less than the immediate data. 1 1 1 0 1 1 0 0 lowaddr high addr Cycles: States: Addressing: Flags: 3 or 5 (2 or 5 on 8085) 11 or 17 (9 or 18 on 8085) immediate/register Indirect none Example: For the sake )f brevity. The values being compared remain unchanged. program execution simply continues with the next sequential instruction. The CPE and CPO instructions are useful for testing the parity of input data. an example is given for the CALL instruction but not for each of its closely related variants. the contents of the second instruction byte with the contents of the accumulator and sets the zero and carry flap to indicate the result. The zero flag Indicates equality. CPI COMPARE IMMEDIATE CPI compare. However. CPE tes\s the setting of the parity flag. the meaning of the carry 1lag is reversed when the values have different signs or one of the values is complemented. If the flag is set to zero. Opcode CPE Operand address Although the use of a label is more common. However. Opcode CPI Operand data 3·16 . The parity flag is set to one to indicate this condition. The flags can be set without altering the data by adding OOH t" the contents of the accumulator. the address may also be specified as a number or an expression.

CPO tests the setting of the panty flag. o data Cycles: States: Addressing: Flags: Example: The instruction CPI 'C' compares the contents of the accumulator to the letter C (43H). program execution simply continues with the next sequential instruction. an ASCII constant.AC CPO CALL IF PARITY ODD Parity is odd if the byte in the accumulator has an odd number of one bits. 2 7 register Indirect Z. The panty flag is set to zero to indicate this condition. The data may not exceed one byte. the label of a previously defined value. Opcode Operand CPO address Although the use of a label is more common. The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. 1 1 1 0 0 1 0 0 lowaddr high addr Cycles: States: Addressing: Flags: 3 or 5 (2 or 5 on 8085) 11 or 17 (9 or 18 on 8085) immediate/register indirect none 3-17 . The CPO and CPE instructions are useful for testing the parity of input data. the assembler assumes the LOW operator and issues an error message. Instruction Set The operand must specify the data to be compared. When neither operator is present. or an expression. the address may also be specified as a number or an expression.S. However. When one of these symbols appears in the operand expression of an immediate instruction.CY. This data may be in the form of a number.Chapter 3. If the flag is set to zero. it must be preceded by either the HIGH or LOW operator to specify which byte of the address is to be used In the evaluation of the expression.P. The CPO instruction combines functions of the JPO and PUSH instructions. The flags can be set without altering the data by adding OOH to the contents of the accumulator. the IN instruction does not set any of the condition flags. If the flag is set to one. CPO pushes the contents of the program counter onto the stack and then jumps to the address specified by the CPO instruction.

CZ tests the setting of the zero flag. CZ CALL IF ZERO The CZ instrJCtion combines functions of the I Z and PUSH Instructions. the address may also be specified as a number or an expression. It is the only instruction whose function requires use of the auxiliary carry flag. 3-18 . If the flag IS . program execution simply continues wil h the next sequential Instruction. If the flag IS set to zero (indicating that the contents of the accumulator are other than zero). Instruction Sf t Example: For the sake of brevity.Chapter 3. DAA IS used when adding deCimal numbers. an example is given for the CALL Instruction but not for each of its closely related vanants. CZ pushes the contents of the program :ounter onto the stack and then lumps to the address specified in the CZ instruction.et to one (indicating that the contents of the accumulator are zero). Opcode Operand CZ address Although the use of a label is most common. In multi-byte arithmetiC operations. 1 I 0 0 1 1 0 0 lowaddr high addr Cycles: States: Addressing: Flags: Example: For the sake of brevity. lIl~truction DECIMAL ADJUST ACCUMULATOR adjusts the eight-bit value in the accumulator to form two four-bit binary coded deCimal Opcode Operand DAA Operands are not permitted with the DAA IIlstructlon. the DAA instruction typically is coded immediately after the arithmetic instruc tion so that the auxiliary carry flag is not altered unintentionally. 3 or 5 (2 or 5 on 8085) 11 or 17 (9 or 18 on 8085) Immediate/register Indirect none DAA The DAA digits. an example IS given for the CALL instruction but not for each of its closely related vanants.

Chapter 3. or if the carry flag IS ON.CY.AC Assume that the accumulator contains the value 9BH as a result of adding 08 to 93: CY 0 1001 0000 1001 Since OBH IS AC 0 0011 1000 1011 = 9BH greater than nine. 2. 3-19 . If the most significant four bits of the accumulator have a value greater than nine. Instruction Set DAA operates as follows: 1.S. the carry flag program. DAA adds six to the most significant four bits of the accumulator. If the least significant four bits of the accumulator have a value greater than nine. DAA adds six to the accumulator. the accumulator contains the value 01 in a BCD format. Since the actual result of this addition is 101. Notice that the carry flag setting is lost as soon as the program executes any subsequent Instruction that alters the flag. the instruction adds CY 1 1010 0110 0000 AC to them: 1 0001 0000 0001 When the DAA has finished. 10 0 Cycles: States: Addressing: Flags: Example: o 0 1 4 register Z. The program IS IS probably significant to the responsible for recovering and using this information. both the carry and auxiliary carry flags are set ON. or if the auxiliary carry flag is ON.P. the Instruction adds six to contents of the accumulator: CY AC o 1001 0000 1010 1 1011 0110 0001 = A1H SIX Now that the most significant bits have a value greater than nine.

No ice that the letter H must be used to specify that the H& L register pair is to be added to Itself. Cycles: States: Addressing: Flags: Examples: 3 10 register CY The DAD in .STORE SP IN MEMORY The instruct on DAD H doubles the number in the Hand L registers except when the operation causes a carry out of the f. D&E.GET SP INTO H&L . DCR DECREMENT DCR subtra'ts one from the contents of the specified byte.register. or the SP (Stack Pointer) register pairs to the contents of H& L. DAD sets th ~ carry flag ON if there is a carry out of the Hand L registers. LXI DAD SHLD H. H&L. DAD affects none of the condition flags other han carry.Chapter 3.e 16-bit value in the specified register pair to the contents of the Hand L register pair. Becaus( DCR preserves the carry flag.truction provides a means for saving the current contents of the stack pointer.CLEAR H&L TO ZEROS .OOH SP SAVSP . DCR affects all the condition flags except the carry flag. Decrement I ~egister Opcode DCR Operand reg 3-20 .t DAD DOUBLE REGISTER ADD DAD adds ti. it can be used within multi-byte arithmetic routines for decrementing character co Jnts and similar purposes. Opcode Operand DAD DAD may add only the contents of the B&C. The result is stored in Hand L. Instruction S .

M D D LOOP: M B LOOP .S.Chapter 3.STORE BYTE . H or L. instruction subtracts one from the contents of the specified register. 3-21 .900H A.LOAD D&E WITH DESTINATION ADDR .DECREMENT DESTINATION ADDRESS .P. Notice that the control counter is decremented to zero rather than incremented until the desired count is reached.LOAD H&L WITH SOURCE ADDR .S.P.DECREMENT SOURCE ADDRESS .260H D. 10 0 Cycles: States: Addressing: Flags: Example: o 3 10 register indirect Z.DECREMENT CONTROL COUNTER .AC Opcode Operand M DCR This instruction subtracts one from the contents of the memory location addressed by the Hand L registers. M is a symbol ic reference to the Hand L registers.SET CONTROL COUNTER . Instruction Set The operand must specify one of the registers A through E.REPEAT LOOP UNTIL COUNTER=O This example also illustrates an efficient programming technique.5H H. This technique avoids the need for a compare instruction and therefore conserves both memory and execution time. Thp.AC The DCR instruction is frequently used to control multi-byte operations such as moving a number of characters from one area of memory to another: MVI LXI LXI MOV STAX DCX DCX DCR JNZ B.LOAD BYTE TO BE MOVED . ~D Cycles: States: Addressing: Flags: Decrement Memory D D 1 5 (4 on 8085) register Z.

Cycles: States: Addressing: Flags: Example: 1 5 (6 on 8085) register none Assume that the Hand L registers contain the address 9800H when the instruction DCX H is executed. Because you cannot the end of the time-dependent code sequence. D&E.Chapter 3. Opcode DI Operand Operands an not permitted with the DI instruction. it can be used for address modification in any instruction sequence that relies on the passing of the flags. You can disable of the code sequence. DCX considers tht: contents of the two registers to be a single 16-bit value and therefore performs a borrow from the H register te produce the value 97FFH. Notice that the letter H must be u. the DI instruction is commonly interrupted. Opcode Operand DCX DCX may dlcrement only the B&C. H&L. Instruction Sct DCX DECREMENT REGISTER PAIR DCX decrerrents the contents of the specified register pair by one. In applicaticns that use interrupts. Exercise carl' when decrementing the stack pointer as this causes a loss of synchronization between the pointer and the actual contents of the stack. For example. time-dependent code sequences become the interrup system by including a DI instruction at the beginning predict the llccurrence of an interrupt.ed to specify the Hand L pair. or the SP (Stack Pointer) register pairs. Because DC: preserves all the flags. DCX affects none of the condition flags. 3-22 . DI DISABLE INTERRUPTS The interruet system is disabled when the processor recognizes an interrupt or Immediately following execution of a DI instl uction. include an EI instruction at used only when a code sequence must not be inaccurate when interrupted.

This special interrupt is intended for serious problems that must be serviced regardless of the interrupt flag such as power failure or bus error. no interrupt including TRAP can interrupt the execution of the 01 or EI instruction. This special interrupt is intended for serious problems that must be serviced regardless of the interrupt flag such as power failure or bus failure. When power is first applied. Enabling the interrupt system is delayed one instruction to allow interrupt subroutines to return to the main program before a subsequent interrupt is acknowledged. Instruction Set 1 1 0 0 11 Cycles: States: Flags: 1 4 none NOTE The 8085 TRAP interrupt cannot be disabled. In applications that use interrupts. include an EI instruction at the end of the code sequence. Opcode EI Operand Operands are not permitted With the EI instruction.Chapter 3. You can disable the interrupt system by including a 01 instruction at the beginning of the code sequence. Because you cannot predict the occurrence of an interrupt. However. EI ENABLE INTERRUPTS The EI instruction enables the interrupt system following execution of the next program instruction. Example: The EI instruction is frequently used as part of a start-up sequence. o Cycles: States: Flags: 1 4 none NOTE The 8085 TRAP interrupt cannot be disabled. no interrupt including TRAP can interrupt the execution of the 01 or EI instruction. the processor begins operating at some indeterminate address_ Application of a RESET signal forces the program counter to 3-23 . the interrupt system is usually disabled only when the processor accepts an interrupt or when a code sequence must not be interrupted. However.

except for the TR/. IN INPUT FROM PORT The IN inst uction reads eight bits of data from the specified port and loads it into the accumulator. you should Je certain that interrupts are enabled before the HLT instruction is executed. This forces the program counter to zero. See the description of the EI (EnaJle Interrupt) instruction. The proceSSJr can temporarily leave the halt state to service a direct memory access request. However. The same is true of the 8085. Opcode IN Operand exp The operand expression may be a number or any expression that yields a value in the range OOH through OFFH. These instructions enable the interrupt system (RESET als" disables the interrupt system) and halt the processor. A subsequent manual or automatic interrupt then determ Ines the effective start-up address. A basic purpose for the HLT instruction is to allow the processor to pause while waiting for an interrupt from a peripheral d~vice. the processor reent~rs the halt state once the request has been serviced.truction halts the processor. Jtherwise. If an 8080 I-lLT instruction IS executed while interrupts are disabled. The program counter contains the address of the next sequential instruction. which IS recognized even when the interrupt system is disabled. However. Input/output structures are described in the 8080 or 8085 Microcomputer Systems User's Manual. Instruction 5 et zero. o Cycles: States: Flags: 1 7 (5 on 8085) none Once in the halt state. Therefore. HLT. typically an interrupt.P Interrupt. a halt wastes processor resources and should be used only when there is no useful processing t Isk available. the only way to restart the processor is by applicatim of a RESET signal. A common instruction sequence at this point is El. the processor can be restarted only by an external event. HLT HALT The HLT in . NOTE fhis description IS restricted to the exact function of the IN instruction.Chapter 3. the flags and registers remain unchanged. 3·24 .

Instruction Set ° exp Cycles: States: Addressing: Flags: ° 3 10 direct none INR INCREMENT INR adds one to the contents of the specified byte. 1° ° Cycles: States: Addressing: Flags: ° 3 10 ° °I register indirect Z.AC 3·25 . H or L.S. INR affects all of the condition flags except the carry flag.S. Increment Register Opcode INR Operand reg The operand must specify one of the registers A through E. The Instruction adds one to the contents of the specified register. it can be used within multi-byte arithmetic routines for incrementing character counts and similar purposes. M is a symbolic reference to the Hand L registers.P. ~I D D D 1 1_ _ 0_01 Cycles: States: Addressing: Flags: 5 (4 on 8085) register Z.AC Increment Memory Opcode INR Operand M This instruction increments by one the contents of the memory location addressed by the Hand L registers.P.Chapter 3. Because INR preserves the carry flag.

If the flag is set to one. the D and E registers contalll the value 01 FFH. Opcode Operand INX INX may lIl. INX INCREMENT REGISTER PAIR INX adds olle to the contents of the specified register pair. D&E. By . program execution resumes at the address spe. Because INX preserVlS all the condition flags. --he INX instruction sets no flags to IIldicate this condition.ified in the JC instruction. The instruction INX D increments the value to 0200H.ontrast. Assume. execution continues with the next sequential instruction. (Tills condition can be detected by testing the Zero condition flag. a PUSH Instruction adds the two new bytes t) the stack.) If the stack pointer register contallls the value OFFFFH. but overlays the low-order byte of the most recent entry Cycles: States: Addresslllg: Flags: Example: 1 5 (6 on 8085) register none Assume tha. Notice that the letter H must be usd to specify the Hand L register pair. for example.rement only the B&C.Chapter 3. Exercise caro when incrementing the stack pOlllter. INX affects none of the condition flags. 3-26 . A subsequent POP instruction accesses the high-order byte of the most recent stack entry and the low-order byte of the next older entry. If the flag is reset to zero. JC JUMP IF CARRY The JC instruction tests the setting of the carry flag.t Example: If register C contains 99H. or the SP (Stack Pointer) register pairs. it can be used for address modification within multi-byte arithmetic routines. the instruction INX SP increments the contents of SP to OOOOH. H& L. Similarly. the instruction INR C increments the contents of the register to 9AH. Instruction 5 . that INX SP IS executed after a number of Items ha' e been pushed onto the stack. the INR E Instruction ignores the carry out of the low-order byte and produces a result of 0100H.

3 (2 or 3 on 8085) 10 (7 or 10 on 8085) immediate none 3-27 . or an expression. If the contents of the accumulator are negative (sign flag = 1). a label. program execution resumes at the address specified In the Jrv1 instruction. 3 (2 or 3 on 8085) 10 (7 or 10 on 8085) immediate none JM JUMP IF MINUS The JM Instruction tests the setting of the sign flag. a label. 1 1 0 1 1 0 1 0 lowaddr high addr Cycles: States: Addressing: Flags: Example: Examples of the variations of the jump instruction appear in the description of the JPO instruction.Chapter 3. execution continues with the next sequential instruction. 1 1 1 1 1 0 1 0 lowaddr high addr CYcles: States: Addressing: Flags: Example: Examples of the variations of the lump instruction appear in the description of the JPO instruction. Instruction Set Opcode Operand address JC The address may be specified as a number. or an expression. If the contents of the accumulator are positive (sign flag = 0). The assembler inverts the high and low address bytes when it assembles the instructions. Opcode Operand address JM The address may be specified as a number. The assembler inverts the high and low address bytes when it assembles the instruction.

Instruction Set JMP JUMP The IMP inst"uction alters the execution sequence by loading the address in its second and third bytes into the program courter. or an expression. Ooeode INC Operand address The address nay be specified as a number. If there is no carry (carry flag = 0).Chapter 3.ruction tests the setting of the carry flag. program execution resumes at ti.e address specified in the I NC instruction. 3 10 immediate none JNC JUMP IF NO CARRY The INC ins. or an expression. execution continues with the nex t sequential Instruction. a label. The assembler inverts the high and low address bytes when it assembles the address. a label. when it assembles the instruction. If there is a carry (carry flag = 1). Opeode IMP Operand address The address rnay be specified as a number. 1 1 0 0 0 0 1 1 lowaddr high addr Cycles: States: Addressing: Flags: Example: Examples of the variations of the Jump instruction appear in the description of the JPO instruction. 1 1 0 1 0 0 1 0 lowaddr high addr Cycles: States: Addressing: Flags: 3-28 3 (2 or 3 on 8085) 10 (7 or 10 on 8085) immediate none . The assembler inverts the high and Jow address byte.

1 1 0 0 0 0 1 0 lowaddr high addr Cycles: States: AddreSSing: Flags: Example: Examples of the variations of the lump instruction appear In the description of the J PO instruction. or an expression. If the contents of the accumulator are positive (sign flag = 0). JNZ JUMP IF NOT ZERO The J NZ Instruction tests the setting of the zero flag. The assembler inverts the high and low order address bytes when it assembles the instruction. program execution resumes at the address specified in the JP Instruction. execution continues with the next sequential instruction. If the contents of the accumulator are not zero (zero flag = 0).Chapter 3. If the contents of the accumulator are zero (zero flag = 1). Instruction Set Example: Examples of the variations of the jump instruction appear in the description of the JPO Instruction. or an expression. 3-29 . a label. 3 (2 or 3 on 8085) 10 (7 or 10 on 8085) immediate none JP JUMP IF POSITIVE The JP instruction tests the setting of the sign flag. execution continues with the next sequential instruction. If the contents of the accumulator are minus (sign flag 1). = Opcode JP Operand address The address may be specified as a number. The assembler inverts the high and low address bytes when it assembles the instruction. program execution resumes at the address specified In the JNZ instruction. a label. Opcode JNZ Operand address The address may be specified as a number.

The parity flag IS set to one to indicate this condition.he accumulator. The flags can be set by adding OOH to the contents of .truction. 3 (2 or 3 on 8085) 10 (7 or 10 on 8085) immediate none JPE JUMP IF PARITY EVEN Parity IS evell if the byte In the accumulator has an even number of one bits. Instruction 51 t 1 1 1 1 0 0 1 0 lowaddr high addr Cycles: States: Addressi ng: Flags: Example: Examples of the variations of the lump instruction appear in the description of the JPO instruction. when it assembles the instruction. If the parity flag is set to one. . The assembler inverts the high and low address byte. However. IN instruction does not set any of the condition flags. a label.Chapter 3. program execution resumes at the addre~ s specified in the J PE instruction. 1 1 1 0 1 0 1 0 lowaddr high addr Cycles: States: Addressing: Flags: Example: Examples 3-30 01 3 (2 or 3 on 8085) 10 (7 or 10 on 8085) Immediate none the variations of the lump instruction appear In the deSCrIption of the J PO instruction. The J PE anc J PO (jump if parity odd) instructions are especially useful for testing the parity of input data. or an expression. The J PE Instruction tests the setting of the parity flag. execution continues with the next sequential in . th. If the flag IS reset to zero. Opcode Operand JPE address The address may be specified as a number..

The parity flag is set to zero to indicate this condition. The flags can be set by adding OOH to the contents of the accumulator.C 80H PLUS MINUS A. If the parity flag is reset to zero.SIGN BIT RESET . a label.SIGN BIT SET 3-31 PLUS: MINUS: . 3 (2 or 3 on 8085) 10 (7 or 10 on 8085) Immediate none Label ONE: Code Operand TWO: THREE: MOV ANI JZ JNZ MOV RLC JNC JMP MOV ADI JM A. The assembler Inverts the high and low address bytes when it assembles the instruction.C PLUS MINUS A. Assume that the byte to be tested IS the C register. the IN instruction does not set any of the condition flags. Instruction Set JPO JUMP IF PARITY ODD Parity is odd if the byte in the accumulator has an odd number of one bits. or an expression.C 0 MINUS . The JPO Instruction tests the setting of the parity flag.Chapter 3. Opcode Operand JPO address The address may be specified as a number. execution continues with the next sequential instruction. 1 1 1 0 0 0 1 0 low addr high addr Cycles: States: Addressing: Flags: Example: This example shows three different but equivalent methods for lumping to one of two points in a program based upon whether or not the Sign bit of a number is set. However. If the flag is set to one. program execution resumes at the address specified in the JPO instruction. The JPO and JPE (jump if panty even) instructions are especially useful for testing the parity of Input data.

and the JNZ instruction will be executed. the Zero condition bit will be set. Otherwise.) The RLC illstruction in block TWO causes the Carry bit to be set equal to the Sign bit of the data byte.) The add irrmediate instruction In block THREE causes the condition bits to be set. program control flows automatically ino the PLUS routine. 1 1 0 0 1 0 1 0 low addr high addr Cycles: States: Addressing: Flags: Example: Examples )f the variations of the jump instruction appear In the deswptlon of the JPO instruction. 3-32 . program execution resumes at the address spe~ified in the JZ instruction.Chapter 3. the JZ instruction will merely update the progranl counter by three. Otherwise the JMP instruction is executed.ruction tests the setting of the zero flag. If the Sign bit wai reset. the J M instruction causes program control to be transferred to MINUS. If the flag is set to one. If the flag is reset to zero. or an expression. unconditiollally transferring control to MINUS. execution continues with the next sequential Instruction Opcode JZ Operand address The addresi may be specified as a number. in this instance. The assembler inverts the high and low address by! es when it assembles the instruction. and the JZ instruction will cause program coltrol to be transferred to the Instruction at PLUS. If the sign bit was set. 3 (2 or 3 on 8085) 10 (7 or lOon 8085) Immediate none LOA LOAD ACCUMULATOR DIRECT LDA load~ the accumulator with a copy of the byte at the location specified In bytes two and three of the LDA instr Jction. Instruction Set The AND iinmediate instruction in block ONE zeroes all bits of the data byte except the Sign bit. the JNC instruction causes a lump to PLUS. If the Sign bit was zero. which remains unch lnged. (Note that. causing control to be transferred to the instruct ion at MINUS. a JC instruction could be substituted for the unconditional jump with identical results. a label. JZ JUMP IF ZERO The J Z Ins". Otherwise. (The Zero bit IS unaffected by all jump instructions.

Instruction Set Opcode Operand LDA address The address may be stated as a number. This instruction may specify only the B or D register pair.Chapter 3. 10 0 0 I~ 0 0 -'--------I I II '" 2 fo '" register pair B register pair D Cycles: States: Addressing: Flags: 7 register indirect none 3-33 . The assembler inverts the high and low address bytes when it builds the instruction. or an expression. a previously defined label. 0 0 1 1 1 0 1 0 lowaddr high addr CYcles: States: Addressing: Flags: Examples: The following instructions are equivalent. Opcode Operand LDAX The operand B specifies the Band C register pair: D specifies the D and E register pair. LOAD: LDA LDA LDA 300H 3*{16*16) 200H+256 4 13 direct none LDAX LOAD ACCUMULATOR INDIRECT L DAX loads the accumulator with a copy of the byte stored at the memory location addressed by register pair B or register pair D. each replaces the accumulator contents with the byte of data stored at memory location 300H. When executed.

tlie MaY instruction moves a copy of the byte stored at address 064E into the accumulator: LHLD MaY 3000H A.SET UP ADDRESS .M 5 16 direct none . Instruction :. or an expression. a label. The user may al:o load the current top of the stack into the Hand L registers (POP instruction). Both LHLD and POP replace the contents of the Hand L registers. SHLD stores Hand L in memory. LHLD then loads the H register with a copy of the byte stored at the next higher memory location. 0 0 1 0 1 0 1 0 lowaddr high addr Cycles: States: Addressing: Flags: Example: Assume that locations 3000 and 3001 H contain the address 064EH stored in the format 4E06. You can also exchange the contents of Hand L with the D and E regist~rs (XCHG instruction) or the top of the stack (XTHL instruction) if you need to save the current Hand L registers for subsequent use. In the following sequence. Certain instl uctions use the symbolic reference M to access the memory location currently specified by the Hand L registers. The following instruction ioads the accumulator with the contents of memory location 938BH: LDAX D LHLD LOAD HAND L DIRECT LHLD loads the L register with a copy of the byte stored ilt the memory location specified in bytes two and three of the LHLD instruction.LOAD ACCUM FROM ADDRESS 3·34 . _HLD is one of the instructions provided for loading new addresses into the Hand L registers.et Example: Assume that register D contains 93H and register E contains 8BH.Chapter 3. Opcode Operand LHLD address The address may be stated as a number.

LXI is the only immediate instruction that accepts a 16-bit value. or an expression. The MOV instruction then loads the data stored at that address into the accumulator. the Hand L register pair. The data must not exceed two bytes. the LXI instruction loads the address of STRNG into the Hand L registers. LXI loads a register pair by copying its second and third bytes into the specified destination register pair. its second and third bytes contain the source data to be loaded into a register pair. Instruction Set LXI LOAD REGISTER PAIR IMMEDIATE LXI is a three-byte instruction. This has the effect of reinverting the data into the format required for an address stored in registers. Notice that the assembler inverts the two bytes of data to create the format of an address stored in memory. LXI can load the Band C register pair. the instruction LXI S.'AZ' loads A Into register Band Z into register C. The LOCATE program provides an address for the special reserved label STACK. LXI MOV H. the label of some previously defined value. This data may be coded in the form of a number. the D and E register pair. 0 o I R P I0 0 0 1 low-order data high-order data Cycles: States: Addressing: Flags: Examples: A common use for LXI is to establish a memory address for use in subsequent instructions. or the Stack Pointer. LXI loads its third byte into the first register of the pair and its second byte into the second register of the pair. All other immediate instructions require 8-bit values. an ASCII constant. LXI SP.M . The second operand specifies the two bytes of data to be loaded.SET ADDRESS .Chapter 3. In the following sequence. Thus.STACK 3-35 . Opcode Operand LXI The first operand must specify the register pair to be loaded.STRNG A.LOAD STRNG INTO ACCUMULATOR 3 10 immediate none The following LXI instruction is used to initialize the stack pointer in a relocatable module.

Vlemory Opcode 0 Is 5 51 2 7 register Indirect none Operand MOV r.M is not allowed.reg2 The instructi)n copies the contents of reg2 into regl. When the sal ne register is specified for both operands (as in MOV A. The instruction's operands specify whether the move is from register to register. MOV H. C. Since M addresses a register pair rather than a byte of data. Move Reglsur to Register Opcode Operand MOV regl. D. Instruction 5et MOV MOVE The MOV in~ tructlon moves one byte of data by copying the source field into the destination field. The second operand must address one of the registers.A). E. and therefore ha~ a slightly longer execution time than NOP.M 3-36 .--0 Cycles: States: Addressing: Flags: Move from . This form of MOV requires one more machine state than NOP. G Move to Men'lOry Opcode D D Dis 1 5 51 Cycles: States: Addressing: Flags: 5 (4 on 8085) register none Operand MOV M.Chapter 3. H. or from memory to a register.r This instruct ion copies the contents of the specified register Into the memory location addressed by the Hand L registers. B. Source data remains unchanged. the MOV functions as a NOP (no operation) since it has no other noticeable effect. or L. M s a symbolic reference to the Hand L register pair. from a register to m"mory. Each operand must specify one of the registers A. 1.

When neither operator is present. CID Cycles: States: Addressing: Flags: Examples: 0 °I 2 01 7 register indirect none Label LDACC: NULOP: Opcode MOV MOV MOV Operands A. The second operand specifies the actual data to be moved. it must be preceded by either the HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression. Move Immediate to Register Opcode MVI Operand reg. MVI moves one byte of data by copying its second byte into the destination field. The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses.COPY ACCUM INTO E REG . The instruction's operands specify whether the move is to a register or to memory. data Cycles: States: Addressing: Flags: 2 7 immediate none 3-37 . When one of these symbols appears in the operand expression of an immediate instruction.NULL OPERATION MVI MOVE IMMEDIATE MVI is a two-byte instruction. the assembler assumes the LOW operator and issues an error message. The first operand must name the destination register. The second operand must be M.M E. its second byte contains the source data to be moved. the label of some previously defined value. This data may be in the form of a number.C Comment . The data must not exceed one byte.data The first operand must name one of the registers A through E. Instruction Set This instruction copies the contents of the memory location addressed by the Hand L registers into the specified register. M is a symbolic reference to the Hand L registers.A C. or an expression. H or L as a destination for the move.Chapter 3. an ASCII constant.LOAD ACCUM FROM MEMORY .

All of M:A' M.5+30*2 NOP NO OPERATION NOP perfor TIS no operation and affects none of the condition flags. NOP IS useful as filler in a timing loop.101Q M.65 M.Chapter 3. Instruction iet Move Immediate to Memory Opcode Operand MVI M. The result is pla:ed in the accumulator. M is a symbolic eference to the Hand L register pair. 3-38 . ORA INCLUSIVE OR WITH ACCUMULATOR ORA perf01 ms an inclusive OR logical operation uSing the contents of the specified byte and the accumulator. o 0 o data o Cycles: States: AddreSSing: Flags: Examples: 3 10 Immediate/register indirect none The followilg examples show a number of methods for defining immediate data the exampk s generate the bit pattern for the ASCII character A.41H M.01000001B In the MVI instruction. MVI MVI MVI MVI MVI MVI M. Opcode Operand NOP Operands al e not permitted with the NOP instruction.data This instruc:ion copies the data stored in its second byte into the memory location addressed by Hand L.

Instruction Set Summary of Logical Operations AND produces a one bit in the result only when the corresponding bits in the test data and the mask data are one.S.S.produces a one bit in the result.AC OR Memory with Accumulator Opcode ORA Operand M The contents of the memory location specified by the Hand L registers are inciusive-oRed with the contents of the accumulator. H or L.AC 3-39 . o Cycles: States: Addressing: Flags: o 2 7 register indirect Z. This instruction ORs the contents of the specified register and the accumulator and stores the result in the accumulator. i.Chapter 3. a one bit in either the test data or the mask data . The carry and auxiliary carry flags are reset to zero.P.CY. AND OR EXCLUSIVE OR 1010 1010 0000 1111 00001010 OR Register with Accumulator Opcode ORA 1010 1010 0000 1111 1010 1111 1010 1010 0000 1111 1010 0101 Operand reg The operand must specify one of the registers A through E. OR produces a one bit in the result when the corresponding bits in either the test data or the mask data are ones..P. The carry and auxiliary carry flags are reset to zero. Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are different. The result is stored in the accumulator.CY.e. o Cycles: States: Addressing: Flags: oIss 1 S I 4 register Z.but not both .

it must be preceded by either the HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression. This data may be in the form of a number. Assume that register D contains the value OSH: Accumulator Register D 01000011 o 0 0 0 1 000 01001011 ORI INCLUSIVE OR IMMEDIATE ORI performs an inclusive OR logical operation using the contents of the second byte of the instruction and the contents 01 the accumulator. Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are different. The result is placed in the accumulator. ar ASCII constant. the assembler assume the LOW operator and issues an error message.S. but the remaining bits are not disturbed. a one bit in either the test data or the mask data . The following example ensures that bit 3 of the accumulator is set ON. When neitrer operator is present.SY. The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. or an expression. I. OR prodU< es a one bit in the result when the corresponding bits in either the test data or the mask data are ones. Opcode ORI Operand data The operar d must specify the data to be used In the inclusive OR operation. Instruction Set Example: Since any tit inciusive-ORed with a one produces a one and any bit ORed with a zero remains unchanged. 3-40 . When one of these symbols appears in the operand expression of an immediate instruction. This is frequently done when individual bits are used as status flags in a program. ORI also resets the carry and auxiliary carry flags to zero.Chapter 3.. the label of some previously defined value. The data may not exceed one byte.P. If Logical Operations AND prod Jces a one bit in the result only when the corresponding bits in both the test data and the mask data are ones.but not both produces a one bit in the result. o data Cycles: States: Addressing: Flags: o 2 7 immediate Z.e. ORA is frequentl y used to set ON particular bits or groups of bits.AC Summary.

It is the responsibility of external logic to decode the port number and to accept the output data. this description is restricted to the exact function of the OUT instruction.Chapter 3. The following examples show a number of methods for defining immediate data in the ORI instruction. Since the number of ports ranges from 0 through 255. Instruction Set AND 1010 1010 00001111 00001010 Example: OR 1010 1010 00001111 1010 1111 EXCLUSIVE OR 1010 1010 0000 1111 10100101 See the description of the ORA instruction for an example of the use of the inclusive OR. Opcode OUT Operand exp The operand must specify the number of the desired output port. NOTE Because a discussion of input/output structures is beyond the scope of this manual. Input/output structures are described in the 8080 or 8085 Microcomputer Systems User's Manual. ORI ORI ORI ORI ORI ORI 01000001B 'A' 41H 101Q 65 5+30*2 OUT OUTPUT TO PORT The OUT instruction places the contents of the accumulator on the eight-bit data bus and the number of the selected port on the sixteen-bit address bus. All of the examples generate the bit pattern for the ASCII character A. 1 0 0 exp 0 I Cycles: States: Addressing: Flags: 1 I 3·41 3 10 direct none . This may be in the form of a number or an expression in the range OOH through OFFH. the port number is duplicated on the address bus.

Because the processor fetches the next instruction from the updated program counter address. assume that two bytes of data follow the subroutine call.ADD 2 TO FORM . o Cycles: States: AddreSSing: Flags: Example: o 1 0 1 I 5 (6 on 8085) register none One techniqlle for passing data to a subroutine IS to place the data Immediately after the subroutine call. PCHL has the effect of a iump instruction. The user pro'~ram must ensure that the Hand L registers contain the address of an executable instruction when the PCHL In: truction is executed. The following coding sequence performs a return to the next Instruction after the call: GO BACK: POP INR INR PCHL H L L . PCHL moves the contents of the H register to the high-order eight bits of the program counter and the contents of the L regHer to the low-order eight bits of the program counter.RETURN ADDRESS . Instruction Se: PCHL MOVE H&L TO PROGRAM COUNTER PCHL loads tle contents of the Hand L registers Into the program counter register. Pair POP copies: he contents of the memory location addressed by the stack pointer Into the low-order register of the register pair POP then increments the stack pointer by one and copies the contents of the resulting address into 3-42 . Opcode PCHL Operand Operands are not permitted with the PCHL instruction.RETURN POP POP The POP ins:ruction removes two bytes of data from the stack and copies them to a register pair or copies the Program Stttus Word into the accumulator and the condition flags.Chapter 3. The return addre. For tillS example. s pushed onto the stack by the CALL Instruction actually addresses the data rather than the next instruction ater the CALL.GET DATA ADDRESS . POP Registe.

POP then increments the stack pointer again so that it addresses the next older Item on the stack. D&E. such subroutines should save and restore any registers it uses so that main program can continue normally when it regains control.P.S. Cycles: States: Addressing: Flags: Example: 3 10 register Indirect Z. In general. Instruction Set the high-order register of the pair.Chapter 3. POP PSW increments the stack pointer by one and restores the contents of that address to the accumulator. POP then increments the stack pointer again so that it addresses the next older item on the stack. POP PSW is explained separately. ~ R pi 0 0 0 11 Cycles: States: Addressing: Flags: 3 10 register indirect none POP PSW POP PSW uses the contents of the memory location specified by the stack pointer to restore the condition flags.CY. or the H&L register pairs. The following sequence of PUSH and POP instructions save and restore the Program Status Word and all the registers: 343 .AC Assume that a subroutine is called because of an external interrupt. Opcode Operand POP The operand may specify the B&C.

as explained below: PUSH Regis'er Pair PUSH decrements the stack pointer register by one and copies the contents of the high-order register of the register pair to the resulting address. PUSH then decrements the pointer again and copies the low-order register to the resuh ing address. The source registers remain unchanged. and the stack pOinter is set at 9AAF. Instruction :.et PUSH PUSH PUSH PUSH PSW B D H subroutine coding POP POP POP POP RET H D B PSW Notice that the sequence of the POP instructions is the opposite of the PUSH instruction sequence. PUSH PSW is explained separately. PUSH PUSH The PUSH ilstruction copies two bytes of data to the stack.Chapter 3. Opcode Operand PUSH {U Cycles: States: Addressi ng: Flags: 3 11 (13 on 8085) register indirect none The operand may specify the B&C. This data may be the contents of a register pair or the Progran Status Word. Example: Assume tha: register B contains 2AH. D&E. or H&L register pairs. The stack pointer is st:t to 9AADH: 344 . the C register contains 4CH. The instruction'USH B stores the B register at memory address 9AAEH and the C register at 9AADH.

The highorder bit of the accumulator transfers into the carry flag. Because there are only five condition flags. xx xx xx xx . PUSH PSW formats the flags Into an eight-bit byte as follows: 7 6 5 4 3 0 2 P ~AC I CY I o On the 8080. it is frequently necessary to preserve the current program status so the calling program can continue normally when it regains control. o Cycles: States: Addressing: Flags: Example: When a program calls subroutines. PUSH PSW again decrements the pointer and copies the formatted condition flag byte to the resulting address. Instruction Set Stack Before PUSH SP before Address 9AAF 9AAE 9AAD 9AAC Stack After PUSH xx 2A 4C xx .. 345 . The subroutine then restores the pre-call system status by executing a POP PSW instruction just before returning control to the calling program.. These filler bits are undefined on the 8085. Opcode RAL Operand Operands are not permitted with the RAL instruction. PUSH PSW decrements the stack pointer by one and copies the contents of the accumulator to the resulting address. SP after PUSH PSW PUSH PSW copies the Program Status Word onto the stack. 3 11 (120n8085) register indirect none RAL ROTATE LEFT THROUGH CARRY RAL rotates the contents of the accumulator and the carry flag one bit position to the left. The carry flag.Chapter 3. bits 3 and 5 are always zero. which is treated as though it were part of the accumulator. The contents of the accumulator and the condition flags remain unchanged. Typically. bit one is always set to one. the subroutine performs a PUSH PSW prior to execution of any instruction that might alter the contents of the accumulator or the condition flag settings. transfers to the low-order bit of the accumulator. The Program Status Word comprises the contents of the accumulator and the current settings of the condition flags.

The carry flag. 10 0 0 1 4 CYonly Cycles: States: Flags: 3-46 . The low-ord"r bit of the accumulator transfers into the carry flag.. which is tre2ted as though it were part of the accumulator. ct of the RAL instruction: Before Carry o }--------. The following diagrams illustrate the eff.Chapter 3.. Opcode Operand RAR Operands an' not permitted with the RAR instruction. Accumulator o After: o Carry o o DJ Accumulator 1 0 0 0 0 01 RAR ROTATE RIGHT THROUGH CARRY RAR rotate~ the contents of the accumulator and the carry flag one bit position to the right. transfers to the high-order bit of the accumulator. Instruction S"t 10 0 0 o 1 4 CYonly Cycles: States: Flags: Example: Assume that the accumulator contains the value OAAH and the carry flag is zero.

Chapter 3. o Cycles: States: Addressing: Flags: Example: o 0 0 I 1 or 3 5 or 11 (6 or 12 on 8085) register indirect none For the sake of brevity. Instruction Set Example: Assume that the accumulator contains the value OAAH and the carry flag is zero. If the flag is set to one to indicate a carry. Program execution resumes at the new address in the program counter. the instruction pops two bytes off the stack and places them in the program counter. program execution simply continues with the next sequential instruction. The following diagrams illustrate the effect of the RAR instruction: Before: Carry 0 Accumulator 0 0 0 0 After: Carry ~ Accumulator 1 0 0 0 0 1 I RETURN IF CARRY RC The RC instruction tests the carry flag. an example is given for the RET instruction but not for each of its closely related variants. Opcode RC Operand Operands are not permitted with the RC instruction. If the flag is zero. 347 .

o 0 Cycles: States: Addressing: Flags: Example: o 3 10 0 register indirect none As mentior ed previously. - T RET RIM (8085 PRO::ESSOR ONLY) READ INTERRUPT MASK The RIM ilstruction loads eight bits of data into the accumulator. (The same IS true of the variants of these instructions. Program ex. The only practical limit on the number of nested calls is the amount of memory available for stackin:.. Typically. as shown In the follOWing example. the two subroutines will call each other indefinitely. Instruction Set RET RETURN FROM SUBROUTINE The RET irstruction pops two bytes of data off the stack and places them In the program counter register. return addresses. Ctherwlse.) MAlt1 PROGRAM CI\LL SUBA 1~ T SUBA CNZ S U B ~ r--~---CALLSUBA 1 SUBB T RET . the setting of the interrupt flag. if any. the processor attempts to execute the data as though it were code..Chapter 3. a subroutine can call a subroutine that calls another sul. (Notice that the program must contain logic that eventually returns control to the main program.) In this case. A nested subroutine can even call the subroutine that called it. 348 . pending interrupts. This has the effect of returning control to the next Instruction after the CILL. I:ET instructions are used in conjunction with CALL instructions. That is. and one bit of serial input data. The user must be certain that the RET instruction finds the address of executable code on the stack. The resulting bit pattern indicates the current setting of . Opcode RET Operand Operands a'e not permitted with the RET Instruction. If th. subroutines can be nested. it IS assumed that the data the RET instruction pops off the stack is a return addr:ss placed there by a previous CALL.routine..:cution resumes at the new address In the program counter. he interrupt mask.' instruction finds the address of data.

5 I SID "--v-' 17 "---v---" V '---v----" L 0 1 0 Cycles: States: Flags: I L Interrupt Masks: 1 = masked = enabled Llnterrupt Enable Flag: 1 Pending Interrupts: = pending '----Serial Input Data Bit. the IE flag is identical in function and level to the INTE pin on the 8080. The IE flag refers to the entire interrupt system.Chapter 3. RST6. if any The mask and pending flags refer only to the RST5.5 1 6.5 hardware interrupts. A 1 bit in this flag indicates that the entire interrupt system is enabled. 0 0 1 0 0 01 4 none RLC ROTATE ACCUMULATOR LEFT RLC sets the carry flag equal to the high-order bit of the accumulator. 10 0 0 0 0 1 4 CYonly Cycles: States: Flags: 349 . Opcode RLC Operand Operands are not allowed with the RLC instruction.5.5 0 5.5. RLC then rotates the contents of the accumulator one bit position to the left with the high-order bit transferring to the low-order position of the accumulator. The RIM instruction loads the accumulator with the following information: I 7 6 5 16 4 15 3 IE 2 7. and RST7. Thus. Instruction Set Opcode RIM Operand Operands are not permitted with the RIM instruction. thus overwriting its previous setting.

3-50 . Program execution resumes at the new addr. o Cycles: States: Addressing: Flags: Example: 0 01 1 or 3 5 or 11 (6 or 12 on 8085) register indirect none For the sake of brevity. program execution simply continues with the next sequentlll instruction. the instruction pcps two bytes off the stack and places them in the program counter. Opcode Operand RM Operands are not permitted with the RM instruction.'ss In the program counter. an example is given for the RET instruction but not for each of its closely related variants. If the flag is set to zero. Before: Carry 0 Accumulator 0 0 0 0 After: Carry Q Accumulator 0 1 0 0 0 1[ RETURN IF MINUS RM The RM instr Jction tests the sign flag.t Example: Assume that tne accumulator contains the value OAAH and the carry flag is zero. Instruction S. The following diagrams illustrate the effect of the RLC instruction.Chapter 3. If the flag is set to one to indicate negative data in the accumulator.

If the flag is set to zero to indicate that the contents of the accumulator are other than zero. Program execution resumes at the new address in the program counter. If the flag is set to zero to indicate that there has been no carry. Instruction Set RNC RETURN IF NO CARRY The RNC instruction tests the carry flag. RNZ RETURN IF NOT ZERO The RNZ instruction tests the zero flag. If the flag is one. program execution simply continues with the next sequential instruction.Chapter 3. the instruction pops two bytes off the stack and places them in the program counter. a Cycles: States: Addressing: Flags: Example: a a a 01 1 or 3 5 or 11 (6 or 12 on 8085) register indirect none For the sake of breVity. 11 a a a a a 01 1 or 3 501'11 (601' 12 on 8085) Cycles: States: Addressing: Flags: Example: For the sake of brevity. Program execution resumes at the new address in the program counter. If the flag is set to one. IS register indirect none given for the RET instruction but not for each of its closely related 3-51 . an example variants. Opcode RNC Operand Operands are not permitted with the RNC instruction. Opcode RNZ Operand Operands are not permitted with the RNZ instruction. program execution simply continues with the next sequential instruction. the instruction pops two bytes off the stack and places them in the program counter. an example is given for the RET instruction but not for each of its closely related variants.

If the flag IS zero. o Cycles: States: Addressing: Flags: Example: 0 0 01 1 or 3 5 or 11 (6 or 12 on 8085) register indirect none For the sake of brevity. Instruction S"t RP RETURN IF POSITIVE The RP instnlction tests the sign flag. Program execution resumes at the new address in the program counter. RPE RETURN IF PARITY EVEN Parity is ever if the byte in the accumulator has an even number of one bits. Opcode RPE Operand Operands are not permitted with the RPE instruction.Chapter 3. Opcode RP Operand Operands are not permitted with the RP instruction. the instruction pops two bytes of' the stack and places them in the program counter. Program execution resumes at the new address in the program counter. The parity flag IS set to one to indicate this . If the flag is reset to zero to indicate positive data in the accumulator. ruction tests the parity flag. the IN instru. o Cycles: States: Addressing: Flags: o 1 or 3 0 01 5 or 11 (6 or 12 on 8085) register indirect none 3-52 . However. The flags can be set without altering the data by adding OOH to the contents of the accumulator. the instruction pops two bytes off the stack and places them in the program counter. an example is given for the RET instruction but not for each of its closely related variants. The RPE and RPO instructions are useful for testing the parity of input data. If the flag is set to one to indicate even parity.ondition. The RPE ins'. program execution simply continues with the next sequential instruction. If the flag is set to one.tion does not set any of the condition flags. program execution simply continues with the next sequential instruction.

The RPO instruction tests the parity flag. However. 3-53 . o Cycles: States: Addressing: Flags: Example: 0 0 0 01 1 or 3 5 or 11 (6 or 12 on 8085) register Indirect none For the sake of brevity. IS given for the RET instruction but not for each of its closely related RPO RETURN IF PARITY ODD Parity is odd if the byte in the accumulator has an odd number of one bits. Opcode Operand RPO Operands are not permitted with the RPO instruction. If the flag is reset to zero to indicate odd parity. The parity flag is reset to zero to indicate this condition. The flags can be set without altering the data by adding OOH to the contents of the accumulator. an example variants. program execution simply continues with the next sequential instruction. an example is given for the RET instruction but not for each of its closely related variants. The RPO and RPE instructions are useful for testing the parity of input data. thus overwriting its previous setting. Instruction Set Example: For the sake of brevity. RRC ROTATE ACCUMULATOR RIGHT RRC sets the carry flag equal to the low-order bit of the accumulator.Chapter 3. If the flag is set to one. the instruction pops two bytes off the stack and places them in the program counter. the IN instruction does not set any of the condition flags. RRC then rotates the contents of the accumulator one bit position to the right with the low-order bit transferring to the high order position of the accumulator. Program execution resumes at the new address in the program counter. Opcode Operand RRC Operands are not permitted with the RRC instruction.

4. the processor acknowlecges the request and prepares its data lines to accept anyone-byte instruction from the deVice. ane 5 of the program counter. The folloving diagrams illustrate the effect of the RRC instruction: Before: Carry G Accumulator 0 0 0 After: Carry G Accumulator 0 1 0 0 0 1\ RESTART RST RST IS a special purpose CALL instruction designed primarily for use with interrupts.Chapter 3. If eight bytes are too few. RST !. RST is generally he instruction of chOice because its special purpose CALL establishes a return to the main program. this multiplies the code by eight. The restart instruction IS unique because it seldom appears as source code 111 an applications program. When a deVice requests interrupt service and lI1terrupts are enabled. A three-bit code carried in the opcode of the RST instruction specifies the Jump . the program can either Jump to or call a subroutine.ushes the contents of the program counter onto the stack to provide a return address and then Jumps to one 0 eight predetermined addresses. More often. In effect. the peripheral devices seekll1g interrupt service pass this one-byte instruction to the processcr. 3-54 . Program execution resumes at the new address where eight bytes are available for code to service the interrupt. The processor moves the three-bit address code from the RST instruction into bits 3.Iddress. Instruction Set 10 0 0 0 Cycles: States: Flags: Example: 4 CYonly Assume that the accumulator contains the value OAAH and the carry flag is zero.

or TRAP input pin.Chapter 3. program execution simply continues with the next sequential instruction. If the flag is zero.5. The processor then generates an internal RST instruction. Rather than send a RST instruction. the interrupting device need only apply a signal to the RST5.5 24H 2CH 34H 3CH Notice that these addresses are within the same portion of memory used by the RST instruction.5 RST6. and therefore allow only four bytes . If Included in the program code. RST6. 3-55 . The execution depends on the input: INPUT NAME RESTART ADDRESS TRAP RST5.5 RSn. If the flag IS set to one to indicate that the contents of the accumulator are zero. Program execution resumes at the new address in the program counter. Instruction Set 8085 NOTE The 8085 processor Includes four hardware inputs that generate internal RST instructions. the instruction pops two bytes of data off the stack and places them in the program counter.enough for a call or jump and a return for the interrupt service routine.5.5. RST7. the RST instruction has the following format: Opcode Operand RST code The address code must be a number or expreSSion within the range 0008 through 1118. 11 Progrdm Counter After RST IC 14 0 0 C ~ '" r I1 10 0 11 --~ 15 10 13 12 0 11 9 0 8 0 7 0 6 0 5 C 4 C 3 C 2 0 0 0 01 0 Cycles: States: Addressing: Flags: 3 11 (12 on 8085) register indirect none RZ RETURN IF ZERO The RZ instruction tests the zero flag.

This instruction subtracts the contents of the specified I egister and the carry flag from the accumulator and stores the result in the accumulator. Instruction Se Gpcode RZ Operand Operands are not permitted with the RZ instruction. SBB then updates the setting of the carry flag to indicate the outcome of the operation SBB's use of he carry flag enables the program to subtract nulti-byte strings. SBB SUBTRACT WITH BORROW SBB subtracts one byte of data and the setting of the carry flag from the contents of the accumulator. o 0 Cycles: States: Addressing: Flags: Example: o 0 01 1 or 3 5 or 11 (6 or 12 on 8085) register indirect none For the sake of brevity. These preliminary operations occur in the processor's internal work registers so that the SOJrce data remains unchanged.P. It then subtracts the result from the accumulator by using two'. complement addition.CY.AC 3-56 . SBB incorporates the carry flag by adding it to tile byte to be subtracted from the accumulator. an example is given for the RET instruction but oot for each of its closely related variants. H or L. Subtract Regl.'ter from Accumulator with Borrow Opcode SBB Operand reg The operand nust specify one of the registers A through E. The result is stored in the accumulator. 11 0 0 1 4 S 5 S I Cycles: States: Addressing: Flags: register Z.Chapter 3.S.

CY.Chapter 3. the carry flag is reset OFF. 3-57 . Carry o o o o 1 SBI SUBTRACT IMMEDIATE WITH BORROW SBI subtracts the contents of the second Instruction byte and the setting of the carry flag from the contents of the accumulator. When SBB complements the carry bit generated by the addition. SBI's use of the carry flag enables the program to subtract multi-byte strings. These preliminary operations occur In the processor's internal work registers so that the immediate source data remains unchanged.AC Assume that register B contains 2. The instruction SBB B operates as follows: 2H + carry = 3H 2's complement of 3H Accumulator = 11111101 = 00000100 11111101 00000001 = 1H Notice that this two's complement addition produces a carry. Cycles: States: Addressing: Flags: Example: 2 7 register indirect Z.P. and the carry flag is set to 1. the accumulator contains 4. It then subtracts the result from the accumulator by using two's complement addition. SBI incorporates the carry flag by adding it to the byte to be subtracted from the accumulator. The result is stored in the accumulator.S. The flag settings resulting from the SBB B instruction are as follows: Carry Sign Zero Parity Aux. Instruction Set Subtract Memory from Accumulator with Borrow Opcode SBB Operand M This instruction subtracts the carry flag and the contents of the memory location addressed by the Hand L registers from the accumulator and stores the result in the accumulator.

P. the Iabel of some perviously defined value. 5BI 1 yields a minUS one. the assembler assumes the LOW operator and issues an error message. it must be preceded by either the HIGH or LOlA operator to specify which byte of the address is to be used in the evaluation of the expression. In most cases. The data may not exceed one byte.Chapter 3.CY. Nhen the flag is set ON. or an expression. When neither cJperator is present. SHLD STORE HAND L DIRECT 5HLD stores l copy of the L register in the memory location specified in bytes two and three of the SHLD Instruction. Instruction Se The assembler s relocation feature treats all external and relocatable symbols as 16-bit addresses. 3·58 . NOTE This example is included for illustrative purposes. o Cycles: States: Addressing: Flags: Example: 01 2 7 immediate Z. or an expression.) When the carry flag is OFF. When one of these symbols appears in the operand expression of an immediate instruction. Opcode 5BI Operand data The operand must specify the data to be subtracted.5. This data may be in the form of a number. (Tfe XRA instruction is explained later in this chapter. 5BI 1 yields a minus two. an ASCII constant. Opcode SHLD Operand address The address may be stated as a number. a previously defined label. 5-lLD then stores a copy of the H register in the next higher memory location.AC The following sequence of instructions enables the program to test the setting of the carry flag: XRA 5BI A 1 The exclusive OR with the accumulator clears the accumulator to zeros but does not affect the setting of the carry flag. the carry flag can be tested more efficiently by using the JNC instruction (jump if no carry).

5. and output bit 7 of the accumulator to the Serial Output Data latch.Chapter 3. you must be certain to load the desired bit configurations into the accumulator before executing the SIM instruction. the H and L data can be placed in the D and E registers (XCHG instruction) or placed on the stack (PUSH and XTHL instructions).5's edge sensitive input. Instruction Set SHLD is one of the instructions provided for saving the contents of the Hand L registers.5 hardware interrupts: reset RST7. Alternately. respectively. and RST7. Opcode SIM Operand Operands are not permitted with the SIM instruction. 0 0 1 0 0 0 1 0 lowaddr high addr Cycles: States: Addressing: Flags: Example: Assume that the Hand L registers contain OAEH and 29H. The following is an illustration of the effect of the SHLD lOAH instruction: 5 16 direct none MEMORY ADDRESS 109 00 00 lOA 00 29 lOB 00 AE 10C 00 00 Memory Before SHLD Memory After SH LD SIM (8085 PROCESSOR ONLY) SET INTERRUPT MASK SI M is a multi-purpose instruction that uses the current contents of the accumulator to perform the following functions: Set the interrupt mask for the 8085's RST5. RST6. However.5. SIM interprets the bits in the accumulator as follows: ]-59 .

If bit 3 is set OFF (reset to 0). The Reset RST7.5. The SIM instruction resets the RST7.5. any subsequent RST7. Use the RIM (Read Interrupt Mask) instruction to determine the current settings of the interrupt flag and the interrupt masks. Notice that the DI (Disable Interrupts) instruction overrides the SIM instruction. Unlike RST5. 2) recognizing the interrupt. The RST7. However. If bit 6 is set to 1. the set mask function is enabled.5 interrupt is pending when this SIM instruction is executed. 3-60 . the interrupt cannot be serviced when RST7.5 input flip flop. a 0 bit leaves the interrupt available. Also. A 1 in accumiJlator bit 4 resets OFF the RST7. If bit 3 IS set ON (set to 1). Use this option when you want to send a serial output bit without affecting the interrupt mas!. or 3) setting accLmulator bit 4 and executing a SIM instruction.5 IS sensed via a processor flip flop that is set when a peripheral device Issues a pulse with a rising edge. RST7.5. and IlST7.5 interrupt mask.:ounter for each interrupt rather than service the device directly.5 and 6.5 f ip flop remains set until reset by 1) Issuing a RESET to the 8085.its 3 and 6 function as enable switches. A 1 bit masks the interrupt mak ng It unavailable.5 feature of the SIM instruction allows the pre gram to override the interrupt. Instruction Set o = available { 1 = masked ignored If 1. For example. The processor latches accumulator bit 7 into the SOD output v'here it can be accessed by a peripheral device.5 are disabled when the DI instruction IS in effect. The RST7. bit 7 is output to Serial Output Data Latch Serial Output Data: ignored if bit 6 = 0 Accumulator :.. the serial output data function is enabled.Chapter 3.5 is also useful when a device does not requ re any explicit hardware service for each interrupt.5 Interrupt is masked and cannot be serviced urtil the interrupt mask is reset. Bits (J through 2 then mask or leave available the corresponding RST interrupt. 0 1 0 0 1 0 0 01 Cycles: States: Flags: Example 1: 4 none <\ssume that the accumulator contains the bit pattern 00011100. This edge triggered Input supports devices that cannot maintain an interrupt request until serviced.5 Illput flip flop is not affected by the setting of the interrupt mask or the DI instruction and therefore can be set at any time. RST6. it is overridden without being serviced. If bit 6 IS reset to 0. Whether masked or not.5 flip fl)p and sets the RST7. RST5. RST7. bits 0 through 2 hav~ no effect. If an RSn. bit 7 IS ignored.5 is masked or a DI instruction is in effect. the program might increment and test an event .

SPHL loads the stack pointer with the value 50FFH. The 51 M instruction masks out the R5T5. stack initialization occurs very early in the program. The assembler inverts the high and low address bytes when it builds the instruction. The hardware decrements the stack pointer as items are added to the stack and increments the pointer as items are removed.Chapter 3. and R5T7. Instruction Set Example 2: Assume that the accumulator contains the bit pattern 11001111. or an expression. the stack must be in random access memory (RAM). SPHL 5PHL loads the contents of the Hand L registers into the SP (Stack Pointer) register. Typically.5. respectively. the bit pattern 10000111 has no effect since the enable bits 3 and 6 are not set to ones. Once established. The stack pointer must be initialized before any instruction attempts to access the stack. SP is a special purpose 16·bit register used to address the stack. STA STORE ACCUMULATOR DIRECT STA stores a copy of the current accumulator contents into the memory location specified in bytes two and three of the STA instruction. the stack pointer should be altered with caution. 3-61 .5. a previously defined label. MOVE H&L TO SP Opcode SPHL Operand Operands are not permitted with the SPHL instruction. Arbitrary use of 5PHL can cause the loss of stack data. Opcode STA Operand address The address may be stated as a number. Because different applications use different memory configurations.5 level interrupts and latches a 1 bit into the SOD input. By contrast. Cycles: States: Addressing: Flags: Example: 1 5 (6 on 8085) register none Assume that the Hand L registers contain SOH and OFFH. R5T6. the user program must load the SP register with the stack's beginning address. The stack is usually assigned to the highest available location in RAM.

. D specifies the D and E register pair.-/ 0 01 IfII CYcles: States: Addressing: Flags: Example: 0 = register pair B = register pair D 2 7 register Indirect none If register B c<. 10 0 oeJo '-. 0 0 1 1 0 0 1 0 lowaddr high addr Cycles: States: Addressing: Flags: Example: The following instruction stores a copy of the contents of the accumulator at memory location SB3H: STA SB3H 4 13 direct none When assembl( d. This instruction may specify only tie B or D register pair. Notice that the assembler inverts the high and I'lw order address bytes for proper storage in memory.Chapter 3. Opcode Operand STAX The operand E specifies the Band C register pair. STAX STORE ACCUMULATOR INDIRECT The STAX ins :ruction stores a copy of the contents of the accumulator into the memory location addressed by register pai B or register pair D. the previous instruction has the hexadecimal value 32 B3 05. Instruction Se.ntains 3FH and register C contains 16H... the following instruction stores a copy of the contents of the accumuiator at memory location 3F16H: STAX 3-62 B .

oIss Cycles: States: Addressing: Flags: S I 1 4 register Z. 10 0 Cycles: States: Flags: o 1 4 CY When used in combination with the rotate accumulator through the carry flag instructions. SUB uses two's complement representation of data as explained in Chapter 2. SET CARRY Opcode STC Operand Operands are not permitted with the STC instruction. The result IS stored in the accumulator. STC allows the program to modify individual bits. Notice that the SUB Instruction excludes the carry flag (actually a 'borrow' flag for the purposes of subtraction) but sets the flag to indicate the outcome of the operation.AC Subtract Memory from Accumulator Opcode SUB Operand M 3-63 .Chapter 3. The result is stored in the accumulator. H or L.CY. The instruction subtracts the contents of the specified register from the contents of the accumulator using two's complement data representation.S.P. No other flags are affected. Subtract Register from Accumulator Opcode SUB Operand reg The operands must specify one of the registers A through E. Instruction Set STC STC sets the carry flag to one. SUB SUBTRACT The SUB instruction subtracts one byte of data from the contents of the accumulator.

The assemble "s relocation feature treats all external and relocatable symbols as 16-bit addresses. the label of some previously defined value. The auxiliary carry flag is set because the particular value used in this example causes a carry out of bit 3. or an expression. Opcode Operand SUI data The operand must specify the data to be subtracted. The data must not exceed one byte.CY.ccumulator.ets the flag to Indicate the outcome ofthe operation. it must be preceded by either the 3-64 . SUI SUBTRACT IMMEDIATE SU I subtracts the contents of the second instruction byte from the contents of the accumulator and stores the result in the •. appears in the operand expression of an immediate instruction.Chapter 3.P. Instruction Se This instruction subtracts the contents of the memory location addressed by the Hand L registers from the contents of th ~ accumulator and stores the result in the accumulator. an ASCII constant. Notice that the SUI instruction disregards the carry ('borrow') flag during the subtraction but .AC Assume that tne accumulator contains 3EH. The instruction SUB A subtracts the contents of the accumulator from the accumulator and produces a result of zero as follows: 3EH +(-3EH) carry out =1 00111110 11000001 1 00000000 one's complement add one to produce two's complement result = 0 The conditior flags are set as follows: Carry Sign Zero Parity Aux. When one of these symbol. Carry 0 0 1 1 1 Notice that the SUB instruction complements the carry generated by the two's complement addition to form a 'borrow' flag. M is a symbolic reference to the Hand L registers.S. This data may be in the form of a number. o Cycles: States: Addressing: Flags: Example: 01 2 7 register indirect Z.

The flag settings resulting from this operation are as follows: Carry Sign Zero Parity Aux. The SUI instruction complements the carry generated by the addition to form a 'borrow' flag.Chapter 3. the assembler assumes the LOW operator and issues an error message. it provides the quickest means of saving and/or altering the Hand L registers.CY. When neither operator is present. Since XCHG is a register-to-register instruction. Carry a a a a 1 XCHG EXCHANGE HAND L WITH D AND E XCHG exchanges the contents of the Hand L registers with the contents of the D and E registers. XCHG both saves the current Hand L and loads a new address into the Hand L registers. Instruction Set HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression.S.P. Opcode XCHG Operand Operands are not allowed with the XCHG instruction.AC Assume that the accumulator contains the value 9 when the instruction SUI 1 is executed: Accumulator Immediate data (2's comp) 00001001 = 9H 11111111 = -1 H 00001000 = 8H Notice that this two's complement addition results in a carry. a Cycles: States: Addressing: Flags: a 1 4 register none 3-65 . a Cycles: States: Addressing: Flags: Example: a 2 01 7 immediate Z.

.P. a Cycles: States: AddreSSing: Flags: a S S S 1 4 register Z.produces a one bit in the resul t. and D and E contain 1234H. OR produces a one bit in the result when the corresponding bits ones. XRA EXCLUSIVE OR WITH ACCUMULATOR XRA performs an exclusive OR logical operation using the contents of the specified byte and the accumulator. Following execution of tre XCHG instruction. and the D and E registers contain OABCDH. 2 one bit in either the test data or the mask data .e.Chapter 3. In either the test data or the mask data are Exclusive OR produces a one bit only when the corresponding bits in the test data and the mask data are different. Hand L contain OABCDH. i. This instruction performs an exclUSive OR using the contelts of the specified register and the accumulator and stores the result In the accumulator.AC 3-66 . H or L.S. Instruction Set Example: Assume that the Hand L registers contain 1234H. The carry and auxil ary carry flags are reset to zero.lith Accumulator Opcode XRA Operand reg The operand mJst specify one of the registers A through E. Summary of Lugical Operations AND produces a one bit in the result only when the corresponding bits in the test data and the mask data are ones. The result IS pi Iced in the accumulator. AND 1010 1010 0000 1111 0000 1010 OR 1010 1010 0000 1111 10101111 EXCLUSIVE OR 1010 1010 0000 1111 1010 0101 XRA Register .but not both .CY.

P.A Any bit exclusive-ORed with a one bit is complemented. Thus.AC Since any bit exclusive-0Red with itself produces zero. an ASCII constant.S. This data may be in the form of a number.A C. The following instructions zero the accumulator and the Band C registers. The data may not exceed one byte. the label of some previously defined value. the instruction XRA B produces the one's complement of the B register in the accumulator. When one of these symbols appears in the operand expression of an immediate instruction.Chapter 3. The result is placed in the accumulator. The carry and auxiliary carry flags are reset to zero. o Cycles: States: Addressing: Flags: Examples: o 2 7 o. XRA MOV MOV A B. Opcode XRI Operand data The operand must specify the data to be used in the OR operation. the assembler assumes the LOW operator and issues an error message. Instruction Set XRA Memory with Accumulator Opcode XRA Operand M The contents of the memory location specified by the Hand L registers is exclusive-ORed with the contents of the accumulator. register indirect Z. XRA is frequently used to zero the accumulator. When neither operator IS present. XRI EXCLUSIVE OR IMMEDIATE WITH ACCUMULATOR XRI performs an exclusive OR operation using the contents of the second instruction byte and the contents of the accumulator. The assembler's relocation feature treats all external and relocatable symbols as 16-bit addresses. 3-67 . if the accumulator contains all ones (OFFH). The result is stored in the accumulator. or an expression. it must be preceded by either the HIGH or LOW operator to specify which byte of the address is to be used in the evaluation of the expression.CY. XRI also resets the carry and auxiliary carry flags to zero.

AC AND ones.Chapter 3.e. a CC instructior (Call if Carry) tests the flag and calls the subroutine if required. Exclusive OR Jroduces a one bit only when the corresponding bits in the test data and the mask data are different. i. a one bit in either the test data or the mask data . o data Cycles: States: Addressing: Flags: Summary of LJgica/ Operations o 2 7 immediate Z.produces a one bit in the result.S.but not both . and the program must set OFF bit 6 and set bit " ON. and any bit exclusive-oRed with a zero remains unchanged. must not be altered. Since any bit ~xclusive-ORed with a one is complemented.P. AND OR EXCLUSIVE OR 1010 1010 0000 1111 00001010 Example: 1010 1010 0000 1111 1010 1111 1010 1010 0000 1111 1010 0101 Assume that a program uses bits 7 and 6 of a byte as flags that control the calling of two subroutines.. which are status flags used for other purposes. th~ following Instruction is used: XRI The Instruction has the follOWing results: Accumulator Immediate data 110000008 01001100 11000000 10001100 3-68 . one bit in the result when the corresponding bits in either the test data or the mask data are ones. Assume that tle control flag byte is positioned normally In the accumulator. The program tests the bits by rotating the contents of the accumulator until the desired bit is in the carry flag.CY. Instruction Se'. produce~ a one bit in the result only when the corresponding bits in the test data and the mask data are OR produces. The remaining bits.

Opcode XTHL Operand Operands are not allowed with the XTHL instruction. respectively. XTHL exchanges the contents of the L register with the contents of the memory location specified by the SP (Stack Pointer) register. register H contains OBH and L contains 3CH. Instruction Set XTHL EXCHANGE H&L WITH TOP OF STACK XTHL exchanges two bytes from the top of the stack with the two bytes stored in the Hand L registers. 3~9 . The following is an illustration of the effect of the XTHL instruction: MEMORY ADDRESS lOAD 10AE Fa 3C aD OB H lOAF FF FF OB aD 3C Fa L 1 I 5 18 (16 on 8085) register indirect none lOAC Before XTHL After XTHL FF FF The stack pointer register remains unchanged following execution of the XTHL instruction. and memory locations 10ADH and 10AEH contain FOH and ODH. 000 Cycles: States: Addressing: Flags: Example: • Assume that the stack pOinter register contains 10ADH.Chapter 3. XTHL both saves the current contents of the Hand L registers and loads new values into Hand L. Thus. The contents of the H register are exchanged with the contents of SP+ 1.

.

ASSEMBLER DIRECTIVES This chapter describes the assembler directives used to control the 8080/85 assembler in its generation of object code. Assembler directives discussed in this chapter are grouped as follows: GENERAL DIRECTIVES: • Symbol Definition EQU SET • Data Definition DB DW • Memory Reservation DS • Conditional Assembly IF ELSE ENDIF • Assembler Termination END LOCATION COUNTER CONTROL AND RELOCATION: • Location Counter Control ASEG DSEG CSEG ORG • Program Linkage PUBLIC EXTRN NAME STKLN 4-1 . This chapter excludes the macro directives. Generally.4. which are discussed as a separate topic in Chapter 5. directives have the same format as instructions and can be interspersed throughout your program.

Label name Opcode EQU Operand expression The required lame in the label field may not be terminated with a colon.) You may defile other symbols and assign them values by using the EQU and SET directives.Chapter 4.EQU. The MACRO. The EQU.' later in this chapter. Also. those defined by SET can be assigned new values by subsequent SET directive~.ctives Three assembl" directives . (External symbols are explained under 'Location Counter Control and Relocation. Symbols defined by EQU and SET have meaning throughout the remainder of the program. (The location counters are explained under 'Address Cont'ol and Relocation. This name cannot be redefined by a subsequent EOU or SET directive. the expression always yields 1 value in the range 0-65. and LOCAL directives are explained in Chapter 5. SET. and MACRO . The EQU expression cannot contain any external symbol. the LOCAL and ENDM directives prohibit the use of the label field. ENDM. SYMBOL DEFINITION The assembler automatically assigns values to symbols that appear as instruction labels. Assembler Oir . Use the LOCAL d rective (described in Chapter 5) to avoid this problem.' later in this chapter. Example: The following EQU directive enters the name ONES into the symbol table and assigns the binary value 11111111 to t: ONES EQU OFFH 4-2 . Symbols defined using EQU callnot be redefined during assembly. and MACRO directives require a name for the symbol or macro being defined to be present in the label field. The name req Jired in the label field of an EQU or SET directive must not be terminated with a colon.have a slightly different format from assembly language instnlctions.) Assembly-tim! evaluation of EQU expressions always generates a modulo 64K address. EQU Directive EQU assigns t le value of 'expression' to the name specified in the label field. Names differ from labels in that they must not be terminated with a colon (:) as laJels are. Thus. This value IS the current setting of the location counter when the instruction IS assembled. This may cause the symbol to have illegal multiple definitions when the EQU or SET directive appears in a macro definition.536. SET.

Therefore. the assembler substitutes its value from the symbol table. Whenever 'name' is encountered subsequently in the assembly. or as a string of text characters.Chapter 4. This value remains unchanged until altered by a subsequent SET directive. Label name Opcode Operand expression SET The assembler enters the value of 'expression' into the symbol table. you can alter the value assigned to 'name' throughout the assembly. The function of the SET directive is identical to EQU except that 'name' can appear in multiple SET directives in the same program.536. Assembly-time evaluation of SET expressions always generates a modulo 64K address. Data can be specified in the form of 8-bit or 16-bit values. Assembler Directives The value assigned by the EQU directive can be recalled in subsequent source lines by referring to its assigned name as in the following IF directive: IF TYPE EQ ONES ENDIF SET Directive SET assigns the value of 'expression' to the name specified in the label field. 4-3 . Thus. DB Directive The DB directive stores the specified data in consecutive memory locations starting with the current setting of the location counter. the expression always yields a value in the range 0-65. Examples: Label IMMED Opcode SET ADI SET ADI Operand 5 IMMED lOH-6 IMMED Assembled Code C605 IMMED C60A DATA DEFINITION The DB (define byte) and DW (define word) directives enable you to define data to be stored in your program.

the assembler may not be a Jle to handle a total of eight items when the list includes a number of complex expressions. Therefore. it must be preceded by either the HIGH or LOW operato' to specify which byte of the address is to be used in the evaluation of the expression. the label STR in the following examples refers to the letter T of the stmg TIME. it is assigned the starting value of the location counter. Label optional: Opcode DW Operands expression list The least sigr ificant eight bits of the first value in the expression list are stored at the current setting of the location cour ter: the most significant eight bits are stored at the next higher location. Expressions E valuate to 1-word (16-bit) numbers. Expressions nlust evaluate to l-byte (8-bit) numbers in the range -256 through 255. If the option. the assembler assumes the LOW operator and issues an error message. If you ever haVE this problem. When one of these symbol~ appears in an operand expression of the DB directive. ectives Label optional: Opcode DB Operands expresslon(s) or string(s) The operand 'ield of the DB directive can contain a list of expressions and/or text strings. When neither opera . 44 .or is present.. Text strings may comprise a maximum of 128 ASCII characters enclosed in quotes.5*2 Assembled Code 54494D45 A3 FDOA DW Directive The DW direl tlve stores each 16-blt value from the expression list as an address. and thus references the first byte stored by the DB directive. Assembler Oi. Examples: Label STR: HERE: WORD1: Opcode DB DB DB Operands 'TIME' OA3H -03H. typically addresses.'s relocation feature treats all external and relocatable symbols as 16-bit addresses. The values are stored starting at the curren setting of the location counter. it is easily solved: simply use two or more directives to shorten the list. This process is repeated for each item in the expression list. If an expression evaluates to a single byte.Chapter 4. it IS assumed to be the low order byte of a 16-bit word where the high order byte is all zeros.! label IS present. The list can contain up to eight tc tal items: list items must be separated by commas. The assemble. Because of limited workspace.

In theory. it is assigned the starting address of the location counter. FILL addresses memory location 3EB4H. The list can contain up to eight total items. Strings containing one or two ASCII characters enclosed in quotation marks may also appear in the expression list. Any symbol appearing in the operand expression must be defined before the assembler reaches the OS directive. Assembler Directives List items must be separated by commas. remember that the characters are stored in reversed order. If you ever have this problem. Because of limited workspace. this value may range from OOH through OFFFFH.'AB' 4H Assembled Code lC3B B43E 41004241 0400 MEMORY RESERVATION OS Directive The OS directive can be used to define a block of storage. If the optional label is present. OS assembles no data into your program. Specifying a string longer than two characters causes an error. COMP addresses memory location 3B1CH. When using such strings in your program. The contents of the reserved storage are unpredictable when program execution is initiated. in practice. The reversed order for storing the high and low order bytes is the typical format for addresses stored in memory. the OW directive is commonly used for storing address constants. Unlike the OB and OW directives. Label AOOR1: AOOR2: STRNG: FOUR: Opcode OW OW OW OW Operands COMP FILL 'A'. and thus references the first byte stored by the OW directive. you will reserve no more storage than will fit in your available memory and still leave room for the program.) Examples: Assume that COMP and FI LL are labels defined elsewhere in the program. 4-5 . (This is the low order byte of the first Item in the expression list. Thus. simply use two or more OW directives to shorten the list. Label optional: Opcode OS Operand expression The value of 'expression' specifies the number of bytes to be reserved for data storage.Chapter 4. the assembler may not be able to handle eight complex expressions.

if the optional label is present. Generally. Example: TTYBUF: DS 72 . Items that can be assigned to ROM. You can use these items In your program. however. Assembler Dir 'ctives If the optlona label is present. the DB and DW directives define constants. Also. followed by the data. it is assigned the current value of the location counter. the following . then the processor fetches the data from memory and loads it into a register.Chapter 4. Data Access Accessing dati from memory is typically a two·step process: First you tell the processor where to find the data.RESERVE 72 BYTES FOR . they have an initial value that YOL r program can modify during execution.A TERMINAL OUTPUT BUFFER Programming Tips: Data Description and Access Random Access lersus Read Only Memory When coding data descriptions. keep in mind the mix of ROM and RAM in your application.AAA B LXI LDAX B. but you cannot modify them. However. The DS directve reserves memory by Incrementing the location counter by the value of the operand expression. usually the accumulator. Variable data n memory must be assigned to RAM. If the value 01 the operand expression is zero. Notice. it is assigned 1he current value of the location counter. and thus references the first byte of tle reserved memory block. Data Description Before coding your program. followed by the stack. the orgalization of a typical program places Instructions in lower memory. you must have a thorough understanding of ItS input and output data. This way you will have a better idea of the constants and workareas needed In your program. that these initial values must be reloaded Into memory Jrior to each execution of the program. But you'll probably find it more convenient to postpone coding the data descriptions until the remainder of the program is fairly well de\eloped. Therefore.ode sequences have the identical effect of loading the ASCII character A into the accumulator. no memory is reserved. If these items are assigned to RAM. AAA: DB 'A' ALPHA: DB 'ABC' LXI LDAX B.ALPHA B 4-6 .

Chapter 4.. NUMBER .DATE OF HIRE . .10-CHAR EMPLOYEE NUMBER . especially when you want only selected fields from the buffer. Add Symbols for Data Access The following example was presented earlier as an illustration of the DS directive: Label Opcode Operand Comment TTYBUF: DS 72 .RESERVE TTY BUFFER . The LDAX instructions then load the accumulator with one byte of data from the address specified in the Band C registers.RECORD IDENTIFIER .SET B TO ALPHA+l . The program must account for the characters at ALPHA+1 and ALPHA+2..)OB DESCRIPTION 4-7 . Assembler Directives In the examples.ALPHA B B B B B .LOAD ADDRESS OF ALPHA . as in the following coding sequence: ALPHA: DB LXI LDAX INX LDAX INX LDAX 'ABC' B.FETCH 1ST ALPHA CHAR . the LXI instructions load the address of the desired data into the Band C registers.SET B TO ALPHA+2 . you can conserve memory by setting up an instruction sequence that is executed repeatedly until the source data is exhausted. You can simplify this task by subdivid.5-CHAR DEPARTMENT NUMBER .ing the buffer with the EQU directive: Label Opcode Operand Comment TTYBUF: ID NAME NUMBER DEPT SSNO DOH DESC DS EQU EQU EQU EQU EQU EQU EQU 72 TTYBUF TTYBUF+6 TTYBUF+26 TTYBUF+36 TTYBUF+41 TTYBUF+50 TTYBUF+56 . The assembler neither knows nor cares that only one character from the three-character field ALPHA has been accessed.FETCH 2ND ALPHA CHAR .RESERVE TTY BUFFER To access data in this buffer using only expressions such as TTYBUF+l. For longer fields. TTYBUF+72 can be a laborious and confusing chore. TTYBUF+2.DEFINE ALPHA .FETCH 3RD ALPHA CHAR The coding above is acceptable for short data fields like ALPHA.20-CHAR NAME FIELD .SOCIAL SEC.

When you need to generate a custom program. that is. These blocks can be nested to eight levels. Assembler Dir'ctives Subdividing d. If bit 0 IS one. you must be certain to terminate the macro definition 4-8 . CONDITIONAL ASSEMBLY The IF. In either case. Conversely. these statements are ignored.) All statement~ included between an IF directive and its required associated ENDIF directive are defined as an IF-ENDIF blo.ices. As an example. The ELSE directive is optional. you can code a single program. Operands are lOt allowed with the ELSE and ENDIF directives. only if certain conditions that you specify are satisfied. all statements be:ween ELSE and the next ENDIF are assembled. ELSE. and only one ELSE directive may appear In an IF-ENDIF block. assume that a basic control program requires customlz'ing to accept input from one of six dif erent sensing devices and to drive one of five different control dev. When i lcluded. ELSE. Conditional a~sembly is especially useful when your application requires custom programs for a number of common options. (A TRUE expression evaluates to OFFFFH and FALSE to OH: only bit zero need be tested.k. If bit 0 of the resulting value is one (TRUE). til Instructions between the IF directive and the next ELSE or ENDIF directive are assembled. IF. ENDIF [irectives Because these directives are used in conjunction. The code for the individual senso's and drivers must be enclosed by the conditional directives. Label Opcode Operand optional: optional: optional: IF ELSE ENDIF expression The assembler evaluates the expression in the operand field of the IF directive. but coding tht m as shown in the example provides a more useful record description. When bit 0 of the expression in the IF directive IS zero. Macro definitions (explained in the next chapter) may appear within an IF-ENDIF block.Chapter 4. they are described together here. Rather than code some ! thirty separat" programs to account for all the possibilities. When bit 0 is zero (FALSE) these instructions are ignored. you can insert SET directives near the beginning of the source program to select the desired sensor and driver routine . IF-ENDIF blocks may al'pear within macro definitions. Notice that these EQU directives can be inserted anywhere within the program as you need them. and ENDIF directives enable you to assemble portions of your program conditionally. ta as shown in the example simplifies data access and provides useful documentation throughout your program.. An IF-ENDIF block may appear within another IF-ENDIF block. ELSE is the converse of IF.

ASSEMBLED IF 'TYPE = 0' .ASSEMBLED IF 'TYPE . Example 1. NOTE Caution IS required when symbols are defined in IF-ENDIF blocks and referenced elsewhere within the program. when a macro definition begins In an IF block but terminates after an ELSE directive. Simple IF-ENDIF Block: IF TYPE EQ 0 .Chapter 4. IF-ELSE-ENDIF Block: IF TYPE EQ 0 . only a portion of the macro can be assembled.IS TRUE ENDIF CONDl = 0' Example 2. Assembler Directives or IF-ENDIF block so that it can be assembled completely. an IF-ENDIF block begun within a macro definition must terminate within that same macro definition. For example.IS TRUE ELSE COND2: . These symbols are undefined when the evaluation of the IF expression suppresses the assembly of the IF-ENDIF block. Similarly.ASSEMBLED IF 'TYPE = 0' :IS FALSE ENDIF 4-9 .

When source files are combined using the INCLUDE cont'ol. When a number of separate program modules are to be joined together.TRUE 2 IF MODE EO 2 .Chapter 4. 4-10 .AND 'MODE = 2' ARE BOTH .FALSE ENDIF ENDIF ASSEMBLER TERMINATION END Directive The END dir~ctlve identifies the end of the source program and terminates each pass of the assembler. only one may specify a program starting address. the assembler assumes zero as the starting address.ASSEMBLED IF 'TYPE = 0' . If the optioml expression is present. and it must be the last source statement.ASSEMBLED IF 'TYPE = 0' . there are no restrictions on which source file contains the END.ASSEMBLED IF 'TYPE = 0' .15 FALSE = 0' .15 TRUE LE\EL 1 ELSE . The module with a starting address is the main module.ASSEMBLED IF 'TYPE . Nested IF's: IF TYPE EO 0 . Label Opcode Operand optional: END expression Only one END statement may appear in a source program.15 FALSE AND 'MODE = 2' . Assembler Directives Example 3.ASSEMBLED IF 'TYPE = 0' .AND 'MODE = l' ARE BOTH . If no expression is gi len.15 TRUE IF MODE EO 1 COt ID3: LE\'EL 1 ENDIF ELSE LEVEL . its value is used as the starting address for program execution.

The location counter can be altered by the ORG (origin) directive. Label optional: Opcode ORG Operand expression The location counter is set to the value of the operand expression.' After the next tape is loaded. EOT Directive Label optional: Opcode EOT Operand When EOT is recognized by the assembler. LOCATION COUNTER CONTROL AND RELOCATION All the directives discussed in the remainder of this chapter relate directly to program relocation except for the ASEG and ORG directives. 4-11 .Chapter 4. the expression always yields an address in the range 0 through 65. the message 'NEXT TAPE' is sent to the console and the assembler pauses. The next machine instruction or data item is assembled at the specified address. The location counter performs the same function for the assembler as the program counter performs during execution. It tells the assembler the next memory location available for instruction or data assembly. Any symbol In the expression must be preViously defined. an assembler default generates an ASEG directive for you. the location counter is set to zero. Location Counter Control (Non-Relocatable Mode) When you elect not to use the relocation feature. a 'space bar' character received at the console signals continuation of the assembly. The ASEG directive specifies that the program is to be assembled in the non-relocatable mode and establishes a location counter for the assembly. Thus. Assembly-time evaluation of ORG expressions always Yields a modulo 64K address. Initially. These directives are described first for the convenience of readers who do not use the relocation feature. Assembler Directives END-OF-TAPE INDICATION The EOT directive allows you to specify the physical end of paper tape to simplify assembly of multiple-tape source programs. Data in the operand field causes an error. ORG Directive The ORG directive sets the location counter to the value specified by the operand expression.535.

4-12 . or 64K of random access memory. The relocatability feature allows you to deveillp. large programs with many symbols cannot be as. The new assembler dir ~ctives are described later in this chapter. your only concern with locating a program is that it doesn't overlap the resident routines of 1515·11. The relocatal dlity feature also has a malor advantage at assembly-time: often. Example: Assume that the current value of the location counter is OFH (decimal 15) when the following ORG directive is encountered: ORG OFFH . 48K. Support for this new feature includes a number of new directives for the assembler and three new programs included in ISIS-II. test. Therefore.are described in the ISIS-II System User's Guide. and debug your program on the Intellec development system and then simply relocate the object code 10 suit your application. Multiple ORG's need not specify addresses In ascending seq Jence. the program you are developing will almost certainly use some mix of random access memory (RAM). Memory ManagEment When developing. read-only memory (ROM). Such a program can be divided Into a number of rrodules that can be assembled separately and then linked together to form a single object program.LIB.Chapter 4. However. allows the programmer to code programs or sections of programs without worrying about the final arrangerlent of the object code in memory. testing.ORG ASSEMBLER TO LOCATION . Relocatabilit. andior programmable read-only memory (PROM).OFFH (decimal 225) The symbol FAG1 is assigned the address OFH. but if you fail to do so.embled because of limited work space for the symbol table. the location of your future program is not a great concerr. LINK. Introduction to Reocatability A maior feature of this assembler is its system for creating relocatable object code modules. If the option" label is present. it is assigned the current value of the location counter before it is updated by the ORG directiv".o areas: memory management and modular program development. and LOCATE . and debugging a system on your Intellec microcomputer development system. the location of y)ur program affects both cost and performance in your application. Because the Intellec syste 11 has 32K. Assembler Oi 'ectives If no ORG di 'ective is included before the first instruction or data byte in your program. you may instruct the assembler to write over some previously assembled POI tion of the program. Your prograrr can include any number of ORG directives. The three new pr<lgrams . This offers developers of microcomputer systems malor advantages In t". assembly begins at location zero. The next instruction or data byte is assembled at location OFFH.

Programmer B need be concerned only with the module for that one sensor. Then he must retest the entire program to be certain that those changes do not affect any of the other sensors. Programmer A will probably have to complete the program himself. and throttle sensor. the modular approach used by Programmer B has a number of advantages you should consider: • Simplified Program Development It is generally easier to code. • Ease of Testing Programmer B can test and debug most of his modules as soon as they are assembled. Because of his single program concept. simpler programs. By contrast. engine air intake temperature. This requires the program to sample the ambient air temperature. • Sharing the Programming Task If Programmer B finds that he is falling behind schedule. what it really means is that you can subdivide a complex program into a number of smaller. Both programmers want to calculate the degree of spark advance or retardation that provides the best fuel economy with the lowest emissions. Let us examine the approaches two different programmers might take to solve this problem. Because Programmer A cannot test h is program until all the sensors are developed. Programmer B can continue developing and testing programs for the sensors that are ready. This advantage continues throughout the life of the program. his testing schedule IS dependent on events beyond his control. Programmer A must test his program as a whole. This concept is best illustrated through the use of an example. he can assign one or more of his subprograms to another programmer. 4-13 . Assume that a microcomputer program IS to control the spark advance on an automobile engine. Programmer B uses a modular approach and codes separate programs for each input plus one program to calculate spark advance.Chapter 4. manifold vacuum. If a change to one of the sensors requires a programming change. Programmer A must search through his entire program to find and alter the coding for that sensor. Programmer A codes a single program that senses all inputs and calculates the correct spark advance. it IS reasonable to expect some changes during system development. test. Assembler Directives Modular Program Development Although 'relocatability' may seem to be a formidable term. If one of the sensors is behind schedule. and debug several simple programs than one complex program. Although Programmer A avoids the need to learn to use the relocatability feature. • Programming Changes Given the nature of automotive design. idle sensor. Notice that Programmer B has an extra advantage if the sensors are being developed at the same time as the program. coolant temperature.

The LINK Ind LOCATE programs are used to combine segments from individual modules and relocate them in memory. data. Assembler Directives DIRECTIVES USED FOR RELOCATION Several direc Ives have been added to the assembler to support the relocation feature. The DSEG ocation counter specifies a relocatable data segment. the assembler produces a . These direc ives allow you to control program segmentation at assembly time. The CSEG c Ifective specifies a relocatable code segment.Chapter 4. This module comprISes four segments: code. you may want to assign cer:ain code segments to specific addresses. These fall into the general categories of location counter control and program linkage.ts the assembler to use the location counter for the absolute program segment. described In the ISIS-II System User's GUide. The ORG directive can be used to assign a new value to the ASEG location counter. For example. and DSEG directives appear in your program. Regardless 'If how many times the ASEG. T lese programs are explained in the ISIS-II System User's Guide. ASEG Directh'e ASEG dire. The ASEG location counter has an initial value of zero. CSEG. contiguous module. This location counter is used for program elements th It must be located In random access memory. In general.ingle. the CSEG location counter is used for portions of the program that are to be in some form of read-only memory. restart routines invoked by the RST instruction require specific addresses. stack and memory. The ASEG c irective specifies an absolute code segment. All instrucions and data following the ASEG directive are assembled In the absolute mode. The LOCATE program. Location Counter :ontrol (Relocatable Programs) Relocatable Jrograms or program modules may use three location counters. such as machine instructions and program consta ltS. Label optional: Opcode Operand ASEG Operands ere not permitted with the ASEG directive. The ASEG. the guidelines given above are only general since they can be overridden by the LOCATE program. Therefore. The ASEG directive remains in effect until a CSEG or DSEG directive is encountered. DSEG. Even in a relocatable program module. gives you control over program segment location. and CSEG directives sp"cify which location counter is to be used. 4-14 ..

512. In the relocatable mode uSing the code Labe! Opcode Operand blank } PAGE { INPAGE optional: CSEG When a program contains multiple CSEG directives. CSEG Directive CSEG directs the assembler to assemble subsequent instructions and data segment location counter. Therefore.Chapter 4. DSEG Directive DSEG directs the assembler to assemble subsequent instructions and data segment location counter.This code segment must begin on a page boundary when relocated. The operands for the DSEG directive have the same meaning as for the CSEG directive except that they apply to the data segment. but is stored with ·the object code to be passed to the LINK and LOCATE programs. The code segment location counter has an initial value of zero.) The LOCATE program uses this information to determine relocation boundaries when it joins this code segment to code segments from other programs. etc. INPAGE This code segment must fit within a single page when relocated. The operand of a CSEG directive has no effect on the current assembly.). • The CSEG directive remains in effect until an ASEG or DSEG directive is encountered.This code segment may be relocated to the next available byte boundary. The meaning of the operand is as follows: • • blank . PAGE . the assembler assumes the ASEG directive to be in effect. In the relocatable mode using the data Labe! Opcode Operand optional: DSEG roo' PAGE INPAGE) i> When multiple DSEG directives appear in a program. Assembler Directives When assembly begins. The ORG directive can be used to assign a new value to the CSEG location counter. they must all specify the same operand throughout the program. (These programs are described in the ISIS-II System User's Guide. the entire program is assembled in absolute mode and can be executed immediately after assembly without using the LINK or LOCATE programs. If neither of these directives appears in the program. 4-15 . 256. all CSEG directives throughout the program must specify the same operand. Page boundaries occur in multiples of 256 bytes beginning with zero (0. a CSEG or DSEG must precede the first instruction or data definition in a relocatable module.

Any symboilised in the operand expression must have been previously defined. ORG Directive ('?elocatable Mode) The ORG dirxtive can be used to alter the value of the location counter presently in use. or DSEG directive is in effect. A program n. n address in the code segment. therefore. but only one location counter is in use at any given point in the program.Chapter 4. it becomes necessary for these separate programs to communicate Information among themselves. Thus. that the assembler normally 4-16 . however. Establishing such communication is the function of the program linkage directives. If the option 11 label is present. CSEG. Thus. Your prograln can directly access data or instructions defined In another program if you know the actual address of tre item. if the ORG directive appears within a data segment. the item must be assigned a name or a label when it IS defined in the program. Label optional: Opcode ORG Operand expression There are thr~e location counters. The data segr. iOlned together and executed as a single program. The ORG directive can be used to assign a new value to the [)SEG location counter.lent location counter has an initial value of zero. Assembler Dil ectives There IS no ir teraction between the operands specified for the DSEG and CSEG directives. Program Linkage [irectives Modular pro! ramming and the relocation feature enable you to assemble and test a number of separate programs that are to b. the val Je of its expression must be relocatable within the data segment. Only Items having an entry in the iymbol table can be shared with other programs. a code segment can be byte r'locatable while the data segment is page relocatable. An exception causes phase errors for all abels that follow the ORG and a label error if the undefined error is defined later.ay share its data addresses and instruction addresses with other programs. Eventually. It is assigned the current value of the location counter presently in use before the ORG din ctive is executed. but this is unlikely when both programs use relocation. Items to be shared with other programs must be declared in a PUBLIC directive. Notice. the value of its operand expression must be either absolu'e or relocatable within the current segment. Your program can also gain access to data or Instructions declared as PUBLIC in other programs. Which one dEpends on whether the ASEG. When the O~ G directive appears in a relocatable program segment. An error occurs if the expression evaluates to . The DSEG diective remains in effect until an ASEG or CSEG directive is encountered.

COS. Assembler Directives flags as an error any reference to a name or label that has not been defined in your program. Example: PUBLIC SIN. When multiple items appear in the list. The assembler flags this error. you must provide the assembler with a list of items used in your program but defined in some other program. EXTRN directives may appear anywhere within a program module. the effect is the same as defining the same symbol more than once in a program. Label optional: Opcode PUBLIC Operands name-list Each item in the operand name-list must be the name or label assigned to data or an instruction elsewhere in this program. they must be separated by commas. they must be separated by commas. A symbol may be declared to be external only once in a program module. Because of this. Label optional: Opcode EXTRN Operands name-list Each item in the name-list identifies a symbol that may be referenced in this program butis defined in another program. When multiple names appear in the list. are individually explained later in this chapter. 4·17 . PUBLIC directives may appear anywhere within a program module. The two remaining program linkage directives.SQRT EXTRN Directive The EXTRN directive provides the assembler with a list of symbols referenced in th is program but defined in a different program. PUBLIC Directive The PUBLIC directive makes each of the symbols listed in the operand field available for access by other programs.TAN. To avoid this. it is flagged as an error. NAME and STKLN.Chapter 4. Each name may be declared PUBLIC only once in a program module. If a symbol in the operand name-list is also defined in this program by the user. Reserved words and external symbols (see the EXTRN directive below) cannot be declared to be PUBLIC symbols. These items must be declared in an EXTRN directive. Symbols declared to be PUBLIC cannot also be declared to be EXTRN symbols. If an item in the operand name-list has no corresponding entry in· the symbol table (implying that it i5 undefined). or is a reserved symbol. the assembler establishes linkage to the other program and does not flag the undefi ned references as errors.

Example: NAME MAIN STKLN Directile Regardless 01 the number of object program modules you may bind together. This will cause an error if you attempt to bind together several object program modules and more than one has the name MODULE. The module···name assigned by the NAME directive appears as part of the page heading in the assembly listing. ectives If you omit a symbol from the name-list but reference it 111 the program. The STKLN dire' tive allows you to specify the number of bytes to be reserved for the stack for each module. Label Opcode Operand optional: STKLN expression The operand expression must evaluate to a number which will be used as the maximum size of the stack. This name must conform to the rules for jefining symbols. but may follow comments anj control lines. the symbol is undefined.Chapter 4. if you make an error coding the NAME directive. Assembler Oi. 4-18 . Also. the assembler supplies a default NAME directive with the module-name MODULE.BEGIN NAME Directive The NAME directive assigns a name to the object module generated by this assemblY. If the NAME directive is missing from the program. Label Opcode Operand optional: NAME module-name The NAME directive requires the presence of a module-name in the operand field. the default nime MODULE is assigned. The assembler flags this erro'. The NAME directive must precede the first data or instruction coding in the source program. Module names are necessary so that you can refer to a module and specify the proper sequence of modules when a numr er of modules are to be bound together. You may include symbols in the operand name-list that are not referenced in the program without causing ail error. only one stack is generated. Example: EXTRN ENTRY.ADDRTN.

a number of housekeeping or initialization procedures are performed when execution first begins. you must duplicate those procedures in the module to be tested. etc. Initialization Routines In most complete programs. However. However. These reserved words are external references whose addresses are supplied by the LOCATE program. the assembler provides a default STKLN of zero. Assembler Directives When the STKLN directive is omitted.Chapter 4. Example: STKLN 100 STACK and MEMORY Reserved Words The reserved words STACK and MEMORY are not directives but are of interest to programmers using the relocation feature. you can base data structures on this address using symbolic references such as MEMORY. that you can link any number of modules together for testing.) One of the most important initialization procedures is to set the stack pointer. however. STACK+2. you can base data structures on this address using svmbolic references such as STACK+1. If the program module you are testing relies on initialization procedures aSSigned to a different module. Also.STACK 4-19 . only one stack will be generated. MEMORY+l. This is useful when multiple programs are bound together. Your program should include the following instruction to initialize the stack pointer: LXI SP. Again. so only one program module need specify the stack size. If your program includes more than one STKLN directive. (Notice. The LOCATE program determines the origin of the stack. Programming Tips: Testing Relocatable Modules The ability to test individual program modules is a maior advantage of modular programming. only the last value assigned is retained. you should provide a STKLN if your module is to be tested separately and uses the stack. many program modules are not logically self-sufficient and require some modification before they can be tested. You need this address to initialize the stack pointer register. STACK is the symbolic reference to the stack origin address. etc. MEMORY is the symbolic reference to the first byte of unused memory past the end of your program. The following is a discussion of some of the more common modifications that may be required.

this is the address of the first byte of unused memory past the end of your program. Since your Intellec development system probably has considerably more random access memory than you need to test a program module.Chapter 4. In particular. This memory can be used fer storing test data or even for a program that generates test data. Your program must simulate any of these procedures it needs to operate. this memory using the symbolic reference MEMORY.rogram modules. you may be able to simula:e Input and output data right in memory. make certain that only one module in the complete program initializes the stack pointer. 4-20 . You can acces. MEMORY+l. The LOCATE program supplies an address for the reserved word MEMORY. be certain to remove any code you inserted for testing. Remove Coding Used for Testing After testing ~our program. Assembler [irectives Input/Output When testing . it is likely that some input or output procedures appear in other modules. and so on.

What Is A Macro? A macro can be described as a routine defined in a formal sequence of prototype instructions that. e e In addition. and the d:". Useful functions can be collected In a library to allow macros to be copied into different programs. results in the replacement of each such call with a code expansion consisting of the actual instructions represented. Therefore. a macro can be used any number of times in the same program without duplicating any of its own symbols. Also. This reduces debugging time. when called within a program. In developing your program. you will find that they are identical except for three parameters: the character count. you find yourself coding another routine to move four bytes from a different source field to a different destination field. as you code your program. the source field starting address. macros can be used to improve program readability and to create structured programs. Duplication of effort between programmers can be reduced. suppose that you code a routine that moves five bytes of data from one memory location to another.5. The macro facility provides this capability and offers several other advantages over writing code repetitiously' e e The tedium of frequent rewrite (and the probability of error) is reduced. 5-' . USing macros to segment code blocks provides clear program notation and simplifies tracing the flow of the program. An error detected In a macro need be corrected only once regardless of how many times the macro appears in the program. As an example.tiiCatltl:'\ field starting address. MACROS INTRODUCTION TO MACROS Why Use Macros? A macro is essentially a facility for replacing one set of parameters with another. Certainly It would be handy if there were some way to regenerate that original 'outine substituting the new parameters rather than rewrite that code yourself. A little later. If the two routines use the same coding techniques. Symbols used in macros can be restricted so that they have meaning only within the macro itself. you need not worry that you will accidentally duplicate a symbol used in a macro. you will frequently find that many Instruction sequences are repeated several times with only certain parameters changed.

When this sou. and expansion can be illustrated by a tYPical business form letter. it overlooks the relationship of the macro processor and the assembler. Thus the macro call might look like CNFII~M 123. 'Ontario'. where the prototypenstructions conSISt of preset text. CAR. This macro might have the text Your lutomobile reservation has been confirmed with MAKE rent-a-car agency. we could define a macro CNFIRM with the text Air FI ght welcomes you as a passenger. Your 'Iight number FNO leaves at DTIME and arrives in DEsT at ATIME. While this exallple illustrates the substitution of parameters in a macro. and arrival time. Dear~AME: The entire tex of the business letter (source file) would then look like GREET 'Ms. Since'ely. '10:45'. the macro calls are expanded to produce the following letter. 'Ontario'. '11:52' CAR 'Blotz' We tr Jst you will enioy your flight. scannel: Air Fight welcomes you as a passenger. Your flight number 123 leaves at 10:45 and arrives in Ortario at 11 :52. We trust you will enjoy your flight. For example. scannel' CNFl~M 123. could be called if the passenger has requested that a rental car be reserved at the destination airport. call. four dummy parameters to be replaced. Macros The concepts c f macro definition. Since ely. This macro ha.ce file is passed through a macro processor. '10:45'. a macro GREET could be defined to specify the passenger name. Finally. departure time destination. when the macro is called. by the actual flight number. 5-2 . Dear 'v1s. Your automobile reservation has been confirmed with Blotz rent-a-car agency.Chapter 5. '11 :52' A second macro. The purpose of the macro processor is to generate source code which is then assembled.

Thus. These two tools enable a general-purpose macro definition to generate customized source code for a particular programming situation. A macro definition is Initiated by the MACRO assembler directive. you may be wondering how macros differ from subroutines Invoked by the CALL instruction. The prototype instructions bounded by the MACRO and ENDM directives are called the macro body. the use of macros may be more efficient.. and subroutines can contain macros... By changing the parameters In a macro call.Chapter 5. you can change the source code the macro generates. Notice the emphasis on 'versions' in the prevIous sentence. 5·3 . Macro Definition Macros must be defined in your program before they can be used. Determining which of these facilities to use is not always an obvious decision. for this is a malor difference between macros and subroutines. which lists the name by which the macro can later be called. uSing a single subroutine rather than multiple In-line macros can reduce the overall program size.. In some cases. A macro does not necessarily generate the same source code each time it is called. Subroutines At this point. macro parameters can be tested at assembly-time by the conditional assembly directives. The macro definition is terminated by the ENDM directive. . In addition. USING MACROS The assembler recognizes the following macro operations: . CI CI CI MACRO directive ENDM directive LOCAL directive REPT directive IRP directive IRPC directive EXITM directive Macro call All of the directives listed above are related to macro definition. a program contains only one version of a given subroutine. . Notice that macro expansion and any code customization occur at assembly-time and at the source code level. One distinction between the two IS that subroutines necessarily branch to another part of your program while macros generate in-line code. notice that macros can call subroutines.. . Both aid program structuring and reduce the coding of frequently executed routines. The macro call initiates the parameter substitution (macro expansion) process. a generalized subroutine resides in your program and requires execution time. It IS usually possible to obtain similar results using either a macro or a subroutine. In situations involving a large number of parameters. but contains as many versions of a given macro as there are calls for that macro. . Also. By contrast. and the dummy parameters to be replaced during macro expansion. Macros Macros Vs.

its reserved value is not recognized. the use of these registers is not affected outside the macro definition. This can be accomplished with minimal coding effort using the REPT (repeat block). Dummy paralneters may appear in a character string. either within a macro or in line with other source ':ode. they must be . The distinguishing feature of ma. A dummy panmeter can be any valid user-defined symbol name or can be null. The EXITM c irective provides an alternate exit from a macro. substitutions will occur properly.eparated by commas. Any valid user-defined symbol name can be Jsed as a macro name. However.ro prototype text is that parts of it can be made variable by placing substitutable dummy parameters in instrLction fields. the dummy parameter must be adjacent to an ampersand chlracter (&) as explained later In this chapter. if you code A. When encountered. and G3. When multiple parameters are listed. IRP (indefinite repeat). A label can be given limited scope using the LOCAL directive. However. Like the MACRO directive. The scope of a dummy parameter is limited to its specific macro definition. Directives MACRO Dire:tive Label name Opcode MACRO Operand optional dummy parameter(s) The name in :he label field specifies the name of the macro body being defined. 5-4 . Because of the limited scope of dummy parameters. Example: Define macro MACl with dummy parameters Gl. multiply-defined symbol errors result if the macro is called more than once. and IRPC (indefinite repeat character) directives. If a reserved symt 01 is used as a dummy parameter. No substitution occurs for such parameters. Note that this name must be present and must not be terminated by a colon. you cannot use the accumulator or the Band::: registers within the macro. Dummy paralneters in a comment are not recognized. Macros When label sy mbols used in a macro body have 'global' scope. For example. Any machine Instruction or applicable assembler directive can be included in the macro body.Chapter 5.C as a dLmmy parameter list. G2.B. Macro Definitior. it terminates the current macro just as if EN['M had been encountered. These dummy parameters are the same as the symbols in the operand field of the MACRO dire'tive. Occasionally "ou may wish to duplicate a block of code several times. Dummy parameters also have limited scope. these directives are terminated by ENDM. This directive assigns a unique value :0 the symbol each time the macro is called and expanded.

Chapter 5. The user should avoid coding symbols in the form ??nnnn so that there will not be a conflict with these assembler-generated symbols. Macros NOTE The following macro definition contains a potential error that IS clarified in the description of the LOCAL directive later in this chapter. the assembler assigns each local symbol a unique symbol in the form 77nnnn. 'nested' macro call. It is also required to terminate code repetition blocks defined by the REPT. Each time the macro is called and expanded.M G2 B.M G3 C. (See 'Nested Macro Definitions' later in this chapter. The assembler assigns ?7OOO1 to the first local symbol.) LOCA L Directive Label Opcode Operand LOCAL label name(s) The specified label names are defined to have meaning only within the current macro expansion. The assembler never duplicates these symbols.G2.G3 Gl A. and so on. and IRPC directives.M . MACl MOVES: MACRO LHLD MOV LHLD MOV LHLD MOV ENDM Gl. IRP.ENDM DIRECTIVE ENDM Directive Label Opcode Operand ENDM The ENDM directive is required to terminate a macro definition and follows the last prototype instruction.MACRO DIRECTIVE . 5-5 . The most recent symbol name generated always indicates the total number of symbols created for all macro expansions. 770002 to the second.MACRO BODY . NOTE Because nested macro calls are not expanded during macro definition. Any data appearing in the label or operand fields of an ENDM directive causes an error. the ENDM directive to close an outer macro cannot be contained in the expansion of an inner.

MOVES is a multiply-defined symbol. MOVES IS replaced with the symbol 7?OOOl. Also.Chapter 5. a name appea-ing in the label field of a LOCAL directive causes an error. MOVES is replaced with 7?0002. Macros Dummy parameters included in a macro call cannot be operands of a LOCAL directive. A LOCAL directive appearing outside a macro definition causes an error. the assembler must encounter the definition of he symbol prior to encountering the expression.M G3 C. 5-6 . All lines appeanng between the REPT directive and a subsequent ENDM directive constitute the block to be repeated. Any number of LOCAL directves may appear in a macro definition. The ~ cope of a dummy parameter is always local to its own macro definition. This is a potential error since no error occurs if MACl IS called only once in the program. but they must all follow the macro call and must precede the first line 01 prototype code. the second time. Because the assembler encounters only these special replacement symbols. if MACl is called more than once. When 'expression' contains symbolic names. the program may contain the 'ymbol MOVES without causing a multiple definition. The first tirle MACl is expanded. or if the program uses the symbol MOVES. This potential error is avoided by naming MOVES in th'eoperand field of a LOCAL directive: MACl MOVES: MACRO LOCAL LHLD MOV LHLD MaY LHLD MaY ENDM Gl. However.M G2 B. No explicit call is required to cause the code insertion since the definition is an implied call for expansion.G3 MOVES Gl A. Example: The definition of MACl (used as an example in the description of the MACRO directive) cOlltains a potential error because the symbol MOVES has not been declared local. and the program itself does not use MOVES as a ~ymbol.G2. The insertion of repeat blocks is performed in-line when the assembler encounters the REPl directive. REPT Directive Label Opcode Operand optional: REPT expression The REPT directive causes a sequence of source code lines to be repeated 'expression' times. Local symbols can be defined only within a macro definition.M Assume that MACl is the only macro in the program and that it is called twice.

The multiplication is accomplished through a series of shifts. This example replaces the loop with seven repetitions of the four instructions enclosed by the REPT-ENDM directives. Notice that the expansion specified by this REPT directive causes the label SKIPAD to be generated seven times. ROTR6: REPT RRC ENDM 6 Example 2: The following REPT directive generates the source code for a routine that fills a five-byte field with the character stored in the accumulator: PROGRAM CODE GENERA TED CODING LHLD REPT MOV INX ENDM CNTR1 5 M.16-BIT RESULT .A H M.A H M.. The example in Chapter 6 uses a program loop for the multiplication.D H.IN H&L 7 SKIPAD SKIPAD D H . SKIPAD must be declared local to this macro. FSTMUL: MVI LXI REPT LOCAL RLC jNC DAD DAD ENDM RLC RNC DAD RET 5-7 D.A H Example 3: The following example illustrates the use of REPT to generate a multiplication routine. Therefore..GET NEXT MULTIPLIER BIT .FAST MULTIPLY ROUTINE .MULTIPLY E*A .Chapter 5.D .A H M..ADD MULTIPLICAND INTO ANSWER SKIPAD: D . Macros Example 1: Rotate accumulator right six times.DON'T ADD IF BIT = D . refer to the example of multiplication in Chapter 6.A H LHLD MOV INX MOV INX MOV INX MOV INX MOV INX CNTR1 M. If this technique is unfamiliar.A H M.

A H IRPC Directhe Label optional: Opcode IRPC Operand dummy param. The number of actual parameters in the list controls the nilmber of times the macro body is repeated. it requires more memory. (See 'Special Operators' later in this chapter for a description of null operands. I items in the list must be separated by commas.<FL01.FLD3> H.text 5-8 . Macros This example ilustrates a classic programming trade-off: speed versus memory Although this example executes more qUickly tlan the example in Chapter 6.) Example: The following code sequence gathers bytes of data from different areas of memory and then stores them in consecutive b~ tes beginning at the address of STORIT PROGRAM CODE LXI IRP GENERA TED CODING LXI LOA MOV INX LDA MOV INX H. IRP Directive Label optional: Opcode IRP Operand dummy param. IRP then expands the prototype code agai 1 substituting the second actual parameter from the list. two commas with no intervening character create a null parameter within the list.A H M. IRP generates one copy of the macro body substituting a nul' for each occurrence of the dummy parameter.STORIT FLOl LOA MOV INX ENOM X M. This process continues until the list is exhausted. <list> The operand field for the IRP (indefinite repeat) directive must contain one macro dummy parameter followed by a list of actual parameters enclosed In angle brackets. IRP expands its associated macro prototype code substituting the fi 'st actual parameter for each occurrence of the dummy parameter. Individu.A H 3E20H M. The list of actJal parameters to be substituted for the dummy parameter must be enclosed In angle brackets « ». An empty list (one with no Jarameters coded) specifies a null operand list. Also.STORIT X.3E20H. a list of n Items causes n repetitions.Chapter 5.A H FL03 LOA MOV INX M.

The assembler generates one iteration of the prototype code for each character in the text string. concatenation (described later in this chapter) provides the capability for building text strings from Individual characters. IRP.7 IRPC provides the capability to treat each character of a string individually. IRPC generates one copy of the macro body substituting a null for each occurrence of the dummy parameter. Example: EXITM is typically used to suppress unwanted macro expansion.X DATE-l H M. EXITM causes an exit to the previous level of macro expansion.l H M. the assembler substitutes the next character from the string for each occurrence of the dummy parameter.9 H M. macro expansion is terminated when the EX1TM directive is assembled because the condition X EQ 0 is true. When used in nested macros. If the text string is enclosed in optional angle brackets. An EXITM within a REPT. IRP. or IRPC terminates not only the current expansion. EXITM Directive Label Opcode Operand optional: EXITM EXITM provides an alternate method for terminating a macro expansion or the repetition of a REPT. In the following example. When EX!TM is encountered. Example: PROGRAM CODE LHLD IRPC INX MVI ENDM GENERA TED CODING LHLD INX MVI INX MVI INX MVI INX MVI DATE-l X. any delimiters appearing in the text string are treated simply as text to be substituted into the prototype code.Chapter 5. or IRPC code sequence. For each Iteration.7 H M. A list of n text characters generates n repetitions of the IRPC macro body. Macros The IRPC (indefinite repeat character) directive causes a sequence of macro prototype instructions to be repeated for each text character of the actual parameter specified. the assembler ignores all macro prototype instructions located between the EXITM and ENDM directive for this macro.1977 H MVDATE: M. 5-9 . but not in place of ENDM. An empty string specifies a null actual operand. but all subsequent iterations as well. Any data appearing in the operand field of an EXITM directive causes an error. Notice that EXITM may be used in addition to ENDM.

M.) Double semicolon. Carriage returns cannot be passed as actual parameters. The 'I' is always preserved while building an actual parameter. The assembler recognizes a number of operators that allow special operations: & Ampersand. when an actual parameter contains blanks (passing the instruction MOV A. for example) the parameter must be enclosed in angle brackets. use one set of angle brackets for each level of nesting. (See 'Nested Macro Definitions. To pass such text to nested macro calls.>. Angle brackets. that contain other delimiters.Y IF X EQ 0 EXITM ENDM Special Macro Op?rators In certain specal cases. Notice that blanks are usually treated as delimiters. Therefore.<. These special ( perators instruct the assembler to accept the enclosed character (the comma) as an actual parameter rather tha'l a del im iter. Used to concatenate (link) text and dummy parameters.. the normal rules for dealing with macros do not work. Used primarily to pass angle brackets as part of an actual parameter. and the second parameter happens to be the comma character. except when the substitution is being used to build another actual parameter. The comment still appears in the listing of the definition. To pass a literalized exclamation point. such as lists. See the further discussion of ampersands below. Exclamation point (escape character). It is not echoed when an actual parameter is substituted for a dummy parameter.. the list PARM1. that you want to specif" three actual parameters. Macros MAC3 MACRO X. Used before a comment in a macro definition to prevent inclusion of the comment in expansions of the macro and reduce storage requirements.' below. To the assembler. The list can be passed correctly by enclosing the comma in angle brackets: PARM1.Chapter 5. Placed before a character (usually a delimiter) to be passed as literalized text in an actual parameter. Used to delimit text. This is also true for any other delimiter that is to be passed as part of an actual parameter. for example.PARM3. issue!!. <> 5-10 . Assume.PARM3 appears to be a list of four parameters where the second and third parameters are missirg.

Intervening blanks are not allowed. It is necessary. A null parameter can also be represented by two consecutive single quotes: ". If nested macro definitions (described below) contain ampersands. In the assembly listing a null looks the same as a blank. The omitted (or null) parameter can be represented by two consecutive delimiters as in the list PARMl "PARM3. Ampersands are not recognized as operators in comments.PARM3. 9800292. Notice that a null is quite different from a blank: a blank is an ASCII character with the hexadecimal representation 20H. The absence of this control (which In effect is a null parameter) specifies that the assembler is to generate only 8080 object code. a null has no character representation.Z it is acceptable for either the X or Y parameter to be null. to indicate the omission of the parameter. The programmer must decide the meaning of a null parameter. Example: In a macro with the dummy parameters W. the only ampersands removed are those adjacent to dummy parameters belonging to the macro definition currently being expanded.Chapter 5. Ampersands placed inside strings are recognized as concatenation delimiters when adjacent to dummy parameters. The following IF directive tests for the error condition: IF NUL X&Y EXITM When a macro IS expanded. but not both. When it is not adjacent to a dummy parameter. coding MOD85 as an assembler control specifies that the assembler is to generate obiect code for the 8085. but that is only because no substitution has taken place.Y. 5-11 .X. the defaults taken for assembler controls provide a good example of what a null parameter can mean. the ampersand is not removed and is passed as part of the macro expansion text. For example. Assembler controls are explained in the 1515-11 8080/8085 Macro Assembler Operator's Manual. similarly. however. Macros NUL In certain cases it is not necessary to pass a parameter to a macro. All ampersands must be reo moved by the time the expansion of the encompassing macro body is performed. dummy parameters within character strings are recognized only when they are adjacent to ampersands. any ampersand preceding or following a dummy parameter in a macro definition is removed and the substitution of the actual parameter occurs at that point. Exceptions force illegal character errors. Although the mechanism is somewhat different.PARM2. NOTE The ampersand must be immediately adjacent to the text being concatenated.

they also can be nested within another definition created by IRF. a lower-level definition can be defined differe ltly if the two contain common dummy parameters. each time a higher-level macro is called. that is.nded. each macro call is replaced by the macro definition code. Macro Call Format Label optional: Opcode macro name Operand optional actual parameter(s) 5-12 . an element in an IRP or IRPC actual parameter list (enclosed 1. In addition. IRFC. or MACRO directives. REPT. A lower-level macro cannot be called unless all higher-level macro definitions have already been called and exp. Such redefinition can be costly. When a higher-evel macro is called for expansion. it can be called any number of times in the program. Since IRP. A new macro I nay be defined or an existing macro redefined by a nested macro definition depending on whether the name of the nested macro is a new label or has previously been established as a dummy parameter in a higher-level ma:ro definition.Chapter 5.PARAM2 ENDM LISTS <A. macro definitions can be nested). The body of a macro consists of all text (including nested macro definitions) bounded by mltching MACRO and ENDM directives. lists of parameters can contain elements that . Macros Nested Macro Del initions A macro definition can be contained completely within the body of another macro definition (that is. Therefore. IRPC.. the next lower-level macro is defined and eligible to be called for expansion. in terms of assem oler execution speed.C» MACRO CALLS Once 'a macro las been defined. dummy parameters are replaced by actual parameters. <B. The assembler allows any number of macro definitions to be nested. Example: LISTS MACRO PARAM1. The call consists of the macro name alid any actual parameters that are to replace dummy parameters during macro expansion_ During assembly.. and REPT blocks constitute macro definitions. however.1 angle brackets) may itself be a list of bracketed parameters.re also lists.

the second actual parameter replaces the second dummy parameter. Notice that blanks are usually treated as delimiters. you must be certain to list actual parameters in the appropriate sequence for the macro. and the C register with a byte from the third parameter.M LOAD simply loads the accumulator with a byte of data from the location specified by the first actual parameter. the extra parameters are ignored. Otherwise. The first time LOAD is called. 5-13 .G3 MOVES Gl A. for example) the parameter must be enclosed in angle brackets. It is used as part of a routine that inverts the order of three bytes in memory. The assembler inserts the macro body identified by the macro name each time it encounters a call to a previously defined macro in your program.M G2 B.G2. When coding a macro call. If fewer parameters appear in the call than in the definition. when an actual parameter contains blanks (passing the instruction MOV A. If a macro call specifies more actual parameters than are listed in the macro definition. Macros The assembler must encounter the macro definition before the first call for that macro. Example: The following example shows two calls for the macro LOAD. the B register with a byte from the second parameter. The first-listed actual parameter replaces each occurrence of the first-listed dummy parameter. and so on. This is also true for any other delimiter that is to be passed as part of an actual parameter. the macro call is assumed to be an illegal opcode. it is part of a routine that adds the contents of the B register to the accumu· lator and then compares the result with the contents of the C register. a null replaces each missing parameter.Chapter 5. The positioning of actual parameters in a macro call is critical since the substitution of parameters is based solely on position. LOAD is defined as follows: LOAD MOVES: MACRO LOCAL LHLD MOV LHLD MOV LHLD MOV ENDM Gl. Therefore. The second time LOAD is called. Carriage returns cannot be passed as actual parameters.M G3 C.M.

C 3EOH A.B DCX H MOY M.CHECK DIGIT CMP C CNZ DGTBAD SUBSTITUTION JNZ LHLD MOY LHLD MOY LHLD MOY MOY DCX MOY DCX MOY LHLD MOY LHLD MOY LHLD MOY ADD CMP CNZ NEXT FLD A. PARAM1 RECALL SET 5 MACRO PARAM1 IF SET RECALL ENDIF PARAM1 NE 0 PARAM1-1 .Chapter 5. as long as the recursive macr" expansions can be terminated eventually. it ml st be defined before the enclosing macro is called.C LOM' 3EOH.FLD+1.M FLD+1 B.INYERT BYTES DCX H MOY M.M FLD+2 C. A macro defin tlon can also contain nested calls to itself (recursIVe macro calls) up to eight levels. Example: Have a macro :all itself five times after it is called from elsewhere in the program.M CHECK C. The macro being called need not be defined when the enclosing macro is defined.CHECK DIGIT C DGTBAD Nested Macro Calls Macro calls (in:luding any combination of nested IRP.A .M B .CHECK ADD B .INYERT BYTES H ??0001 . 7?0002: M.M BYTE B. IRPC.RECURSIYE CALL ENDM 5-14 . Macros MAIN PROGRAM JNZ nEXT LOA[ FLD.BYTE. ELSE.FLD+2 MOY M. and REPT constructs) can be nested within macro definitions up to eight levels. ENDIF).B H M.A . however. This operation can be controlled using the conditional assembly direc:lves described in Chapter 4 (IF.M M.

Chapter 5. Macros

Macro Expansion When a macro is called, the actual parameters to be substituted into the prototype code can be passed in one of two modes. Normally, the substitution of actual parameters for dummy parameters is simply a text substitution. The parameters are not evaluated until the macro is expanded. If a percent sign (%) precedes the actual parameter in the macro call, however, the parameter is evaluated immediately, before expansion occurs, and is passed as a decimal number representing the value of the parameter. In the case of IRPC, a '%' preceding the actual parameter causes the entire text string to be treated as a single parameter. One IRPC iteration occurs for each digit in the decimal string passed as the result of immediate evaluation of the text string. The normal mechanism for passing actual parameters is adequate for most applications. Using the percent sign to pre-evaluate parameters is necessary only when the value of the parameter is different within the local context of the macro definition as compared to its global value outside the macro definition. Example: The macro shown in this example generates a number of rotate instructions. The parameters passed in the macro call determine the number of positions the accumulator is to be rotated and whether rotate right or rotate left instructions are to be generated. Some typical calls for this macro are as follows: SHIFTR SHIFTR 'R',3 L,%COUNT-l

The second call shows an expression used as a parameter. This expression is to be evaluated immediately rather than passed simply as text. The definition of the SHIFTR macro is shown below. This macro uses the conditional IF directive to test the validity of the first parameter. Also, the REPT macro directive is nested within the SHIFTR macro. SHIFTR MACRO IF X EQ 'R' REPT Y RAR ENDM ENDIF IFXNE'L' EXITM ELSE REPT Y RAL ENDM ENDIF ENDM The indentation shown in the definition of the SHIFTR macro graphically illustrates the relationships of the IF, ELSE, ENDIF directives and the REPT. ENDM directives. Such indentation is not required in your program, but may be desirable as documentation. X,Y

5-15

Chapter 5. Macros

The SHI FTRllacro generates nothing if the first parameter is neither R nor L. Therefore, the following calls produce no c(,de. The result in the object program is as though the SHIFTR macro does not appear in the source program. SHIFTR SHIFTR 5 'B',2

The following call to the SHIFTR macro generates three RAR instructions: SHIFTR 'R',3

Assume that, SET directive elsewhere in the source program has given COUNT the value 6. The following call generates five RAL instructions: SHIFTR 'L ',%COUNT -1

The following is a redefinition of the SHIFTR macro. In this definition, notice that concatenation is used to form the RAf: or RAL operation code. If a call to the SHIFTR macro specifies a character other than R or L, illegal operati,m codes are generated. The assembler flags all illegal operation codes as errors. SHIFTR MACRO REPT RA&X ENDM ENDM
X,y Y

NULL MACROS
A macro may legally comprise only the MACRO and ENDM directives. Thus, the following is a legal macro definition: NADA MACRO ENDM P1,P2,P3,P4

A call to thiS macro produces no source code and therefore has no effect on the program. Although thel e is no reason to write such a macro, the null (or empty) macro body has a practical application. For example, all the macro prototype instructions might be enclosed With IF-ENDIF conditional directives. When none 0', the specified conditions IS satisfied. all that remainS of the macro is the MACRO directive and the ENDM di ·ective.

SAMPLE MACR05
The followin! sample macros further demonstrate the use of macro directives and operators.

5-16

Chapter 5. Macros

Example 1: Nested IRPC The following macro definition contains a nested IRPC directive. Notice that the third operand of the outer macro becomes the character string for the IRPC: MOVE MACRO IRPC LHLD SHLD ENDM ENDM X,Y,l PARAM,l X&&PARAM Y&&PARAM

Assume that the program contains the call MOVE SRC,DST,123. The third parameter of this call IS passed to the IRPC. This has the same effect as coding IRPC PARAM,123. When expanded, the MOVE macro generates the following source code: LHLD SHLD LHLD SHLD LHLD SHLD SRCl DSTl SRC2 DST2 SRC3 DSn

Notice the use of concatenation to form labels in this example.

Example 2: Nested Macros Used to Generate DB Directives This example generates a number of DB 0 directives, each With ItS own label. Two macros are used for this purpose: INC and BLOCK. The INC macro is defined as follows: INC $ SAVE GEN Fl&F2: RESTORE MACRO DB ENDM The BLOCK macro, which accepts the number of DB's to be generated (NUMB) and a label prefix (PREFIX), is defi ned as follows: BLOCK MACRO SAVE NOGEN COUNT SET REPT COUNT SET INC ENDM RESTORE ENDM NUMB,PREFIX Fl,F2
0

;GENERATE LABELS & DB's

$

o
NUMB COUNT+l PREFIX,%COUNT ;NESTED MACRO CALL

$

5-17

Chapter 5. Macros

The macro ca I BLOCK 3.LAB generates the following source code: BLOCK DB DB DB 3.LAB

LABl: LAB2: LAB3:

o

o
o

The assemblet controls specified in these two macros (the lines beginning with $) are used to clean up the assembly Iistit,g for easier reading. The source code shown for the call BLOCK 3.LAB is what appears in the assembly listillg when the controls are used. Without the controls. the assembly listing appears as follows: BLOCK SET REPT SET INC ENDM SET INC DB SET INC DB SET INC DB 3.LAB 0 3 COUNT+l LAB.%COUNT COUNT+1 LAB.%COUNT 0 COUNT+l LAB.%COUNT 0 COUNT+l LAB.%COUNT 0

COUNT COUNT

COUNT LAB1: COUNT LAB2: COUNT LAB3: Example 3:

" Macro that Converts Itself into a Subroutine

In some case5. the in-line coding substituted for each macro call imposes an unacceptable memory requirement. The next thrEe examples show three different methods for converting a macro call into a subroutine call. The first time the SBMAC macro is called. it generates a full in-line substitution which defines the SUBR subroutine. Each subsequ;nt call to the SBMAC macro generates only a CALL instruction to the SUBR subroutine. Within the fo.lowing examples. notice that the label SUBR must be global so that it can be called from outside the first expa 1sion. This IS possible only when that part of the macro definition containing the global label is called only Ollce in the entire program. Method #1:
i~ested

Macro Definitions

Macros can b" redefined during the course of a program. In the following example. the definition of SBMAC contains its own redefinition as a nested macro. The first time SBMAC is called, it is full expanded. and the redefinition of SBMAC replaces the original definition. The second time SBMAC IS called. only its redefinition (a CALL inst"uction) is expanded.

5-18

The j MP DUN instruction simply transfers control past the end of the subroutine. Macros SBMAC SBMAC LINK: SUBR: MACRO MACRO CALL ENDM CALL jMP SUBR SUBR DUN .REDEFINITION OF SBMAC RET DUN: ENDM Notice that both versions of SBMAC contain CALL SUBR instructions. This is necessary to provide a return address at the end of the SUBR routine. Notice that neither code nor data is generated for an ENDM directive. Method #2: Conditional Assembly The second method for altering the expansion of the SBMAC macro uses conditional assembly.Chapter 5. SBMAC is defined as follows: TRUE FALSE FIRST SBMAC EQU EQU SET MACRO CALL SUBR IF SET jMP OFFH 0 TRUE FIRST LINK: SUBR: FIRST FALSE DUN RET DUN: ENDIF ENDM 5-19 . Such a label IS assigned to the next source line for which code or data is generated. This construct is required because the ENDM directive itself may not be given a label. The jump instruction labelled LINK is required to prevent the SUBR subroutine from executing a return to itself. In this example. so the label DUN is assigned to whatever instruction follows the ENDM directive. NOTE The assembler allows the use of a source line consisting only of a label.. a switch (FI RST) is set TRUE just before the first call for SBMAC. Notice that the return address for the second CALL SUBR instruction would be SUBR if the jump instruction were omitted.

which it is aft er the first call to SBMAC. including the call to and definition of SUBR: SBMAC CALL IF JMP LINK: SUBR: SUBR FIRST DUN RET DUN: ENDIF Because FI RS r is TRUE when encountered during the first expansion of SBMAC. the conditionally-assembled code is skipped so that the sUJroutine is not regenerated. but uses the EXIT M directive to Sl ppress unwanted macro expansion after the first call. TRUE FALSE FIRST SBMAC EQU EQU SET MACRO CALL IF EXITM ENDIF SET JMP OFFH 0 TRUE SUBR NOT FIRST FIRST SUBR: FALSE DUN RET DUN: ENDM 5-20 . Macros The first call 0 SBMAC expands the full definition. In subsequent calls.Chapter 5. Only the following expansion is produced: SBMAC CALL IF Method #3: :onditlonal Assembly with EXITM SUBR FIRST The third met hod for altering the expansion of SBMAC also uses conditional assembly. EXITM is effective when FIRST is FALSE. all the statements between IF and ENDI!' are assembled into the program.

a common feature of many high level languages. only the first call to the TJ UMP macro generates the calculated GOTO routine. the variable IS placed in the accumulator. The list of addresses is defined as a series of DW directives starting at the symbolic address TABLE. if the variable has the value 3. allows the program to jump to one of a number of different locations depending on the value of a variable.O E.ADD OFFSET TO TABLE ADDR IN H&L .REDEFINE TJUMP TO SAVE CODE .TABLE TABLE: DW DW DW LOCO LOC1 LOC2 The call sequence shown above causes a lump to LOC2.JUMP TO A-TH ADDR IN TABLE . Therefore. the program jumps to the fourth address In the list.GET TABLE OFFSET INTO D&E . if the variable has the value zero. the program jumps to the first item In the list.NEXT CALL JUMPS TO ABOVE CODE A D. TJUMP TJCODE: MACRO ADD MVI MOV DAD MOV INX MOV XCHG PCHL MACRO JMP ENDM ENDM .M TJUMP TJCODE Notice that the definition of the TJ UMP macro does not account for loading the address of the address table into the Hand L registers. Subsequent calls produce only the jump instruction JMP TJCODE. This macro (T JUMP) also modifies itself with a nested definition.CLEAR DREG .M H D. The following shows the coding for the address table (TABLE) and a typical call sequence for the TJ UMP macro: MVI LXI TJUMP A.MULTIPLY A BY 2 .A D E.Chapter 5.2 H.GET 1ST ADDRESS BYTE . Macros Example 4: Computed GOTO Macro This sample macro presents an implementation of a computed GOTO for the 8080 or 8085. the user must load this address just before calling the TJ UMP macro.GET 2ND ADDRESS BYTE . For example.J UMP TO ADDRESS . The computed GOTO. 5-21 . In this example.

Also. and PTDRVR. the GOTO and TJ UMP macros together causl a jump to the address of the DATE routine. 5-22 . DATE. It hen loads the base address of the table into the Hand L registers and calls the Tj UMP macro. but only one copy of the coding for thl TjUMP is generated since the TJUMP macro redefines itself to generate only a jMP TjCODE instruction. Macros Example 5: Using IRP to Define the Jump Table The TJ UMP macro becomes even more useful when a second macro (GOTOl IS used to define the jump table.PTDRVR> This call to He GOTO macro builds a table of DW directives for the labels COUNT. The GOTO macro is defined as follows: GOTO MACRO LOCAL LDA LXI TJUMP IRP DW ENDM ENDM INDEX.(COUNT. If the value o' the variable CASE is 2 when the GOTO macro is called.SET UP TABLE A typical call to the GOTO macro would be as follows: GOTO CASE.LOAD H&L WITH TABLE ADDRESS . the GOTO macro may be called any number of times. Notice that allY number of addresses may be specified in the list for the GOTO routine as long as they all fit on a single so Jrce line. load the addr"ss of the table Into the Hand L registers.CALL TJUMP MACRO )TABLE: FORMAL.LOAD ACCUM WITH INDEX .Chapter 5.(L1ST> FORMAL . and then call TJ UMP. TIMER.TIMER.L1ST JTABLE INDEX H.DATE.JTABLE .

For example. The branch table itself consists of a list of starting addresses for the routines to be branched to. BRANCH TABLES PSEUDO-SUBROUTINE Suppose a program consists of several separate routines.. ... consider a program that executes one of eight routines depending on which bit of the accumulator is set: Jump to routine 1 if the accumulator holds 2 .. 7" " 8 II II .• it appears just once in memory).6. the branch table program loads the selected routine's starting address into the program counter. 4" If .. One way to code this would be to check each condition sequentially and branch to the routines accordingly as follows: CONDITION = CONDITION ]I IF YES BRANCH TO ROUTINE 1 CONDITION = CONDITION 2? IF YES BRANCH TO ROUTINE 2 BRANCH TO ROUTINE N A sequence as above is inefficient. 3 .. 6-1 . II lJ 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 A program that provides such logic follows. .... 5 .. but is entered via a regular JUMP instruction rather than via a CALL Instruction.. PROGRAMMING TECHNIQUES This chapter describes some techniques that may be of help to the programmer.e . thus effecting a jump to the desired routine. The program is termed a 'pseudo-subroutine' because it IS treated as a subroutine by the programmer (i. any of which may be executed depending upon some initial condition (such as a number passed In a register). and can be improved by using a branch table. Using the Hand L registers as a pointer. . The logic at the beginning of the branch table program loads the starting address of the branch table into the H and L registers. 6 II " .

Chapter 6. Programming Techniques Main Pre gram Branch Table Program Jump Routines I normal subroutine return sequence not followed by branch table program 6-2 .

(H. One way to do this is to place a list of the required data (called a parameter list) in some data area of memory.JUMP TO ROUTINE .BTBL .IN BRANCH TABLE .POINT TO BRANCH TABLE INX INX JMP MOV INX MOV XCHG PCHL GETAD H H GTBIT E. and pass the address of this list to the subroutine in the Hand L registers. TRANSFERRING DATA TO SUBROUTINES A subroutine typically requires data to perform its operations.BIT FOUND .BYTE FIRST The control routine at START uses the Hand L registers as a pointer into the branch table (BTBL) corresponding to the bit of the accumulator that is set. this data may be transferred In one or more registers.EXCHANGE D AND E . and then uses a PCH L Instruction. Sometimes it is more convenient and economical to let the subroutine load its own registers.ADDRESS GETAD: BTBL: DW DW DW DW DW DW DW DW ROUTl ROUT2 ROUTJ ROUT4 ROUTS ROUT6 ROUT7 ROUT8 .BRANCH TABLE.INTO D AND E REGISTERS .Chapter 6. The rdutine at GETAD then transfers the address held In the corresponding branch table entry to the Hand L registers via the D and E registers.M . In the simplest case.POINT TO NEXT ADDRESS .ADDRESS .HELD LEAST SIGNIFICANT . EACH :ENTRY IS A TWO-BYTE .REGISTERS HAND L WILL . Programming Techniques Label Code Operand START: GTBIT: LXI RAR jC H.WITH HAND L .LOAD JUMP ADDRESS .L)=(H. 6-3 .M H D. thus transferring control to the selected routine.L)+2 TO .

INCREMENT MEMORY .ETER LIST .PARAMETER STORE .A .LOAD HAND L WITH .ADDED . It adds the fiJ st and second bytes of the list.ADDRESSES OF THE PARAM.Chapter 6.M H B.RETURN UNCONDITIONALLY The first time ADSUB is called. it loads the A and B registers from PLiST and PLlST+1 respectively.STORE RESU LTAT TH IRD .GET SECOND PARAMETER . and stores the result in the third byte of the list: Label Code LXI Operand H. adds them.ADD FIRST TO SECOND .LOAD HAND L REGISTERS . 6-4 .RESULT WILL BE STORED HERE .M B H M.SECOND NUMBER TO BE . and stores tr e result in PLiST+2.INCREMENT MEMORY .ADDRESS . Return is then made to the instruction at RET1.FOR ANOTHER CALL TO ADSUB 10 35 1 PDSUB: MOV INX MOV ADD INX MOV RET A.PLlST Comment .ADDRESS .FIRST. the subroutine ADSUB expects the address of a three-byte parameter list in the Hand L registers. Programming Techniques For example.GET FIRST PARAMETER .L1ST2 ADSUB .NUMBER TO BE ADDED .CALL THE SUBROUTINE CALL RET1: 'LIST DB DB DS LXI CALL RET2: L1ST2: DB DB DS ADSUB 6 8 1 H.

it reloads the accumulator with the sum held in the C register and returns to the calling routine. and they must be contiguous in memory. however. and leave the sum in the accumulator. it 6-5 . It then loads the address of the first parameter into the D and E registers. Note that the parameter lists PLIST and L1ST2 could appear anywhere in memory without altering the results produced by ADSUB. ADSUB must receive a list of two and only two numbers to be added. Call to GENAD: H L GENAD: D PARMl ADRl ADR2 ADR3 ADR4 FFFF PARM4 PARM3 PARM2 As implemented below. Return is then made to the Instruction at RET2. rather than the parameters themselves. GENAD saves the current sum (beginning with zero) in the C register. and signifying the end of the parameter list be a number whose first byte is FFH (assuming that no parameters will be stored above address FFOOH). This can be done by passing the subroutine a parameter list which is a list of addresses of parameters. Programming Techniques First call to ADSUB: 06 08 OEH PLIST PLlST+l PLlST+2 The second time ADSUB IS called. As coded. located anywhere in memory.Chapter 6. If this address is greater than or equal to FFOOH. the Hand L registers POint to the parameter list L1ST2. The A and B registers are loaded with 10 and 35 respectively. Suppose we wanted a subroutine (GENAD) which would add an arbitrary number of bytes. This approach does have its limitations. Otherwise. and the sum is stored at L1ST2+2.

TO NEXT PARAMETER ADDRESS .LOAD ADDRESS OF .COMPARE TO FFH . The routine then loops b:.M H A.D AND E NOW ADDRESS PARAMETER .PLlST GENAD Comment .A D C H LOOP A.ck to pick up the remaining parameters.A E.Chapter 6.RM1 : PARM4: DB DB 6 16 FARM3: DB 13 FARM2: DB 82 GENAD: LOOP: XRA MOV MOV INX MOV CPI jZ MOV LDAX ADD INX JMP MOV RET END A C.RESTORE TOTAL .TERMINATOR PA.GET LOW ORDER ADDRESS BYTE . Label Code LXI CALL Operand H.LOAD ACCUMULATOR WITH PARAMETER .ROUTINE DONE .GET HIGH ORDER ADDRESS BYTE .SAVE CURRENT TOTAL IN C .ADD PREVIOUS TOTAL .CLEAR ACCUMULATOR .L1ST OF PARAMETER ADDRESSES .M OFFH BACK D.OF FIRST PARAMETER .IF EQUAL. Programming Techniques loads the panmeter into the accumulator and adds the sum in the C register to the accumulator.RETURN TO CALLING ROUTINE BACK: 6-6 .INCREMENT HAND L TO POINT .C . ROUTINE IS COMPLETE .OF FIRST PARAMETER .GET NEXT PARAMETER .PARAMETER ADDRESS LIST PLlST: HALT DW DW DW DW DW PARM1 PARM2 PARM3 PARM4 OFFFFH .

it is 0. it is 0. add the multiplicand to the most significant byte of the result. Shifting a byte left one bit is equivalent to multiplying by 2. so add 2AH to high-order byte of result and shift 16-bit result right one bit. a calling program can pass the total number of parameters as the first parameter. if it IS necessary to allow parameters to be stored at any address. For example. no matter where in memory they might be located (excluding addresses above FFOOH). and shifting a byte right one bit IS equivalent to dividing by 2. Programmmg Techniques Note that GENAD could add any combination of the parameters with no change to the parameters themselves. If zero. For example. The sequence: LXI CALL H.PLlST GENAD PUST: DW DW DW PARM4 PARMl OFFFFH would cause PARMl and PARM4 to be added. 6-7 . The following process will produce the correct 2-byte result of multiplying a one byte multiplicand by a one byte multiplier: A. but slowest. Shift the entire two-byte result right one bit position. so shift 16-bit result right one bit. Repeat steps a and b until all 8 bits of the multiplier have been tested. Test the least significant bit of multiplier. Test multiplier 2-blt. If one. Repetitive addition provides the simplest. go to step b. or use of a register shifting operation. B. 2AH*74H may be generated by adding 74H to the (initially zeroed) accumulator 2AH times. the subroutine then loads this first parameter into a register and uses It as a counter to determine when all parameters had been accepted. it is 1. SOFTWARE MULTIPLY AND DIVIDE The multiplication of two unsigned 8-bit data bytes may be accomplished by one of two techniques: repetitive addition. Shift operations provide faster multiplication. C. form of multiplication. For example. consider the multiplication: 2AH*3CH=9D8H Step 1: Step 2: Step 3: Test multiplier O-bit. Many variations of parameter passing are possible.Chapter 6. so shift 16-bit result right one bit. Test multiplier l-bit.

. ". The result produced is 09D8.0 . so add 2AH to high-order byte of result and shift 16-bit result right one bit. b MULTIPLIER 00111100(3C) MULTIPLICAND 00101010(2A) HIGH-ORDER BYTE OF RESULT 00000000 00000000 00000000 00101010 00010101 00111111 00011111 01001001 00100100 01001110 00100111 00010011 LOW-0RDER BYTE OF RESULT 00000000 00000000 00000000 00000000 00000000 00000000 10000000 10000000 11000000 11000000 01100000 10110000 11 011 000(9D8) '>. The prograrr uses the B register to hold the most significant byte of the result.. it is 1. it is 0. .• ' · · · . . """" . b Step 7 a . b Step 8 a . b Step 4 a . a sample program IS g ven with comments. Programming Techniques Step 4: Test multiplier 3-bit. . "" . so add 2AH to high-order byte of result and shift 16-bit result right one bit.....Chapter 6.•. .. " . . so shift 16-bit result right one bit. . '" 0 . . Test multiplier 4-bit. Step 5: Step 6: Test multiplier 5-bit. . Test multiplier 6-bit. so add 2AH to high-order byte of result and shift 16-bit result right one bit. b Step 5 a b Step 6 a .. •• . it is 1. so shift 16-bit result right one bit.Lnt byte of the result.. and the C register to hold the least signific. it is 0... it is 1. 00001001 Since the mliitiplication routine described above uses a number of important programming techniques. ' . Step 7: Step 8: Start Step 1 a b Step 2 a b Step 3 a ... The 16-bit right shift of the result is performed in the accumulator by two rotate-right-! hrough -carry instructions. Test multiplier 7-bit. ." . 6-8 .

EXIT IF COMPLETE Register D holds the multiplicand.MULTIPLIER TO CARRY AND SHIFT .WAS A ONE .BIT COUNTER .A E DONE A.LOW-ORDER BYTE OF RESULT .INITIALIZE MOST SIGNIFICANT BYTE .ADD MULTIPLICAND TO HIGH. the process involves subtraction rather than addition. and register C originally holds the multiplier.ORDER BYTE OF RESULT DONE: An analogous procedure is used to divide an unsigned 16-bit number by an unsigned 16-bit number.ORDER BYTE OF RESULT IF BIT .Chapter 6.O E.CARRY=O HERE SHIFT HIGH.C C. Programming Techniques Zero carry and then rotate B: B C I ~~0 [_ _ _I Then rotate C to complete the shift: D C B D MULT: MVI MVI MOV RAR MOV DCR JZ MOV JNC ADD B.OF RESULT . Here.9 A. 6-9 .B MULT1 D MULTO: 'I~b .ROTATE LEAST SIGNIFICANT BIT OF . and rotate-left instructions instead of rotate-right instructions. MULT1: RAR MOV JMP BA MULTO .

SUBTRACT DIVISOR (ADD NEGATIVE) :UNDER FLOW.A A.A D H. DIV: MOV CMA MOV MOV CMA MOV INX LXI MVI PUSH DAD JNC XTHL POP PUSH MOV RAL MOV MOV RAL MOV MOV RAL MOV MOV RAL MOV POP DCR JNZ A.D D.INITIALIZE LOOP COUNTER . and the D and E register to held the divisor and remainder.CY->C->B->L->H :RESTORE LOOP COUNTER (A) .DECREMENT IT :KEEP LOOPING .POST·DIVIDE CLEAN UP :SHIFT REMAINDER RIGHT AND RETURN IN DE ORA MOV RAR MOV MOV RAR MOV RET END A A.C C.E E.A PSW A DVO :NEGATE THE DIVISOR DVO: :FOR TWO'S COMPLEMENT .H H. The Hand L registers are used to store data temporarily. Programming Techniques The followin: reentrant program uses the Band C registers to hold the dividend and quotient.A 6·10 .Chapter 6.A A.A A.4 REGISTER LEFT SHIFT .SAVE REMAINDER .A A.IN ITIAL VALUE FOR REMAINDER .H D.B BA A.17 H D DVl H PSW A.L L. RESTORE HL DV1: :SAVE LOOP COUNTER (A) .O A.WITH CARRY .L E.

J 6A ~ 8A 90 i carry = 1 . Programming Techniques MULTI BYTE ADDITION AND SUBTRACTION The carry flag and the ADC (add with carry) instructions may be used to add unsigned data quantities of arbitrary length. 3). Consider the following addition of two three-byte unsigned hexadecimal numbers: 32AF8A +84BA90 B76A1A To perform this addition. J 1A The following routine will perform this multibyte addition. +-+-liI>- lA 6A B7 ~ carry --t ~ carry SECND SECND+l SECND+2 90 BA 84 90 BA 84 6-11 . but does not Include the carry flag in the addition. Then use ADC to add to all higher order bytes. The numbers to be added are stored from low-order byte to high-order byte beginning at memory locations FI RST and SECND. The result will be stored from low-order byte to high-order byte beginning at memory location FIRST.. replacing the original contents of these locations. ADD sets the carry flag for use in subsequent instructions.Chapter 6. 84 3n B7 BA I carry = 1 . MEMORY LOCATION FIRST FIRST+l FIRSTt2 before 8A AF 32 after --+ .. respectively. making these assumptions: The E register holds the length of each number to be added (in this case. add to the low-order byte uSing an ADD instruction..

Chapter 6. bytes FIRST through FIRST+2 will contain 1A6AB7. changing the ADC instruction to an SBB instruction. the addition with carry will proceed cornctly. placing the result at FIRST.CLEAR CARRY FLAG . When locaticn DONE is reached.ADD BYTE OF SECND . This could cause the result to be high by one if the carry flag were left set by some previous instruction.H AND L ADDRESS SECND . it is necessary only to duplicate the multibyte addition routine of this sectic n. The program will then subtract the number beginning at SECND from the number beginning at FIRST. 6-12 .SECND . In order to (reate a multibyte subtraction routine. Programming Techniques The followin: routine uses an ADC instruction to add the low-order bytes of the operands.B AND C ADDRESS FIRST . DECIMAL ADDIlION Any 4-bit d.POINT TO NEXT BYTE OF .DONE IF E = 0 .POINT TO NEXT BYTE OF . Label I~ADD: Code Operand Comment LOOP: LXI LXI XRA LDAX ADC STAX DCR B.FIRST H.WITH CARRY .ADD NEXT TWO BYTES JZ INX INX JMP DONE: FIRST DB DB DB DB DB DB ~ECND: 90H OBAH 84H 8AH OAFH 32H Since none cf the instructions in the program loop affect the carry flag except ADC.SECND A B M B E DONE B H LOOP . In order to preserve this decimal interpretation when performing addition. the value 6 must be added to the 4-bit quantily whenever the addition produces a result between 10 and 15.FIRST . and does not contain any of the bit patterns representing the hexadecimal digits A through F. which is the sum shown at the beginldng of this section arranged from low-order to high-order byte. This is because each 4-bit data quantity car hold 6 more combinations of bits than there are decimal digits.STORE RESULT AT FIRST . ta quantity may be treated as a decimal number as long as it represents one of the decimal digits from 0 throllgh 9. This routine avoids the problem Jy clearing the carry flag with the XRA instruction just before LOOP.LOAD BYTE OF FIRST .

Chapter 6. a 6 is added to these bits. Clear the Carry and add the two lowest-order digits of each number (remember that each 2 decimal digits are represented by one byte). This is because you need the carry flag setting from the DAA instruction for adding the higher-order bytes. you must perform the decimal adiust before adding the next higher-order bytes. 85 = 10000101 B 36 = 00110110B 0 Q]10111011B carry Carry = 0 ~ ~ Auxiliary Carry = 0 The accumulator now contains OBBH. Accumulator = 10111011 B 6 = 0110B 11000001 B Since the leftmost bits are greater than 9. Since the rightmost four bits are greater than 9. and the DAA (decimal adiust accumulator) instruction is then used to convert the 8-bit binary result to the correct representation of 2 decimal digits. 6-13 . To perform the decimal addition: 2985 +4936 7921 the process works as follows: 1. a 6 is added to the accumulator. Perform a DAA operation. 2. The bytes are summed In the accumulator in standard fashion. thus setting the carry flag_ Accumulator = 11000001 B 6=0110 B /]00100001B Carry flag = 1 The accumulator now contains 21 H. Store these two digits. For multibyte strings. Programming Techniques Decimal addition is performed by letting each 8-bit byte represent two 4-bit decimal digits.

Then. we get 22. to subtract 34 from 56. IS exactly analogous to the multibyte addition routine MADD of the last sect on. Thus.Q] 0111 0011 B ~AuXiliary Carry = 1 The accumulator now contains 73H. DECIMAL SUBTltACTION DeCimal subtraction is considerably more complicated than decimal addition. This inverted carry flag setting :an be used in an add operation to form either the nines or tens complement of the subtrahend. the correct decimal result 7921 IS generated in two bytes. Since the auxiliary carry flag is set.. and may be produced by Inserting the instruction DAA after the ADC M instruction of that example. Each iteration of the program loop will add two decimal digits (one byte) of the numbers. use the nines complement of the subtrahend. By truncating eff the carry out of the high order digit. In general. For example. and then adding the result to the minuend digit. the correct result. Notice that the meaning of the carry flag IS Inverted because you are dealing with complemented data. When no borrow occurs from a subtract. If a borrow does occur. you want t. you v'ant to use the tens complement of the subtrahend for the next operation. a one bit in tle carry flag Indicates no borrow: a zero bit In the carry flag indicates a borrow. 6 is added to the accumulator. form the tens complement of 34 (99-34=65+1=66). The problerl of handling borrows arises in multibyte deCimal subtractions. A routine wlich adds decimal numbers. 56+66=122. then. the process consists of generating tle tens complement of the subtrahend digit. Programming Techniques 3. no further action occurs. Thus. 6-14 . Perform a DAA operation.Chapter 6. Accumulator = 01110011 B 6 = 0110B /QlOl111001B Carry flag = 0 Since the leftmost 4 bits are less than 10 and the carry flag is reset. Add the next group of two digits: 29 = 001 01 001 B 49 = 01001001B carry Carry = 0 ~ .

Programming Techniques The detailed procedure for subtracting multi-digit decimal numbers is as follows: 1. 3. 5. Accumulator 62 = 100110108 = 1001111 08 ] 001110008 6-15 . 6. Set carry = 1 . producing either 99H or 9AH. Use the DAA instruction to make sure the result In the accumulator is In decimal format. and resetting the carry flag. and to indicate a borrow in the carry flag if one occurred. Load accumulator with 99H. producing 9AH. representing the number 99 decimal. Subtract the subtrahend digits 62 from the accumulator. Load the accumulator with 99H. go to step 2. Subtract the subtrahend digits from the accumulator. Add the minuend digits to the accumulator.Chapter 6. 2. Otherwise. 7. 3. stop. producing either the nines or tens complement. Example: Perform the decimal subtraction: 43580 -13620 29960 1. Set the carry flag = 1 to indicate no borrow. If there are more digits to subtract. 2. Add zero with carry to the accumulator. Add zero to the accumulator with carry. = 9AH 4. Accumulator = 100110018 = 000000008 Carry 100110108 4.

~ Q] 1001 OOOOB = 90H 'AUXiliarY Carry = 1 DAA converts accumulator to 96 (since Auxiliary Carry Indicating that a borrow occurred. Add the minuend digits 58 to the accumulator. 6-16 . Accumulator = 10011 001 B 13= 11101101B 1] 10000110B 10. leaving accumulator = 99H. subroutine will subtract one 16-digit decimal number from another using the following assumptions: The minuend IS stored least significant (2) digits first beginning at location MINU. Programming -rechniques 5. 9. The result will be stored least significant (2) digits first. Add zero with carry to accumulator. Accumulator = 1000011 OB 43 = 01000011 B ~~ 11001001B = C9H Carry = 0 11 'AUXiliary Carry = 0 DAA converts accumulator to 29 and sets the carry flag = 1. = 1) and leaves carry flag =0 7 8. indicating no borrow occurred. replacing the minuend. Load accumulator with 99H. Therefore. the result of subtracting 1362 from 4358 is 2996. Subtract the subtrahend digits 13 from the accumulator. The followinl.Chapter 6. The subtrahe ld IS stored least significant (2) digits first beginning at location SBTRA. Add the minuend digits 43 to the accumulator. Accumulator = 00111 OOOB 58 = 01011 OOOB Carry = 0 6.

OF SUBTRAHEND .H AND L .OF MINUEND .EACH LOOP SUBTRACTS 2 .DONE IF C = 0 .SET CARRY INDICATING .RESWITCH D AND E .STORE RESULT .99H 0 M M.NO BORROW . .GET NEXT 2 DECIMAL DIGiTS STC LOOP: MVI ACI SUB XCHG ADD DAA MOV XCHG DCR JZ INX INX JMP NOP C DONE D H LOOP M A. .A DONE: 6-17 .WITH HAND L .WITH 99H.PRODUCE COMPLEMENT . Programming Techniques Label DSUB: Code LXI LXI MVI Operand D.ADD ZERO WITH CARRY .SBTRA C.DIGITS (ONE BYTE).ADDRESS NEXT BYTE .8 Comment .SWITCH D AND E WITH .ADDRESS NEXT BYTE . .ACCUMULATOR .MINU H.HEND .THEREFORE PROGRAM WILL .H AND L ADDRESS SUBTRA.SUBTRACT 16 DIGITS.DECIMAL ADJUST .OF SUBTRAHEND .Chapter 6.ADD MINUEND .D AND E ADDRESS MINUEND .LOAD ACCUMULATOR .

.

and RST instructions in Chapter 3. This method is referred to as programmed Input/Output. events occur external to the central processing unit which require immediate action by the CPU. waits until the next character is ready (e. the 8085 processor has some additional hardware features for interrupt handling. one at a time. executes a timeout by incrementing a sufficiently large counter).. The device controller could interrupt the CPU when a character is ready to be input. There are two ways to handle such a situation: A. forcing a branch from the executing program to a special interrupt service routine. Often. SIM. The interrupt sequence may be illustrated as follows: INTERRUPT Normal Program Execution Program Execution Continues Interrupt Service Routine 7-1 . suppose a device is sending a string of 80 characters to the CPU. B. For example.7. A program could be written which accepts the first character. see the description of the 8085 processor in Chapter 1 and the descriptions of the RIM. and proceeds in this fashion until the entire 80 character string has been received.g. INTERRUPTS INTERRUPT CONCEPTS The following is a general description of interrupt handling and applies to both the 8080 and 8085 processors. at fixed intervals. then accepts the next character. However. For more information on these features.

INTE. and the programmer has no control over it. the following actions occur: 1. The interrupt enable bit. since it is a function of the interrupting device's controller design.• 0008 OOOF I J Beginning of subroutine for device 'b' 7-2 . Then the subroutine which processes data transmitted from the deVice to the CPU will be called into execution via an eight-byte instruction sequence at memory locations OOOOH to 0007H. The interrupting device supplies. For instance. is reset = O. :epvpi~i::a~ST OH Device supplie. 3. When the 8010 recognizes an interrupt request from an external device. This instruction does not appear anywhere in memory. RST 1 H d " d Transfers c_o_n_t_ro_l_t_o . since this is an efficienl one byte call to one of 8 eight-byte subroutines located in the first 64 words of memory. The program counter is not incremented before this instruction. Wilenever INTE is equal to 0. A digital inplt device may supply the instruction: RST 1H Then the sub'outine that processes the digital input signals will be called via a sequence of instructions occupying m"mory locations 0008H to OOOFH. via hardware. 2. ut interrupt. The Instruction supplied by the interrupting device is normally an RST instruction (see Chapter 3). The instruction currently being executed is completed. the jevice may supply the instruction: RST OH with each in. the entire interrupt handling system is disabled. Interrupts The 8080 cor tains a bit named INTE which may be set or reset by the instructions EI and DI described in Chapter 3.~ 0000 0007 } Beginning of subroutine for device 'a' T_ra_n_s_fe_r_s control to . one instruction which the CPU executes. and no interrupts will be accepl ed.Chapter 7.

"p<f.) When the RETURN is executed. causing execution to continue at this point.Chapter 7. Control transferred to to 0000 0000 '0"'". Since this is a call to location zero. The program counter remains set to 3COC.'ce . address 3COC is popped off the stack and replaces the contents of the program counter.o".om D. 3COC is pushed onto the stack and program control is transferred to location OOOOH. The following is an example of an Interrupt sequence: ARBITRARY MEMOR Y ADDRESS 3COB INSTRUCTION I ~3COC ~~~ ~'1~{. if necessary. or any other operation. I . (This subroutine may perform jumps.j Device 1 supplies RST OH Program Counter = 3COC pushed onto A B the stack. 7-3 . calls.'. Interrupts Device 'x' supplies RST 7H Transfers control to 0038 003F } Beginning of subroutine for device 'x' Note that any of these 8-byte subroutines may in turn call longer subroutines to process the interrupt.00 .. This instruction is completed. / Instruction 2 RET t Stack popped into program counter C Device 1 signals an interrupt as the CPU is executing the instruction at 3COB. Any device may supply an RST instruction (and indeed may supply anyone-byte 8080 instruction). and the instruction RST OH supplied by device 1 is executed..

) Further. For example. If the interrupt subroutine happens to reset the carry bit before returning to the Interrupted pngram. causing the interrupted program to produce err Jneous results. One instruction after an EI is executed. or errors will occur. correct progra n execution will continue automatically. the II terrupt enable system is automatically disabled whenever an Interrupt is acknowledged.RETURN TO INTERRUPTED PROGRAM 74 .RESTORE MACHINE STATUS .Chapter 7. Except in special cases. then.SAVE CONDITION BITS AND ACCUMULATOR . the jump to LOC which should have occurred will not. any interrupt subroutine should save at least the condition bits and restore them before perfornling a RETURN operation. an interrupt subroutine should include an EI instruction somewhere to permit detection and handling (of future interrupts. the interrupt subroutine may itself be Interrupted. anI registers or condition bits changed by an Interrupt subroutine must be restored before returning to the interrurted program.PERFORM NECESSARY ACTIONS TO SERVICE . u. A typical intel rupt subroutine. uppose a program is interrupted lust prior to the instruction: JC LOC and the carry Jlt equals 1. Like any othe subroutine then. but as long as all pertinent data are saved and restored.THE INTERRUPT POP PSW RET . . T lis process may continue to any level.RE-ENABLE INTERRUPTS . could appear as follows: Code Operand Comment PUSH EI PSW . 1herefore. (The obVIOUS and most convenient way to do this IS to save the data In the stack.lng PUSH and POP operations. Interrupts WRITING INTERRJPT SUBROUTINES In general.

INSTRUCTION SUMMARY This appendix summarizes the bit patterns and number of time states associated with every 8080 CPU instruction. note the following symbology DDD represents a destination register. When USing this summary. 7976. and the larger number of time periods is required if the condition IS met. 7977 INTEL CORPORATION A-l .APPENDIX A. 7975. A time period may vary from 480 nanoseconds to 2 microseconds on the 8080 or 320 nanoseconds to 2 microseconds on the 8085. Both DDD and SSS are interpreted as follows: DDD or SSS 000 001 010 011 100 101 110 111 Interpretation Register Register Register Register Register Register B C D E H L A memory register or stack pointer or PSW (flags + accumulator) The accumulator Instruction execution time equals number of time periods multiplied by the duration of a time period. Where two numbers of time periods are shown (eq. The instructions are listed in both mnemonic (alphabetical) and operation code (numerical) sequence. NUMBER OF TIME PERIODS MNEMONIC D7 D6 D5 D4 D3 D2 D1 DO 8080 8085 CALL CC CNC CZ CNZ CP CM CPE CPO RET RC RNC RZ I 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 I 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 17 11/17 11/17 11/17 11/17 11/17 11/17 11/17 11/17 10 5/11 5/11 5/11 18 9/18 9/18 9/18 9/18 9/18 9/18 9/17 9/18 I ! 1 1 1 1 10 6/12 6/12 6/12 ALL MNEMONICS©7974. it means that the smaller number of time periods is required if a condition is not met. SSS represents a source register.5/11).

7976. Instruction 5ummary NUMBER OF TIME PERIODS MNEMONIC D7 D6 D5 D4 D3 D2 D1 DO 8080 8085 RNZ RP RM RPE RPO RST IN OUT LXI B LXI D LXI H LXI SP PUSH B PUSH D PUSH H PUSH PSW POP B POP D POP H POP PSW STA LDA XCHG XTHL SPHL PCHL DAD B DAD D DAD H DAD SP STAX B STAX D LDAX B LDAX D INX B INX D INX H INX SP MOV r1/2 MOV M.Appendix A.r MOV r. 7977/NTEL CORPORATION I 0 1 A-2 .7975.M HLT MVI r MVI M INR DCR 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 A 0 0 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 I 0 0 0 0 0 0 1 1 D 1 D 1 D 1 D D 0 1 1 0 0 A 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 1 0 A 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 S S 0 0 0 0 5/11 I 5/11 5/11 5/11 5/11 11 10 10 10 10 10 10 11 11 6/12 6/12 6/12 6/12 6/12 12 10 10 10 10 10 10 12 12 12 12 10 10 10 10 I 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 S S 1 1 1 1 1 1 11 11 10 10 10 10 I 0 1 1 0 1 1 1 1 1 1 13 13 4 18 5 5 10 10 10 10 7 13 13 4 16 6 6 10 10 10 10 7 0 1 0 1 0 1 0 1 D 0 0 1 1 1 1 7 7 7 7 1 1 1 1 7 5 5 5 5 5 7 6 6 6 6 4 0 0 0 0 D 0 D 0 1 1 S S 1 1 D 1 D 1 D D 7 7 7 7 10 5 5 7 7 5 7 10 4 4 1 1 1 D 0 D D 0 0 0 0 ALL MNEMON/CS© 1974.

7975. 7976.Appendix A. 7977 INTEL CORPORATION . Instruction Summary NUMBER OF TIME PERIODS MNEMONIC D7 D 6 D5 D4 D3 D2 D1 DO 8080 8085 INR A DCR A INR M DCR M ADD r ADC r SUB r SBB r .AND r XRA r ORA r CMPr ADD M ADC M SUB M 5BB M AND M XRA M ORA M CMP M ADI ACI SUI 5BI ANI XRI ORI CPI RLC RRC RAL RAR JMP JC JNC JZ JNZ JP JM JPE JPO DCX B DCX D DCX H DCX 5P 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 5 5 0 0 0 0 5 5 5 5 i 0 1 0 1 5 5 5 10 10 4 4 4 4 4 4 4 4 4 4 10 10 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 I 5 5 5 5 1 5 5 5 5 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 I 1 1 1 1 1 1 1 1 1 1 1 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 7 7 4 4 4 4 10 10 10 10 10 10 10 10 10 5 5 5 5 7 7 7 7 4 4 4 4 10 7{10 7{10 7{10 7{10 7/10 7/10 7/10 7{10 6 6 6 6 A-3 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 ALL MNEMONICS©7974.

Appendix A. Instruction S!lmmary

NUMBER OF TIME PERIODS MNEMONIC D7 D 6 D

s

D

4

D

3

°2

°1

DO
8080 8085

CMA STC CMC OAA SHLD LHLD RIM SIM EI DI NOP

I

0 0 0 0 0 0 0 0 1 1 0

0 0 0 0 0 0 0 0 1 1 0

1 1 1 1 1 1 1 1 1 1 0

0 1 1 0 0 0 0 1 1 1 0

1 0 1 0 0 1 0 0 1 0 0

1 1 1 1 0 0 0 0 0 0 0

1 1 1 1 1 1 0 0 1 1 0

1 1 1 1 0 0 0 0 1 1 0

4 4 4 4 16 16 4 4 4

4 4 4 4 16 16 4 4 4 4 4

ALL MNEMONICS ©7~ 74, 7975, 7976. 7977 INTEL CORPORA nON

A4

Appendix A. Instruction Summary

The following is a summary of the instruction set:

8080/85 CPU INSTRUCTIONS IN OPERATION CODE SEQUENCE
OP CODE MNEMONIC 00 01 02 03 04 05 06 07 08 09 OA OB OC OD OE OF 10 11 12 13 14 15 16
17

OP OP CODE MNEMONIC CODE MNEMONIC 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 DCX INR DCR MYI CMA SIM LXI STA INX INR DCR MVI STC
--

OP OP OP CODE MNEMONIC CODE MNEMONIC CODE MNEMONIC 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 8G 91
92

NOP LXI STAX INX INR DCR MYI RLC
-

H
L

B.D16 B B B B B,D8

L L,D8

DAD B LDAXB DCX B INR C DCR C MYI C.08 RRC
--

SPD16 Adr SP M M M,D8

LXI STAX INX INR DCR MYI RAL
--

D,D16 D D D D D,D8

18 19 1A 1B 1C
10

1E 1F 20 21 22 23 24 25 26 27 28 29 2A

DAD D LDAXD DCX D INR E DRC E MYI E.D8 RAR RIM LXI H.D16 SHLD Adr INX H INR H DCR H MYI H,D8 DAA

-DAD H LHLD Adr

DAD SP LDA Adr DCX SP INR A DCR A MYI A,D8 CMC MOY B.B MOV B,C MOY B.D MOV B,E MOV B.H MOV B,L MOY B,M MOY B,A MOY C,B MOY C,C MOY C.D MOY C,E MOV C,H MOY C.L MOV C,M MOV C.A MOV D.B MOV D.C MOY D,D MOY D.E MOY D,H MOY D.L

56 57 58 59 SA 5B 5C 5D 5E SF 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71
72 73

74 75 76
77

78 79 7A 7B 7C 7D 7E 7F 80

MOY MOY MOY MOY MOY MOY MOY MOY MOY MOY MOY MOV MOV MOV MOY MOY MOY MOV MOV MOY MOY MOY MOY MOV MOV MOV MOV MOV MOY MOV MOV MOV HLT MOY MOV MOY MOY MOV MOV MOV MOY MOY ADD

D,M D,A E.B E.C E,D E,E E,H E.L E,M E,A H,B H,C H,D H,E H,H H,L H,M H,A L,B L.C L,D L,E L,H L,L L,M L,A M.B M,C M,D M.E M.H M.L M,A A,B A.C A.D A.E A,H A.L A.M A,A B

93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F AO A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB
016

ADD ADD ADD ADD ADD ADD ADD ADC ADC ADC ADC ADC ADC ADC ADC SUB SUB SUB SUB SUB SUB SUB SUB SBB SBB SBB SBB SBB SBB SBB SBB ANA ANA ANA ANA ANA ANA ANA ANA XRA XRA XRA XRA

C D E H L M A B C D E H L M A B C D E H L M A B C D E H L M A B C D E H L M A B C D E

AC AD AE AF BO B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF CO C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF DO D1 D2 D3 D4 D5 D6

XRA XRA XRA XRA ORA ORA ORA ORA ORA ORA ORA ORA CMP CMP CMP CMP CMP CMP CMP CMP RNZ POP jNZ IMP CNZ PUSH ADI RST RZ RET jZ

H

L M A B C D E H L M A B C D E H L M A B Adr Adr Adr B D8 0 Adr

-CZ Adr CALL Adr ACI D8 RST 1 RNC POP D INC Adr OUT D8 CNC Adr PUSH D SUI D8

D7 D8 D9 DA DB DC DD DE DF EO E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF FO F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF

RST 2 RC
-

JC IN CC

Adr D8 Adr

SBI D8 RST 3 RPO POP H jPO Adr XTHL CPO Adr PUSH H ANI D8 RST 4 RPE PCHL IPE Adr XCHG CPE Adr

-XRI RST RP POP JP DI CP PUSH ORI RST RM SPHL jM EI CM
--

D8 5 PSW Adr Adr PSW D8 6

Adr Adr

CPI D8 RST 7

08 = constant. or logical/arithmetic expressIOn that evaluates

constant. or logical/arithmetic expression that evaluates

Adr

~

to an 8 bit data quantity. 16-bit address

to a 16 bit data quantity

ALL MNEMONICS © 1974, 7975, 1976, 7977 INTEL CORPORA TfON

A-5

Appendix A. Instruction :;ummary

Instruction Sct Guidc Thc following IS
I

slIl11l11dry of thc IIlstrllclion sct: ADI ACI SUI SBI ANI XRI ORI CPI

,ADD ,A DC SUB S3B ,ANA >RA eRA CMP

REGM S

DS

RLC RAL RRC RAR CMA DAA INR} DCR REGM 8 rlCCUMULATORI MOV REGM 8 ,REGM S[ B FLAGS C

I

ISTC CMC INXi 1DCXJ REG 16

HIGH STACK
I

LOW POINTER RST

I

[

LXI REG 16 ,D 16 [

DIE H L

~ XCHG
IC
jZ jP

,-------jMP
jNCi jNZ

CALL CC CZ 16 CP A CPE CNCl CNZ A CM > 16 CPO

RET RC RZ RP RPE RNCl RNZ RM RPO

jM

JPE jPO
~-"

J
I

I

J

J

LHLDi STHDj A16 MEMORY INPUT PORTS

OUT P8 OUTPUT PORTS

LDAX\ BC DE STAX) ,

CONTROL INSTRUCTIONS RST NOP HLT EI DI SIMI RIM]

LDA~
STA) MVI MOV A16 D8
REGM8,REGI~8

--------STACK
MEANING

I-E-'--

PUSH POP

I j

B,D,H,PSW

8085 ONLY

CODE

REGM 8

The operand l11ay specify one of the 8-bit registers A,B,C,D,E,H, or L or M (a l11el11ol-y reference via the 16-bit address 111 the Hand L registers). The MOV instruction, which calls for two operands, can specify M for only one of Its operands_ Designates 8·bit Il11mediatc operand. Designates a 16·bit address. Designates an 8·bit port number. Designates a -16·bit register pair (B&C,D&E,H&L,or SP). Designates a 16 -bit immediate operand.

ALL MNEMONICS © 1:174, 1975, 7976, 1977 INTEL CORPORA nON

A-6

APPENDIX B. ASSEMBLER DIRECTIVE SUMMARY
Assembler directives are summarIZed alphabetically the contents of directive fields.
In

this appendix. The following terms are used to describe

NOTATION
Term
Expression

Interpretation
Numerical expression evaluated during assembly: must evaluate to 8 or 16 bits depending on directive issued. Series of symbolic values or expreSSions, separated by commas. Symbol name terminated by a space. Field must be empty or an error results. Optional label; must be terminated by a colon. Dummy parameters are symbols holding the place of actual parameters (symbolic values or expressIOns) specified elsewhere in the program. Series of any ASCII characters, surrounded by single quote marks. Single quote within string is shown as two consecutive single quotes. Series of ASCII characters.

List Name Null Oplab Parameter

String

Text

Macro definitions and calls allow the use of the special characters listed below.

Character
&

Function
Ampersand. Used to concatenate symbols. Angle brackets. Used to delimit text, such as lists, that contain other delimiters. Double semicolon. Used before a comment in a macro definition to prevent inclusion of the comment in each macro expansion. Exclamation point (escape character). Placed before a delimiter to be passed as a literal in an actual parameter. To pass a literal exclamation point, issue'!!.'

%

Percent sign. Precedes actual parameters to be evaluated immediately when the macro is called.

ALL MNEMONICS © 7974, 7975, 7976, 7977 INTEL CORPORA nON
8-1

<lisO Terminate macro definition. 7976.) Terminate assembler pass. Set location counter to 'expression. (See IF. (See ENDM. Define 16·blt data word(s).) Repeat instruction sequence. Jpcode )8 oplab: oplab: )S expression exp(sl or string(s) )W oplab: "LSE null oplab: "ND expression oplab: name "NDIF null expression "QU oplab: iF expression Assemble code between IF and following ELSE or ENDIF directive if 'exp' is true. Reserve data storage area of specified length.ECTIVES FORMAT Label oplab: FUNCTION Operand(s) exp(sl or string(sl Define 8-bit data byte(s). oplab: name )RG . Conditional assembly.' if present.' Symbol is not redefi nab Ie. 7975. Opcode I:NDM l:XITM IRP ALL MNEMONICS©7974. Terminate conditional assembly block.' Symbol can be redefined. Expressions must evaluate to one byte. Alternate terminator of macro definition. Assembler 0 :rective Summary SUMMARY OF DI~. at location O.' Define symbol 'name' with value 'expression.Appendix B. Strings limited to 1-2 characters. Code between ELSE and ENDIF directives is assembled if expression in IF clause is FALSE. Must be last statement of program. otherWise. Define symbol 'name' with value 'exp. Program execution starts at 'exp. substituting one character form 'list' for 'dummy param' in each iteration.ET expression expression MACRO DIRECTIV::S FORMAT Label null oplab: oplab: FUNCTION Operand(s) null null dummy param. 7977 INTEL CORPORATION 8-2 .

Assemble subsequent instructions and data in the relocatable mode using the data location counter. Repeat REPT block 'expression' times. null LOCAL label name(s) name MACRO dummy param(s) oplab: REPT expression RELOCATION DIRECTIVES FORMAT Label oplab: Opcode ASEG Operand(s) null FUNCTION Assemble subsequent instructions and data in the absol ute mode. Define macro 'name' and dummy parameter(s) to be used in macro definition. Assembler Directive Summary FORMAT Label oplab: Opcode IRPC Operand(s) dummy param.Appendix B. 7975. 7977 INTEL CORPORA TlON B-3 . oplab: DSEG boundary specification oplab: EXTRN name(s) oplab: oplab: NAME PUBLIC module-name name(s) oplab: STKLN expression ALL MNEMONICS©7974. Specify label(s) in macro definition to have local scope. Identify symbols defined in this module that are to be available to other modules. Identify symbols used in this program module but defined in a different module. ASSigns a name to the program module. 7976. substituting one character from 'text' for 'dummy param' in each iteration. oplab: CSEG boundary specification Assemble subsequent instructions and data In the relocatable mode using the code location counter. Specify the number of bytes to be reserved for the stack for this module.text FUNCTION Repeat instruction sequence.

.

ASCII CHARACTER SET ASCII CODES The 8080 and 8085 usc the seven-bit ASCII code.APPENDIX C. GRAPHIC OR CONTROL ASCII (HEXADECIMAL) GRAPHIC OR CONTROL + ASCII (HEXADECIMAL) GRAPHIC OR CONTROL V ASCII (HEXADECIMAL) NUL SOH STX ETX EaT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DCl (X-ON) DC2 (TAPE) DC3 (X-OFF) DC4 (+Afl8 NAK SYN ETB CAN EM SUB ESC FS GS RS US SP 00 01 02 03 04 05 06 07 08 09 OA OB OC OD OE OF 10 11 12 13 14 15 16 17 I 0 1 2 3 4 5 6 7 8 9 < > @ 18 19 lA lB lC 10 A B C D E F G H I J # $ % & lE IF 20 21 22 23 24 25 26 27 28 29 2A K L M N a P Q R S T U 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 W X Y Z [ \ 1 i\ (t) (+-) . a b c d e f 9 h I J k I m n 0 P q r 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 I s t u v w x 73 74 75 76 77 v z \ I I . (ALT MODE) I ~ 78 79 7A 7B 7C 7D 7E DEL (RUB OUT) 7F C-1 . with the high-order eighth bit (parity bitl always reset. .

.

D-l .APPENDIX D. BINARY -DECIMAL-HEXADECIMAL CONVERSION TABLES.

Appendix D. BinarVMDecinal-Hexadecimal Conversion Tables

P<)WERS OF TWO
2
n n

2

·n

1 2 4 8 16 32 64 128

o

1.0 1 0.5 2 0.25 3 0.125 0.062 0.031 0.015 0.007 0.003 0.001 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 5 25 625 812 5 906 953 976 488 244 122 061 030 015 007 003 001 000 000 000 000 25 125 562 5 281 25 140 070 035 517 258 629 814 907 953 476 238 119 059 029 014 007 003 001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 625 312 5 156 25 578 125 789 394 697 348 674 837 418 209 6Cl4 802 901 450 725 862 931 465 232 116 058 029 014 007 003 001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 062 531 265 632 316 158 579 289 644 322 161 580 290 645 322 661 830 415 207 103 551 275 637 818 909 4,,4 227 113 056 028 014 007 003 001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 5 25 625 812 5 406 203 101 550 77 5 387 193 596 298 149 574 287 643 321 660 830 915 957 978 989 494 747 373 686 25 125 5625 781 25 390 695 847 923 461 230 615 307 653 826 913 456 228 614 807 403 701 350 675 837 625 312 5 656 25 828 125 914 957 478 739 869 934 467 733 366 183 091 545 772 886 443 721 062 031 515 257 628 814 407 703 851 425 712 856 928 464 232 616 5 25 625 812 5 906 453 226 613 806 903 951 475 25 125 562 5 281 25 640 320 660 830 625 312 5 156 25 078 125 039 062 519531 759 765 379 882 689 844 422 711 355 677 338 169 084 042 021 510 755 377 188 094 547 773 886 443 5 25 625 812 5 25 125 5625 781 25 890 945 472 236 625 312 5 656 25 328 125 164 082 541 270 135 567 783 391 695 347 173 086 062 5 031 25 015625 507 812 5 253 676 813 906 953 976 988 994 906 950 476 738 369 684 342 171 25 125 562 5 281 25 140 570 285 142 625 312 5 156 25 578 125

4 5 6 7

256 8 512 9 1 024 10 2 Cl48 11 4 8 16 32 65 131 262 524 1 2 4 8 16 33 67 134 048 097 194 388 096 192 384 768 536 072 144 288 576 152 304 308 12 13 14 15 16 17 18 19 20 21 22 23

7?7 216 24 0.000 000 554 ~32 25 0.000 000 108 364 26 0000 000 217 728 27 0.000 000 000 000 000 000 000 000 000 000

268 435 ~56 28 0.000 536 870 :l12 29 0.000 1 073 741 324 30 0.000 2 147 483 548 31 0.000 4 8 17 34 68 137 274 549 1 2 4 8 17 35 70 140 099 199 398 796 592 184 368 737 294 589 179 359 719 438 877 755 511 023 046 093 186 372 744 488 967 934 869 738 296 592 184 368 32 33 34 35 0000 0000 0000 0.000

476 736 36 0.000 000 953 ~72 37 0.000 000 906 :l44 38 0.000 000 813 388 39 0.000 000 627 255 511 022 044 088 177 355 776 40 55241 104 42 208 43 41644 332 45 56446 328 47 48 49 50 51 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0000 0.000 0.000 0.000 000 00.0 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000

237 915 118957 059 478 029 739 014 007 003 001 500 250 125 062 869 434 717 858 929 464 232 616

843 418 421 709 210 854 105427 552 776 888 444

860 808 430 404 715202 357 601 800 400 700 850 925 462 231 615 807 903 951 475 737 868 434 217

941 406 970 703 485 351 242675 621 810 905 452 726 363 181 590 295 647 823 411 205 602 801 400 337 668 3Cl4 667

281 474 976 710 556 562 949 953 421 312 1 125899906842 524 2 251 799 813 685 248 4 9 18 36 72 144 288 576 1 2 4 9 152 305 611 223 503 007 014 028 057 115 230 460 921 843 686 372 599 199 398 797 594 188 376 752 504 009 018 036 627 254 509 018 037 075 151 303 606 213 427 854 370 740 481 963 927 855 711 423 846 693 387 775

713 678 356 839 178419 089 209 604 302 151 575 787 893 446 723 361 680 840 420

496 52 992 53 98454 968 55 936 872 744 488 976 952 904 808 56 57 58 59 60 61 62 63

222 044 111 022 055511 027 755 013 006 003 001 000 000 000 000 877 938 469 734 867 433 216 108

031 308 515 654 257827 628 913 814 907 953 976 988 994 497 248 456 228 614 807 403 201 100 550

333 618 166 809 583404 791 702 395 697 848 924 962 981 490 745 851 925 962 481 240 120 560 280

D-2

Appendix D.

Binary~Decimal-Hexadecimal

Conversion Tables

POWERS OF 16 (IN BASE 10)
16" 1 16 256 096 536 576 216 456 296 736 776 416 656 496 936 976 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0.10000 0.62500 0.39062 0.24414 0.15258 0.95367 0.59604 0.37252 0.23283 0.14551 0.90949 0.56843 0.35527 0.22204 0.13877 0.86736 00000 00000 50000 06250 78906 43164 64477 90298 06436 91522 47017 41886 13678 46049 78780 17379 16'" 00000 00000 00000 00000 25000 06250 53906 46191 53869 83668 72928 08080 80050 25031 78144 88403 00000 00000 00000 00000 00000 00000 25000 40625 62891 51807 23792 14.870 09294 30808 56755 54721
X X X X X X X X

10
10- 1 10- 2

1 17 281 4 503 72 057 152 921

4 68 099 592 474 599 594 504

1 16 268 294 719 511 186 976 627 037 606

4 65 048 777 435 967 476 627 044 710 370 927 846

10- 3 10-4
10-6

x x
X X X X X X

10- 7 10-8 10-9 10- 10 10- 12
10- 13

10- 14 10- 15
10- 16

10- 18

POWERS OF 10 (IN BASE 16)
10" 10'"

3 23 163 oEO 8AC7

2 17 E8 918 5AF3 807E 8652 4578 B6B3 2304

1 F 98 5F5 3B9A 540B 4876 o4A5 4E72 107A A4C6 6FCl 508A A764 89E8

1 A 64 3E8 2710 86AO 4240 9680 El00 CAOO E400 E800 1000 AOOO 4000 8000 0000 0000 0000 0000

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

1.0000 0.1999 0.28F5 0.4189 0.68oB 0.A7C5 0.10C6 0.lA07 0.2AF3 0.44BB 0.6oF3 O.AFEB 0.1197 0.lC25 0.2009 0.480E 0.734A 0.B877 0.1272 0.1083

0000 9999 C28F 374B 8BAC AC47 F7AO F29A lOC4 2FAO 7F67 FFOB 9981 C268 3700 BE7B CA5F AA32 5001 C94F

0000 9999 5C28 e6A7 710C lB47 B5EO BCAF 6118 9B5A SEF6 CB24 20EA 4976 4257 9058 6226 36A4 0243 B602

0000 999A F5C3 EF9E B296 8423 8037 4858 73BF 52CC EAoF AAFF 1119 81C2 3604 5660 FOAE B449 ABAl AC35

x 16- 1 x 16 -2 x 16- 3 x 16- 4 x 16-4
X

x x x x x
X

x
X

x x
X
X

16- 5 16-6 16- 7 16-8 16- 9 16-9 16- 10 16- 11 16- 12 16- 13 16- 14 16- 14 16- 15

D-3

Appendix D. Binary-Declllal-Hexadecimal ConversIon Tables

HEXADECIMAL-DECIMAL INTEGER CONVERSION
The table below provide! for direct conversions between hexadecimal Integers In the range O-FFF and decimal integers In the range 0-4095. For conVHSlon of larger Integers, the table values may be added to the following figures: Hexadecimal 01000 02000 03000 04000 05000 06000 07000 08000 09000 OA 000 OB 000 oe 000 OD 000 OE 000 OF 000 10000 11 000 12000 13000 14000 15000 16000 17000 18000 19000 lAOOO lB 000 leOOO 10 000 lE 000 1F 000 0 000 010 020 030 040 050 060 070 080 090 OAO OBO 0000 0016 0032 0048 0064 0080 0096 0112 0128 0144 0160 0176 0192 0208 0224 0240 1 0001 0017 0033 0049 0065 0081 0097 0113 0129 0145 0161 0177 0193 0209 0225 0241 Decimal 4096 8192 12288 16384 20480 24576 28672 32768 36864 40960 45056 49152 53248 57344 61440 65536 69632 73728 77 824 81920 86016 90112 94208 98304 102400 106496 110592 114688 118784 122 880 126976 5 0005 0021 0037 0053 0069 0085 0101 0117 0133 0149 0165 0181 0197 0213 0229 0245 6 0006 0022 0038 0054 0070 00B6 0102 0118 0134 0150 0166 0182 0198 0214 0230 0246 7 0007 0023 0039 0055 0071 0087 0103 0119 0135 0151 0167 0183 0199 0215 0231 0247 Hexadecimal 20000 30000 40000 50000 60000 70000 80000 90000 AO 000 80000 CO 000 DO 000 EO 000 FO 000 100000 200000 300000 400000 500000 600000 700000 800000 900000 AOO 000 BOO 000 COO 000 DOO 000 EOO 000 FOO 000 1000000 2000000 8 OOOB 0024 0040 0056 0072 0088 0104 0120 0136 0152 0168 0184 0200 0216 0232 0248 9 0009 0025 0041 0057 0073 0089 0105 0121 0137 0153 0169 0185 0201 0217 0233 0249 Decimal 131072 196608 262144 327 680 393216 458752 524288 589824 655360 720896 786432 851 968 917504 983040 1048576 2097152 3 145728 4194304 5242880 6291456 7340032 8388608 9437184 10485760 11 534336 12 582912 13631488 14680064 15728640 16777216 33554432 A 0010 0026 0042 0058 0074 0090 0106 0122 0138 0154 0170 0186 0202 0218 0234 0250 B 0011 0027 0043 0059 0075 0091 0107 0123 0139 0155 0171 0187 0203 0219 0235 0251 e 0012 0028 0044 0060 0076 0092 0108 0124 0140 0156 0172 0188 0204 0220 0236 0252 D 0013 0029 0045 0061 0077 0093 0109 0125 0141 0157 0173 0189 0205 0221 0237 0253

2
0002 0018 0034 0050 0066 0082 0098 o 14 030 046 062 078 094 0:!10 0:!26 0:!42

3 0003 0019 0035 0051 0067 0083 0099 0115 0131 0147 0163 0179 0195 0211 0227 0243

4 0004 0020 0036 0052 0068 0084 0100 0116 0132 0148 0164 0180 0196 0212 0228 0244

E
0014 0030 0046 0062 0078 0094 0110 0126 0142 0158 0174 0190 0206 0222 0238 0254

F 0015 0031 0047 0063 0079 0095 0111 0127 0143 0159 0175 0191 0207 0223 0239 0255

oeo
ODO OEO OFO D-4

Appendix D. Binary-Decimal-Hexadecimal Conversion Tables

HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cant'dl

100 110 120 130 140 150 160 170 180 190 lAO lBO lCO lDO lEO lFO 200 210 220 230 240 250 260 270 280 290 2AO 2BO 2CO 2DO 2EO 2FO 300 310 320 330 340 350 360 370 380 390 3AO 3BO j3CO 3DO 3EO 1 i 3FO

1 0 2 3 0256 0257 0258 0259 0272 0273 0274 0275 0288 0289 0290 0291 0304 0305 0306 0307

4 0260 0276 0292 0308 0324 0340 0356 0372 038l:l 0404 0420 0436 0452 0468 0484 0500 0516 0532 0548 0564 0580 0596 0612 0628 0644 0660 0676 0692 0708 0724 0740 0756 0772 0788 0804 0820 0836 0852 0868 0884 0900 0916 0932 0948 0964 0980 0996 1012

5 0261 0277 0293 0309 0325 0341 0357 0373 0389 0405 0421 0437 0453 0469 0485 0501 0517 0533 0549 0565 0581 0597 0613 0629 0645 0661 0677 0693 0709 0725 0741 0757 0773 0789 0805 0821 0837 0853 0869 0885

6 0262 0278 0294 0310 0326 0342 0358 0374 0390 0406 0422 0438 0454 0470 0486 0502 0518 0534 0550 0566 0582 0598 0614 0630 0646 0662 0678 0694 0710 0726 0742 0758 0774 0790 0806 0822 0838 0854 0870 0886

7 0263 0279 0295 0311 0327 0343 0359 0375 0391 0407 0423 0439 0455 0471 0487 0503 0519 0535 0551 0567 0583 0599 0615 0631 0647 0663 0679 0695 0711 0727 0743 0759 0775 0791 0807 0823 0839 0855 0871 0887

8 0264 0280 0296 0312 0328 0344 0360 0376 0392 0408 0424 0440 0456 0472 0488 0504 0520 0536 0552 0568 0584 0600 0616 0632 0648 0664 0680 0696 0712 0728 0744 0760 0776 0792 0808 0824 0840 0856 0872 0888 0904 0920 0936 0952

9 0265 0281 0297 0313 0329 0345 0361 0377 0393 0409 0425 0441 0457 0473 0489 0505 0521 0537 0553 0569 0585 0601 0617 0633 0649 0665 0681 0697 0713 0729 0745 0761 0777 0793 0809 0825 0841 0857 0873 0889 0905 0921 0937 0953

A 0266 0282 0298 0314

B 0267 0283 0299 0315

C 0268 0284 0300 0316 0331 0348 0364 0380 0396 0412 0428 0444 0460 0476 0492 0508 0524 0540 0556 0572 0588 0604 0620 0636 0652 0668 0684 0700 0716 0732 0748 0764 0780 0796 0812 0828 0844 0860 0876 0892 0908 0924 0940 0956 0972 0988 1004 1020

D 0269 0285 0301 0317 0333 0349 0365 0381 0397 0413 0429 0445 0461 0477 0493 0509 0525 0541 0557 0573 0589 0605 0621 0637 0653 0669 0685 0701 0717 0733 0749 0765 0781 0797 0813 0829 0845 0861 0877 0893 0909 0925 0941 0957

E 0270 0286 0302 0318 0334 0350 0366 0382 0398 0414 0430 0446 0462 0478 0494 0510 0526 0542 0558 0574 0590 0606 0622 0638 0654 0670 0686 0702 0718 0734 0750 0766 0782 0798 0814 0830 0846 0862 0878 0894 0910 0926 0942 0958

F 0271 0287 0303 0319 0335 0351 0367 0383 0399 0415 0431 0447 0463 0479 0495 0511 0527 0543 0559 0575 0591 0607 0623 0639 0655 0671 0687 0703 0719 0735 0751 0767 0783 0799 0815 0831 0847 0863 0879 0895 0911 0927 0943 0959

I 0320
0336 0352 0368

0321 0337 0353 0369

0322 0338 0354 0370

0323 0339 0355 0371 0387 0403 0419 0435

0330 0331 0346 0347 0362 0363 0378 0379 0394 0410 0426 0442 0458 0474 0490 0506 0522 0538 0554 0570 0586 0602 0618 0634 0650 0666 0682 0698 0714 0730 0746 0762 0778 0794 0810 0826 0842 0858 0874 0890 0906 0922 0938 0954 0395 0411 0427 0443 0459 0475 0491 050"/ 0523 0539 0555 0571 0587 0603 0619 0635 0651 0667 0683 0699 0715 0731 0747 0763 0779 0795 0811 0827 0843 0859 0875 0891 0907 0923 0939 0955

0384 0385 0386 0400 0401 0402 0416 0417 0418 0432 0433 0434

I 0448 0464
0480 0496

0449 0465 0481 0497

0450 0451 0466 0467 0482 0483 0498 0499 0514 0515 0530 0531 0546 0547 0562 0563 0578 0579 0594 0595 0610 0611 0626 0627 0643 0659 0675 0691 0707 0723 0739 0755 0771 0787 0803 0819 0835 0851 0867 0883 0899 0915 0931 0947

I 0528

0512

0513 0529 0544 0545 0560 0561 0576 0592 0608 0624 0577 0593 0609 0625

0640 0641 0642 0656 0657 0658 0672 0673 0674 0688 0689 0690 0704 0705 0706 0720 0721 0722 0736 0737 0738 0752 0753 0754 0768 0769 0770 0784 0785 0786 0800 0301 0802 0816 0817 0818 0832 0848 0864 0880 0896 0212 0928 0944 0833 0849 0865 0881 0897 0913 0929 0945 0834 0850 0866 0882 0898 0914 0930 0946

0901 0902 0903 0917 0918 0919 0933 0934 0935 0949 0950 0951 0965 0981 0997 1013 0966 0982 0998 1014 0967 0983 0999 1015

0960 0961 0962 0963 0976 0977 0978 0979 0992 0993 0994 0995 1008 1009 1010 1011

0968 0969 0970 0971 0984 0985 0986 0987 1000 1001 1002 1003 1016 1017 1018 1019

0973 0974 0975 0989 0990 0991 1005 1006 1007 1021 1022 1023
D-5

Binarv-Oet Imal~HexadecimaJ Conversion Tables HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd) I 400 410 420 430 440 450 460 470 480 490 4AO 4BO 4CO 400 4EO 4FO 500 0 1024 1040 1056 1072 1088 1104 1120 1136 1152 1168 1184 1200 1216 1232 1248 1264 1280 1296 1312 1328 1344 1360 1376 1392 1408 1424 1440 1456 1472 1488 1504 1520 1536 1552 1568 1584 1600 1616 1632 1648 1664 1680 1696 1712 1728 1744 1760 1776 1 1025 1041 1057 1073 1089 1105 1121 1137 1153 1169 1185 1201 1217 1233 1249 1265 1281 1297 1313 1329 1345 1361 1377 1393 1409 1425 1441 1457 1473 1489 1505 1521 1537 1553 1569 1585 1601 1617 1633 1649 1665 1681 1697 1713 1729 1745 1761 1777 2 1026 1042 1058 1074 1090 1106 1122 1138 1154 1170 1186 1202 1218 1234 1250 1266 1282 1298 1314 1330 1346 1362 1378 1394 1410 1426 1442 1458 1474 1490 1506 1522 1538 1554 1570 1586 1602 1618 1634 1650 1666 1682 1698 1714 1730 1746 1762 1778 3 1027 1043 1059 1075 1091 1107 1123 1139 1155 1171 1187 1203 1219 1235 1251 1267 1283 1299 1315 1331 1347 1363 1379 1395 1411 1427 1443 1459 1475 1491 1507 1523 1539 1555 1571 1587 1603 1619 1635 1651 1667 1683 1699 1715 1731 1747 1763 1779 4 1028 1044 1060 1076 1092 1108 1124 1140 1156 1172 1188 1204 1220 1236 1252 1268 1284 1300 1316 1332 1348 1364 1380 1396 1412 1428 1444 1460 1476 1492 1508 1524 1540 1556 1572 1588 1604 1620 1636 1652 1668 1684 1700 1716 1732 1748 1764 1780 5 1029 1045 1061 1077 1093 1109 1125 1141 1157 1173 1189 1205 1221 1237 1253 1269 1285 1301 1317 1333 1349 1365 1381 1397 1413 1429 1445 1461 1477 1493 1509 1525 1541 1557 1573 1589 1605 1621 1637 1653 1669 1685 1701 1717 1733 1749 1765 1781 6 1030 1046 1062 1078 1094 1110 1126 1142 1158 1174 1190 1206 1222 1238 1254 1270 1286 1302 1318 1334 1350 1366 1382 1398 1414 1430 1446 1462 1478 1494 1510 1526 7 1031 1047 1063 1079 1095 1111 1127 1143 1159 1175 1191 1207 1223 1239 1255 1271 1287 1303 1319 1335 1351 1367 1383 1399 1415 1431 1447 1463 1479 1495 1511 1527 8 1032 1048 1064 1080 1096 1112 1128 1144 1160 1176 1192 1208 1224 1240 1256 1272 1288 1304 1320 1336 1352 1368 1384 1400 1416 1432 1448 1464 1480 1496 1512 1528 1544 1560 1576 1592 1608 1624 1640 1656 1672 1688 1704 1720 1736 1752 1768 1784 9 1033 1049 1065 1081 1097 1113 1129 1145 1161 1177 1193 1209 1225 1241 1257 1273 1289 1305 1321 1337 1353 1369 1385 1401 1417 1433 1449 1465 1481 1497 1513 1529 1545 1561 1577 1593 1609 1625 1641 1657 1673 1689 1705 1721 A 1034 1050 1066 1082 1098 1114 1130 1146 1162 1178 1194 1210 1226 1242 1258 1274 1290 1'306 1322 1338 1354 1370 1386 1402 1418 1434 1450 1466 1482 1498 1514 1530 1546 1562 1578 1594 1610 1626 1642 1658 1674 1690 1706 1722 B 1035 1051 1067 1083 1099 1115 1131 1147 1163 1179 1195 1211 1227 1243 1259 1275 1291 1307 1323 1339 1355 1371 1387 1403 1419 1435 1451 1467 1483 1499 1515 1531 1547 1563 1579 1595 1611 1627 1643 1659 1675 1691 1707 1723 1739 1755 1771 1787 C 1036 1052 1068 1084 1100 1116 1132 1148 1164 1180 1196 1212 1228 1244 1260 1276 1292 1308 1324 1340 1356 1372 1388 1404 1420 1436 1452 1468 1484 1500 1516 1532 1548 1564 1580 1596 1612 1628 1644 1660 1676 1692 1708 1724 1740 1756 1772 1788 0 1037 1053 1069 1085 1101 1117 1133 1149 1165 1181 1197 1213 1229 1245 1261 1277 1293 1309 1325 1341 1357 1373 1389 1405 1421 1437 1453 1469 1485 1501 1517 1533 1549 1565 1581 1597 1613 1629 1645 1661 1677 1693 1709 1725 1741 1757 1773 1789 E 1038 1054 1070 1086 1102 1118 1134 1150 1166 1182 1198 1214 1230 1246 1262 1278 1294 1310 1326 1342 1358 1374 1390 1406 1422 1438 1454 1470 1486 1502 1518 1534 1550 1566 1582 1598 1614 1630 1646 1662 1678 1694 1710 1726 1742 1758 1774 1790 F 1039 1055 1071 1087 1103 1119 1135 1151 1167 1183 1199 1215 1231 1247 1263 1279 1295 1311 1327 1343 1359 1375 1391 1407 1423 1439 1455 1471 1487 1503 1519 1535 1551 1567 1583 1599 1615 1631 1647 1663 1679 1695 1711 1727 1743 1759 1775 1791 510 520 530 540 550 560 570 580 590 5AO 5BO 5CO 500 5EO 5FO 600 610 620 630 640 650 660 670 680 690 6AO 680 6CO 600 6EO 6FO D-6 154~ 1543 1558 1559 1574 1575 1590 1591 1606 1622 1638 1654 1670 1686 1702 1718 1734 1750 1766 1782 1607 1623 1639 1655 1671 1687 1703 1719 1735 1751 1767 1783 1737 1738 1753 1754 1769 1770 1785 1786 .Appendix O.

Appendix D. Binarv-Decimal-Hexadecimal Conversion Tables HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd) 0 700 710 720 730 740 750 760 770 780 790 7AO 7BO 7CO 700 7EO 7FO 800 1 1793 1809 1825 1841 1857 1873 1889 1905 1921 1937 1953 1969 1985 2001 2017 2033 2049 2065 2081 2097 2113 2129 2145 2161 2177 2193 2209 2225 2241 2257 2273 2289 2305 2321 2337 2353 2369 2385 2401 2417 2433 2449 2465 2481 2497 2513 2529 2545 2 1794 1810 1826 1842 1858 1874 1890 1906 1922 1938 1954 1970 1986 2002 2018 2034 2050 2066 2082 2098 2114 2130 2146 2162 2178 2194 2210 2226 2242 2258 2274 2290 2306 2322 2338 2354 2370 2386 2402 2418 2434 2450 2466 2482 2498 2514 2530 2546 3 1795 1811 1827 1843 1859 1875 1891 1907 1923 1939 1955 1971 1987 2003 2019 2035 2051 2067 2083 2099 2115 2131 2147 2163 2179 2195 2211 2227 2243 2259 2275 2291 2307 2323 2339 2355 2371 2387 2403 2419 2435 2451 2467 2483 2499 2515 2531 2547 4 1796 1812 1828 1844 1860 1876 1892 1908 1924 1940 1956 1972 1988 2004 2020 2036 2052 2068 2084 2100 2116 2132 2148 2164 2180 2196 2212 2228 2244 2260 2276 2292 2308 2324 2340 2356 2372 2388 2404 2420 2436 2452 2468 2484 2500 2516 2532 2548 ! I 1792 1808 1824 1840 1856 1872 1888 1904 1920 1936 1952 1968 1984 2000 2016 2032 2048 2064 5 1797 1813 1829 1845 1861 1877 1893 1909 1925 1941 1957 1973 1989 2005 2021 2037 2053 2069 2085 2101 2117 2133 2149 2165 2181 2197 2213 2229 2245 2261 2277 2293 2309 2325 2341 2357 2373 2389 2405 2421 2437 2453 2469 2485 2501 2517 2533 2549 6 1798 1814 1830 1846 1862 1878 1894 1910 1926 1942 1958 1974 1990 2006 2022 2038 2054 2070 2086 2102 2118 2134 2150 2166 2182 2198 2214 2230 2246 2262 2278 2294 2310 2326 2342 2358 2374 2390 2406 2422 2438 2454 2470 2486 2502 2518 2534 2550 7 1799 1815 1831 1847 1863 1879 1895 1911 1927 1943 1959 1975 1991 2007 2023 2039 2055 2071 2087 2103 2119 2135 2151 2167 2183 2199 2215 2231 2247 2263 2279 2295 2311 2327 2343 2359 2375 2391 2407 2423 2439 2455 2471 2487 2503 2519 2535 2551 8 1800 1816 1832 1848 1864 1880 1896 1912 1928 1944 1960 1976 1992 2008 2024 2040 2056 2072 2088 2104 2120 2136 2152 2168 2184 2200 2216 2232 2248 2264 2280 2296 2312 2328 2344 2360 2376 2392 2408 2424 2440 2456 2472 2488 2504 2520 2536 2552 9 1801 1817 1833 1849 1865 1881 1897 1913 1929 1945 1961 1977 1993 2009 2025 2041 2057 2073 2089 2105 2121 2137 2153 2169 2185 2201 2217 2233 2249 2265 2281 2297 2313 2329 2345 2361 2377 2393 2409 2425 2441 2457 2473 2489 2505 2521 2537 2553 A 1802 1818 1834 1850 1866 1882 1898 1914 1930 1946 1962 1978 1994 2010 2026 2042 2058 2074 2090 2106 2122 2138 2154 2170 2186 2202 2218 2234 2250 2266 2282 2298 2314 2330 2346 2362 2378 2394 2410 2426 2442 2458 2474 2490 2506 2522 2538 2554 B 1803 1819 1835 1851 1867 1883 1899 1915 1931 1947 1963 1979 1995 2011 2027 2043 2059 2075 2091 2107 2123 2139 2155 2171 2187 2203 2219 2235 2251 2267 2283 2299 2315 2331 2347 2363 2379 2395 2411 2427 2443 2459 2475 2491 2507 2523 2539 2555 C 1804 1820 1836 1852 1868 1884 1900 1911j 1932 1948 1964 1980 1996 2012 2028 2044 2060 2076 2092 2108 2124 2140 2156 2172 2188 2204 2220 2236 2252 2268 2284 2300 2316 2332 2348 2364 2380 2396 2412 2428 2444 2460 2476 2492 2508 2524 2540 2556 0 1805 1821 1837 1853 1869 1885 1901 1917 1933 1949 1965 1981 1997 2013 2029 2045 2061 2077 2093 2109 2125 2141 2157 2173 2189 2205 2221 2237 2253 2269 2285 2301 2317 2333 2349 2365 2381 2397 2413 2429 2445 2461 2477 2493 2509 2525 2541 2557 E 1806 1822 1838 1854 1870 1886 1902 1918 1934 1950 1966 1982 1998 2014 2030 2046 2062 2078 2094 2110 2126 2142 2158 2174 2190 2206 2222 2238 2254 2270 2286 2302 2318 2334 2350 2366 2382 2398 2414 2430 2446 2462 2478 2494 2510 2526 2542 2558 F 1807 1823 1839 1855 1871 1887 1903 1919 1935 1951 1 1967 1983 1999 2015 2031 2047 2063 2079 2095 2111 2127 2143 2159 2175 2191 2207 2223 2239 2255 2271 2287 2303 2319 2335 2351 2367 2383 2399 2415 2431 2447 2463 2479 2495 2511 2527 2543 2559 0-7 810 820 830 840 .850 860 870 880 890 8AO 8BO 8CO 800 8EO 8FO 2080 2096 2112 2128 2144 2160 2176 2192 2208 2224 2240 2256 2272 2288 1 900 2304 910 2320 920 2336 930 I 2352 940 950 960 970 980 990 2368 2384 2400 2416 2432 2448 2464 2480 2496 2512 2528 2544 9AO 980 9CO 900 9EO 9FO .

Binary-Declmal-Hexadeclmal Conversion Tables HEXADECIMAL·DECIMAL INTEGER CONVERSION (Cont'dl Aoo Al0 A20 A30 A40 A50 A60 A70 A80 A90 AAO ABO 0 2560 2576 2592 2608 2624 2640 2656 2672 2688 2704 2720 2736 1 2561 2577 2593 2609 2625 2641 2657 2673 2689 2705 2721 2737 2753 2769 2785 2801 2817 2833 2849 2865 2881 2897 2913 2929 2945 2961 2977 2993 3009 3025 3041 3057 3073 3089 3105 3121 3137 3153 3169 3185 2 2562 2578 2594 2610 2626 2642 2658 2674 2690 2706 2722 2738 2754 2770 2786 2802 2818 2834 2850 2866 2882 2898 2914 2930 2946 2962 2978 2994 3010 3026 3042 3058 --- 3 2563 2579 2595 2611 2627 2643 2659 2675 2691 2707 2723 2739 2755 2771 2787 2803 2819 2835 3851 2867 2883 2899 2915 2931 2947 2963 2979 2995 3011 3027 3043 3059 3075 3091 3107 3123 3139 3155 3171 3187 3203 3219 3235 3251 3267 3283 3299 3315 4 2564 2580 2596 2612 2628 2644 2660 2676 2692 2708 2724 2740 2756 2772 2788 2804 2820 2836 2852 2868 2884 2900 2916 2932 2948 2964 2980 2996 3012 3028 3044 3060 3076 3092 3108 3124 3140 3156 3172 3188 3204 3220 3236 3252 3268 3284 3300 3316 5 2565 2581 2597 2613 2629 2645 2661 2677 2693 2709 2725 2741 2757 2773 2789 2805 2821 2837 2853 2869 2885 2901 2917 2933 2949 2965 2981 2997 3013 3029 3045 3061 3077 3093 3109 3125 3141 3157 3173 3189 3205 3221 3237 3253 3269 3285 3301 3317 7 6 2566 2567 2582 2583 2598 2599 2614 2615 2630 2646 2662 2678 2631 2647 2663 2679 8 2568 2584 2600 2616 2632 2648 2664 2680 2696 2712 2728 2744 2760 2776 2792 2808 2824 2840 2856 2872 2888 2904 2920 2936 2952 2968 2984 3000 3016 3032 3048 3064 3080 3096 3112 3128 3144 3160 3176 3192 3208 3224 3240 3256 3272 3288 3304 3320 9 2569 2585 2601 2617 A 2570 2586 2602 2618 8 2571 2587 2603 2619 C 2572 2588 2604 2620 2636 2652 2668 2684 2700 2716 2732 2748 2764 2780 2796 2812 2828 2844 2860 2876 2892 2908 2924 2940 2956 2972 2988 3004 3020 3036 3052 3068 3084 3100 3116 3132 3148 3164 3180 3196 3212 3228 3244 3260 3276 3292 3308 3324 D 2573 2589 2605 2621 2637 2653 2669 2685 2701 2717 2733 2749 2765 2781 2797 2813 2829 2845 2861 2877 2893 2909 2925 2941 2957 2973 2989 3005 3021 3037 3053 3069 3085 3101 3117 3133 3149 3165 3181 3197 3213 3229 3245 3261 3277 3293 3309 3325 E 2574 2590 2606 2622 2638 2654 2670 2686 2702 2718 2734 2750 2766 2782 2798 2814 2830 2846 2862 2878 2894 2910 2926 2942 2958 2974 2990 3006 3022 3038 3054 3070 3086 3102 3118 3134 3150 3166 3182 3198 3214 3230 3246 3262 3278 3294 3310 3326 F 2575 2591 2607 2623 2639 2655 2671 2687 2703 2719 2735 2751 2767 2783 2799 2815 2831 2847 2863 2879 2895 2911 2927 2943 2959 2975 2991 3007 3023 3039 3055 3071 3087 3103 3119 3135 3151 3167 3183 3199 3215 3231 3247 3263 3279 3295 3311 3327 2633 2634 2635 2649 2650 2651 2665 2666 2667 2681 2682 2683 2697 2713 2729 2745 4761 2777 2793 2809 2825 2841 2857 2873 2889 2905 2921 2937 2698 2714 2730 2746 2762 2778 2794 2810 2826 2842 2858 2874 2890 2906 2922 2938 2699 2715 2731 2747 2763 2779 2795 2811 2827 2843 2859 2875 2891 2907 2923 2939 2694 2695 2710 2711 2726 2727 2742 2743 2758 2774 2790 2806 2822 2838 2854 2870 2759 2775 2791 2807 2823 2839 2855 2871 ACO 12752 ADO I 2768 AEO 2784 AFO 2800 BOO Bl0 B20 B30 B40 B50 B60 B70 B80 B90 BAO BBO BCO BDO BEO BFO COO Cl0 C20 C30 C40 C50 C60 C70 C80 C90 CAO CBO CCO CDO CEO CFO D-8 2816 2832 2848 2864 2880 2896 2912 2928 2944 2960 2976 2992 3008 3024 3040 3056 3072 3088 3104 3120 3136 3152 3168 3184 2866 2887 2902 2903 2918 2919 2934 2935 2950 2966 2982 2998 3014 3030 3046 3062 3078 3094 3110 3126 3142 3158 3174 3190 3206 3222 3238 3254 3270 3286 3302 3318 2951 2967 2983 2999 3015 3031 3047 3063 3079 3095 3111 3127 3143 3159 3175 3191 3207 3223 3239 3255 3271 3287 3303 3319 2953 2954 2955 2969 2970 2971 2985 2986 2987 3001 3002 3003 3017 3033 3049 3065 3081 3097 3113 3129 3145 3161 3177 3193 3018 3034 3050 3066 3082 3098 3114 3130 3146 3162 3178 3194 3019 3035 3051 3067 3083 3099 3115 3131 3147 3163 3179 3195 3074 3090 3106 3122 3138 3154 3170 3186 3202 3218 3234 3250 3266 3282 3298 3314 3200 3201 3216 3217 3232 3233 3248 3249 3264 3280 3296 3312 3265 3281 3297 3313 3209 3210 3211 3225 3226 3227 3241 3242 3243 3257 3258 3259 3273 3289 3305 3321 3274 3290 3306 3322 3275 3291 3307 3323 .Appendix D.

4040 4056 4072 4088 4041 4057 4073 4089 4042 4043 4058 4059 4074 4075 4090 4091 3981 3982 3983 3997 3998 3999 4013 4014 4015 4029 4030 4031 4045 4046 4047 4061 4062 4063 4077 4078 4079 4093 4094 4095 0-9 . Binary-Declmal-Hexadecimal ConverSion Tables HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd) 0 1 3328 3329 3344 3345 3360 3361 3376 3377 2 3 3330 3331 3346 3347 3362 3363 3378 3379 3395 3411 3427 3443 3459 3475 3491 3507 4 3332 3348 3364 3380 3396 3412 3428 3444 3460 3476 3492 3508 3524 3540 3556 3572 3588 3604 3620 3636 3652 3668 3684 3700 3716 3732 3748 3764 3780 3796 3812 3828 3844 3860 3876 3892 3908 3924 3940 3956 3972 3988 4004 4020 4036 4052 4068 4084 5 3333 3349 3365 3381 6 3334 3350 3366 3382 7 8 3336 3352 3368 3384 9 3337 3353 3369 3385 A 3338 3354 3370 3386 B 3339 3355 3371 3387 C 3340 3356 3372 3388 3404 3420 3436 3452 3468 3484 3500 3516 3532 3548 3564 3580 3596 3612 3E528 3644 3660 3676 3692 3708 3724 3740 3756 3772 3788 3804 3820 3836 3852 3868 3884 3900 3916 3932 3948 3964 3980 3996 4012 4028 4044 4060 4076 4092 0 3341 3357 3373 3389 E 3342 3358 3374 3390 F 3343 3359 3375 3391 000 010 020 030 040 050 060 070 080 090 OAO OBO OCO 000 OEO OFO EOO El0 E20 E30 E40 E50 E60 E70 E80 E90 EAO EBO ECO EOO EEO EFO FOO FlO F20 F30 F40 F50 F60 F70 F80 F90 FAO FBO FCO FOO FEO FFO 3335 3351 3367 3383 3392 3393 3394 3408 3409 3410 3424 3425 3426 3440 3441 3442 3456 3472 3488 3504 3457 3473 3489 3505 3458 3474 3490 3506 3397 3398 3399 3413 3414 3415 3429 3430 3431 3445 3446 3447 3461 3477 3493 3509 3525 3541 3557 3573 3589 3605 3621 3637 3653 3669 3685 3701 3462 3478 3494 3510 3526 3542 3558 3574 3590 3606 3622 3638 3654 3670 3686 3702 3463 3479 3495 3511 3527 3543 3559 3575 3591 3607 3623 3639 3655 3671 3687 3703 3400 3401 3416 3417 3432 3433 3448 3449 3464 3480 3496 3512 3528 3544 3560 3576 3592 3608 3624 3640 3656 3672 3688 3704 3720 3736 3752 3768 3465 3481 3497 3513 3529 3545 3561 3577 3593 3609 3625 3641 3657 3673 3689 3705 3721 3737 3753 3769 3402 3403 3418 3419 3434 3435 3450 3451 3466 3482 3498 3514 3530 3546 3562 3578 3594 3610 3626 3642 3467 3483 3499 3515 3531 3547 3563 3579 3595 3611 3627 3643 3405 3406 3407 3421 3422 3423 3437 3438 3439 3453 3454 3455 3469 3485 3501 3517 3533 3549 3565 3581 3470 3486 3502 3518 3534 3550 3566 3582 3471 3487 3503 3519 3535 3551 3567 3583 3599 3615 3631 3647 3663 3679 3695 3711 3727 3743 3759 3775 3791 3807 3823 3839 3855 3871 3887 3903 3919 3935 3951 3967 3520 3521 3522 3523 3536 3537 3538 3539 3552 3553 3554 3555 3568 3569 3570 3571 3584 3585 3586 3587 3600 3601 3602 3603 3616 3617 3618 3619 3632 3633 3634 3635 3648 3664 3680 3696 3712 3728 3744 3760 3649 3665 3681 3697 3713 3729 3745 3761 3650 3651 3666 3667 3682 3683 3698 3699 3714 3730 3746 3762 3715 3731 3747 3763 3779 3795 3811 3827 3597 3598 3613 3614 3629 3630 3645 3646 3661 3677 3693 3709 3725 3741 3757 3773 3789 3805 3821 3837 3853 3869 3885 3901 3917 3933 3949 3965 3662 3678 3694 3710 3726 3742 3758 3774 3790 3806 3822 3838 3854 3870 3886 3902 3918 3934 3950 3966 3658 3659 3674 3675 3690 3691 3706 3707 3722 3738 3754 3770 3723 3739 3755 3771 3787 3803 3819 3835 3851 3867 3883 3899 3915 3931 3947 3963 3717 3718 3719 3733 3734 3735 3749 3750 3751 3765 3766 3767 3781 3782 3783 3797 3798 3799 3813 3814 3815 3829 3830 3831 3845 3846 3847 3861 3862 3863 3877 3878 3879 3893 3894 3895 3909 3910 3911 3925 3926 3927 3941 3942 3943 3957 3958 3959 3973 3974 3975 3989 3990 3991 4005 4006 4007 4021 4022 4023 4037 4053 4069 4085 4038 4054 4070 4086 4039 4055 4071 4087 3776 3777 3778 3792 3793 3794 3808 3809 3810 3824 3825 3826 3840 3856 3872 3888 3904 3920 3936 3952 3841 3857 3873 3889 3905 3921 3937 3953 3784 3785 3786 3800 3801 3802 3816 3817 3818 3832 3833 3834 3848 3864 3880 3896 3912 3928 3944 3960 3849 3865 3881 3897 3913 3929 3945 3961 3850 3866 3882 3898 3914 3930 3946 3962 3842 3843 3858 3859 3874 3875 3890 3891 3906 3922 3938 3954 3907 3923 3939 3955 3968 3969 3970 3971 3984 3985 3986 3987 4000 4001 4002 4003 4016 4017 4018 4019 4032 4033 4034 4035 4048 4049 4050 4051 4064 4065 4066 4067 4080 4081 4082 4083 3976 3977 3978 3979 3992 3993 3994 3995 4008 4009 4010 4011 4024 4025 4026 4027 .Appendix D.

.

7-22 · 6-1 .3-74 .4-70 .3-/4 .4-74 1-3 2-1 1-3 1-1 ./-72 · 2-6 · 2-3 7-78.3-ll .5-11.2-74 3-8 .2-/3 2-8 ./-/0 . Need for Assembler Character Set Assembler Compared with PL/M Assembler Function .3-70 .3-72 .5-15.8080/8085 Differences Binary Data (Coding Rules) blank (character) Branching Instructions Branch Table Byte Isolation Operations CALL Instruction Carry Flag .7-/6 · 2-4 .2-11 .2-12 . Assembler Termination Assembly-Time Expression Evaluation Auxiliary Carry Flag Auxiliary Carry Flag Setting .7-75 1-7 · 3-6 . 1-7 _/-79 3-2 3-2 3-4 3-5 .7-77 2-6 .INDEX Absolute symbols Accumulator Accumulator Instructions ACI Instruction ADC Instruction ADD Instruction ADI Instruction Addressing Modes Addressing Registers ANA (AND) Instruction AND Operator ANI (AND Immediate) Instruction Arithmetic Expression Operators Arithmetic Instructions ASCII Constant ASEG (Absolute Segment) Directive Assembler.7-77 .2-13 · 2-7 · 2-8 5-10.3-72 .5-16 1-1 .2-73 · 3-7 .3-70 . 2-16 1-6. CC (Call if Carry) Instruction CM (Call if Minus) Instruction CMA (Complement Accumulator) Instruction CMC (Complement Carry) Instruction CMP (Compare) Instruction CNC (Call if no carry) Instruction CNZ (Call if not Zero) Instruction Combined Addressing Modes Comment Field Compare Operators Comparing Complemented Data Comparisons in Expressions Complement Used for Subtraction Complemented Data Concatenation 2-11.

3-22. 1-9 4-8 3-75 3-76 3-76 3-77 4-75 3-78 3-78 3-20 4-7 4-3 4-6 6-3 2-5 7-76 .5-6.3-60 7-75 6-9 2-12 4-5 4-75 5-4 4-4 3-23 4-8 4-70 4-8 5-5. I'recedence of Operators Expressions.4-3 3-20 3-22 6-12 2-5 6-14 2-2 .erators Expressions Expressions.~ero) Instruction .\ are Example) Division in Expressions DS (Define ~ torage) Directive DSEG (Data Segment) Directive Dummy Paralneters DW (Define Nord) Directive EI (Enable I:1terrupts) Instruction ELSE Directi'e .5-12 4-77 1-5 2-73 4-2 5-9 2-11 2-11 2-6 2-75 2-75 4-77 1-2 . .Condition Fla 5S Conditional /J ssembly CP (Call if I'ositlve) Instruction CPE (Call if Parity Even) Instruction CPI (Compan Immediate) Instruction CPO (Call if Parity Odd) Instruction CSEG (Code Segment) Directive CZ (Call if . DAA (Decim. tive . I Adjust Accumulator) Instruction DAD (DoublE Register Add) Instruction Data Access Example Data Definiti<n Data Descrtpt on Example Data for Subroutines Data Label Data Transfer Instructions DB (Define Iiyte) Directive DCR (DecrelT ent) Instruction DCX (DecrelT ent Register Pair) Decimal AddiCion Routine Decimal Data (Coding Rules) Decimal Subt 'action Routine Delimiters DI (Disable Interrupts) Instruction Direct Addre~ sing Divide (Soft'. ~ange of Values EXTRN Dire.5-7. END Directlv ~ ENDIF Direclve ENDM (End Macro) Directive EOT Directive EPROM EQ Operator EQU Directlv ~ EXITM (Exit Macro) DireClive Expression E' aluatton Expression O. .

5-17 3-26 3-27 3-28 3-28 3-29 3-29 3-30 3-37 3-32 2-3 2-6 3-32 3-33 1-3 . 3-24 ·4-74. 7-74. 404 .GE Operator General Purpose Registers GT Operator Hardware Overview Hexadecimal Data (Coding Rules) HIGH Operator HLT (Halt) Instruction IF Directive Immediate Addressing Implied Addressing IN (Input) Instruction INPAGE Reserved Word Input/Output Ports IN R (I ncrement) Instruction Instruction Addressing Modes Instruction Execution Instruction Fetch Instructlon Label Instruction Naming Conventions Instruction Set GUide Instruction Summary Instruction Timing Instructions as Operands INTE Pin Internal Registers Interrupt Subroutines Interrupts Interrupts (8085) INX (Increment Register Pair) Instructions IRP (Indefinite Repeat) Directive IRPC (Indefinite Repeat Character) )C (J ump if Carry) Instruction JM (J ump if Minus) Instruction JMP (J ump) Instruction JNC (Jump if no carry) Instruction JNZ (J ump if not zero) Instruction JP (Jump if Positive) Instruction JPE (Jump if parity Even) JPO (J ump if parity Odd) j Z (J ump if Zero) Instruction Label Field Labels LDA (Load Accumulator Direct) Instruction LDAX (Load Accumulator Indirect) 2-73 7-7 2-73 1-5 2-5 2-74. . 5-12.5-8.5-22 . .5-8. .4-75 7-74 3-25 7-75 1-9 1-8 2-6 1-16 7-23 . . 3-2.1-19. 3-5. 3-7.5-12. 3-24 4-8 7-75 7-75 .7-23 3-7 2-7 3-49 1-6 7-4 7-1 1-24 3-26 . .

3-7.4-14. m Linkage List File LOCAL Dip-ctive LOCAL Syrlbols LOCATE Pr Jgram Location Counter (Coding Rules) Location Counter Control (Absolute Mode) Location Counter Control (Relocatable Mode) Logical Instr uctions Logical Instl uctions.4-19 2-6 4-77 4-74 7-17 3-6 2-13 2-74.LE OperatOl LIB Prograrr LHLD (Load L Direct) Instruction LINK Progr.4-15 4-16 1-1 5-5 5-6 4-12.4-13.4-4 2-13 3-35 5-1 5-12 5-4 5-4 5-15 5-5 5-3 1-3 1-5 4-72 4-5 4-19 2-12 4-72 4-17 3-36 6-11 6-11 2-12 6-7 3-37 4-78 2-13 5-14 5-12 3-48 2-7 3-38 1-4 . Summary Logical Ope-a tors LOW Opera:or LT Operato LXI (Load Register Pair Immediate) Macros Macro Calls Macro Defir Ition MACRO Dir ective Macro Expa lSlon Macro Parar leters Macros verslls Subroutines Manual ProFamming Memory Memory Management with Relocation Memory REservation MEMORY I:eserved Word MOD Opera tor Modular Pr<gramming MODULE [efault Name MOV (MovE) Instruction Multibyte P ddition Routines Multibyte S Jbtraction Routine Multiplicatiol in Expressions Multiply (Software Example) MVI (Move Immediate) NAME Dire. 3-5.tive NE Operatcr Nested Maco Calls Nested Mac'o Definitions Nested Sub-outines Nine's Com~lement NOP (No Operation) Instruction 2-13 4-12 3-34 4-12.4-14. 3-2.

.5-77 5-16 5-11 7-2 1-1 2-5 2-7 1-1 2-4 2-4 2-4 2-5 2-11 2-73 4-77 4-76 3-38 3-40 1-14. 4 c74.NOP NOT NUL Null Null via MOV Operator Operator Macros Parameter .7-74. 2-73 . 4-75 7-77 3-42 2-11 1-3 1-3 3-42 3-43 2-75 1-9 1-6 4-76 1-2 1-13 7-74 1-24 1-5 . . Expression OR Operator ORG (Origin) Directive (Absolute Mode) ORG (Origin) Directive (Relocatable Mode) ORA (Inclusive OR) Instruction OR! (Inclusive OR Immediate) OUT Instruction PAGE Reserved Word Parity Flag PCHL (Move H & L to Program Counter) Instruction Permanent Symbols PL/M PL/M Compared with Assembler POP Instruction POP PSW instruction Precedence of Expression Operators Processor Registers Program Counter Program linkage Directives Program listing Program Status Program Status Word (PSW) Programming the 8085 PROM PSW PUBLIC Directive PUSH Instruction PUSH PSW Instruction RAM RAM versus ROM RAL (Rotate Left through Carry) Instruction 4-77 3-44 3-45 1-5 4-6 3-45 1-5 . 3-36 . . 3-45 Object Code Object File Octal Data (Coding Rules) One's Complement Opcode Opcode Field Operand Field Operand Field (Coding Rules) Operands Operators.2-13.3-47 .

3-49.5-17.ltor SHLD (St"re H & L Direct) Instruction SHR Operltor Sign Flag SIM (Set Interrupt Mask) 8085 Instruction Software Divide Routine Software I~ultiply Routine Source Coje Format Source Lilie Fields Source Program File SPHL (Mcve H & L to Stack Pointer) Instruction 3-46 3-47 2-11 7-75 7-76 7-27 1-7 4-72 .5 RST7. 3-59. 3-55.2-79 2-11 1-2 2-9 3-24 3-48 5-6.5 RST6. 3-59. te Accumulator Left) Instruction RM (RetUi n if Minus) Instruction RNC (Retllrn if no Carry) Instruction RNZ (Retllrn if not Zero) Instruction ROM RP (Retur 1 if Positive) Instruction RPE (Retun if Parity Even) Instruction RPO (RetiTn if Parity Odd) Instruction RRC (Rot Ite Accumulator Right) Instruction RST (Restlrt) Instruction RST5. 3-60 3-55 7-73 3-56 3-57 2-10 4-3 2-12 2-12 2-72 3-58 2-72 7-70 3-59 6-7 6-7 2-1 2-1 1-1 3-67 1-6 . 3-60 3-49.5-12. 3-55. 3-60 .5-16.5-15. 3-55.RAR (Rotte Right through Carry) Instruction RC (Retum if Carry) Instruction Redefinable Symbols Register AddreSSing Register Injirect Addressing Register Pc ir Instructions Register Pc irs Relocatabili ty Defined Relocatable Expressions Relocatable Symbols Relocation Feature Reserved 5ymbols RESET Si f nal RET (Retl rn) Instruction REPT DirE ctive RIM (Read Interrupt Mask) 8085 Instruction RLC (Rot.5-18 3-48 3-49 3-50 3-57 3-57 1-5 3-52 3-52 3-53 3-53 3-54 . 3-49.5 RZ (Return if Zero) Instruction Savings Program Status SBB (Subtract with Borrow) Instruction SBI (Subtlact Immediate with Borrow) Instruction Scope of Symbols SET Direc:ive Shift Expression Operators Shift Opel ations in Expressions SHL Oper.2-76. 3-59.

3-35 4-10 3-62 3-63 4-18 3-63 6-3 . limited Permanent Redefinable Relocatable Reserved 3-35 3-67 7-7 2 1-19 1-13 1-72 4-79.7 .SP (Stack Pointer Register) STA (Store Accumulator Direct) Instruction Stack Stack and Machine Control Instructions Stack Operations Stack Pointer STACK Reserved Word Start Execution Address STAX (Store Accumulator Indirect) Instruction STC (Set Carry) Instruction STKLN Directive SUB (Subtract) Instruction Subroutine Data Subroutines Subroutines versus Macros Subtraction for Comparison SUI (Subtract Immediate) Instruction Symbol-Cross-Reference File Symbol Definition Symbol Table Symbol ic Addressing Symbols Symbols. Symbols. Symbols.72.1-3 4-2 2-9 2-9 2-9 2-11 2-9 2-10 2·10 2·11 2-11 2-11 2·9 TRAP Interrupt Ten's Complement Testing Relocatable Modules Timing Effects of Addressing Modes TRAP (8085) Two's Complement Data Use of Macros Using Symbols for Data Access Val ue of ExpreSSions What Word Word Work is a Macro? Instructions Storage in Memory Registers 3-54 2-7 4-19 1·16 3-23 2-7 5-1 4-7 2-15 5·2 7·27 4-4 1-7 \. 3-9 5-3 3-12 3-64 1-1. Symbols. Global Symbols. 1. Symbols. Absolute Symbols (Coding Rules) Symbols.

) (doubk semicolon) (divlslo 1) Operator (excian ation pOint) HT (horizo ltal tab character) (minus) Operator * (multiplication) Operator ( ) (parent 1eses) (plus) Operator + ??nnnn Svmbo s (semic( Ion) (single quote) (charac .XCHG (Excllange H & L with D & E) Instruction XOR Operator XRA (Exclu .er) space & 8080/8085 !)ifferences 8085 Featul es 8085 Proces .or 8085 Programming 3-65 2-73 3-66 3-67 3-69 7-77 5-10 5-10 2-2 2-2 2-2 5-10 2-12 5-10 2-2 2-12 2-12 2-2 2-12 5-5 2-2 2-2 2-2 7-24 1-24 7-24 1-24 1-8 .Ive OR) Instruction XRI (Exclus ve OR Immediate) Instruction XTHL (Exciange H & L with Top of Stack) Instruction Zero Flag (ampepand) <> (angle brackets) CR (carriag = return character) (colon) (comm.

NOTES .

.

NOTES .

Sign up to vote on this title
UsefulNot useful