Microprocessor & Assembly Language by Shmdch ARU
Microprocessor & Assembly Language by Shmdch ARU
1. A (Accumulator) register
2. F Flag register (Flag flip-flops)
3. B register
4. C register
5. D register
6. E register
7. H register
8. L register
8085 Microprocessor Architecture
• Registers B, C, D, E, H and L registers are 8-bit general purpose registers.
These registers can either be used as single register store 8-bit data for
processing or a combination of two registers as 16 bit register pair. The
valid register pairs are B-C, D-E or H-L register pairs. The higher order
byte of 16 bit data is stored in first register (B in B-C register pair), and low
order byte in the second register (C in B C register pair).
• The H-L register pair can also be used for register indirect addressing and
data pointer. The large number of general purpose registers gives more
flexibility and ease in the programming. However, the general purpose
registers are limited as registers occupy more space on the silicon chip.
• Beside these general purpose registers, the 8085 has two 8-bit registers
Accumulator (A) and Flag (F) as special purpose registers and two 16 bit
registers namely Program counter (PC) and stack pointer (SP).
8085 Microprocessor Architecture …
➢Accumulator (A) is an 8 bit register which stores the results of
arithmetical and logical operations. It is also used to receive data from
input port to microprocessor and to send data to output port from
microprocessor. It is referred as register A in the program.
➢Flag Register (F) is also an 8 bit register which indicate status of the
accumulator after any arithmetical or logical operation. Out of 8 bits,
five are defined as flags. These flags are given below.
8085 Microprocessor Architecture …
➢ Sign Flag (S): It indicates the sign of the number. If the number is negative
then sign flag is set (changed to 1) and if positive then reset (changed to 0).
➢ Zero Flag (Z): If after any arithmetical or logical operation, all the bits in
accumulator are zero then zero flag is set otherwise reset.
➢ Auxiliary Carry Flag (AC): If carry is generated from D3 to D4 in the
accumulator after any operation then auxiliary carry flag is set otherwise reset.
This flag is used internally by microprocessor for BCD operations and cannot be
used by the programmer.
➢ Parity Flag (P): If after any arithmetical or logical operation number of 1’s in
accumulator are even, then parity flag is set, otherwise reset.
➢ Carry Flag (CY): The size of accumulator is 8 bit. If after any operation 9th bit
is generated then carry flag is set, otherwise reset.
8085 Microprocessor Architecture …
➢Program counter: is a 16 bit register which is also known as memory pointer. It
stores the address of the next byte of the program to be executed. The
microprocessor takes the address from program counter and executes
instruction at that address. Each time the address in program counter is
incremented by one.
➢Stack Pointer (SP): It is a 16 bit register which contains the memory address of
top of the stack. Stack is a part of memory which is used to store data
temporarily, especially while the execution of subroutines or functions.
8085 Microprocessor Architecture …
• Arithmetic and Logic Unit (ALU)
The arithmetic and logical unit (ALU) basically consists of
accumulator (A), flag register (F) and a temporary register (which is
inaccessible by the programmer or user). This unit carries out the
arithmetic and logic calculations of the data stored in general
purpose registers or in memory locations. The arithmetic operations
are ADD, SUB, compare, increments, decrements and complements
etc.; while logical operations are AND, OR, XOR and Rotate. The
result of these operations could be placed in the accumulator or
elsewhere through the internal bus. Arithmetic operations are usually
carried out in 2’s complement and for these operations the ALU
receives the control signals from the timing and control unit.
8085 Microprocessor Architecture …
• Timing and Control Unit
This unit is responsible to synchronize Microprocessor operation as
per the clock pulse and to generate the control signals which are
necessary for smooth communication between Microprocessor and
peripherals devices. The RD bar and WR bar signals are synchronous
pulses which indicates whether data is available on the data bus or
not. The control unit is responsible to control the flow of data
between microprocessor, memory and peripheral devices.
8085 Microprocessor Architecture …
Table (1): Pins Description of 8085 μp
Table (1): Pins Description of 8085 μp
Table (1): Pins Description of 8085 μp
Table (1): Pins Description of 8085 μp
Chapter 3: Addressing Modes
What is Addressing Mode?
• Addressing mode specify how an instruction identifies the data, or
operands. It operates on in assembly language. This field indicates
whether the operand is a direct value, a memory address, or stored
in a register. Addressing modes are important during instruction
execution, as they define the form of an operand and the way data
is accessed, making sure proper data handling at the machine level.
Types of Addressing Modes
a. Data Addressing
b. Register Addressing
c. Immediate Addressing
d. Direct Addressing
e. Register indirect Addressing
• Immediate Addressing: In this type of addressing, the operand given in
the instruction a byte or word transfers to the destination register or
memory location.
Example:
MVI A,9AH
MVI AX, 0500H
✓ The operand is part of instruction
✓ The operand is stored in the register mentioned in the instruction.
• Memory direct Addressing: In this addressing moves a byte or word
between register or memory location.
Example:
LDA 856H; instruction used to load the content of memory address
8560H in accumulator.
Register Direct Addressing:
✓ Register direct addressing transfer a copy of a byte or word between
source register to destination register. Both operands in this particular
addressing mode are registers
Example:
MOV B,C; it copies the content of register C to register B and store in B
MOV BX, CX; it copies the content of register CX to register BX and store
in BX.
✓ Register Indirect Addressing: In this addressing transfer a byte or word
between register and memory location.
Example:
MOV AX,M; data in the memory location pointed to by the contents of HL
pair. The data is moved to accumulator.
MOV CX, [BX]; data transfer a byte b/n register and memory location
MOV AX,[SI];
Direct Addressing Mode
✓indicates that the value is immediately fixed and immutably entered into the
instruction.
✓ is the most straightforward of all the addressing techniques.
Examples:
MOV AX, [5000H]
• The square brackets around the 5000H imply the contents of the memory
location. When it is executed, this instruction will copy the contents of the
memory location into the AX register.
• Register Indirect Addressing Mode
• The base register, source index, or destination index (BX, SI, or DI register,
respectively) contains the offset address of the data. Either DS or ES are the
Lesson: outlines
❖Data movement instruction
✓Push/POP
✓Load effective Address
✓String Data Transfer
❖Arithmetic and Logical Instructions
✓Arithmetic instructions
✓Basic Logic instructions
✓Shift and rotate
✓String compression
Instruction Set of 8086
• An instruction is a binary pattern designed inside a microprocessor to
perform a specific function.
• The entire group of instructions that a microprocessor supports is called
Instruction Set.
• 8086 has more than 20,000instructions.
Classification of Instruction Set
✓ Data Transfer Instructions
✓ Arithmetic Instructions
✓ Logical Instructions
✓ Control Transfer Instructions
✓ String Manipulation Instructions
✓ Processor Control Instructions
Data Movement Instructions
✓Are used to transfer data from source to destination.
✓The operand can be a constant, memory location, register or I/O port
address.
MOV Des, Src:
✓Src operand can be register, memory location or immediate operand.
✓Des can be register or memory operand.
✓Both Src and Des cannot be memory location at the same time.
E.g.:
MOV CX, 037A H; The content of CX is changed with 037A hex value.
MOV AL, BL; The content of AL is changed with content of BL
MOV BX, [0301 H]; The content of BX is changed with content location
[0301H]
Data movement
PUSH Operand:
• It pushes the operand into top of stack.
Example: PUSH BX
POP Destiny:
• It pops the operand from top of stack to Des.
• Destiny can be a general purpose register, segment register (except
CS) or memory location.
Example : POP AX
XCHG Des, Src:
• This instruction exchanges Src with Des.
• It cannot exchange two memory locations directly.
• Example: XCHG DX, AX
IN Accumulator, Port Address:
• It transfers the operand from specified port to accumulator register.
E.g.: IN AX, 0028 H
OUT Port Address, Accumulator:
• It transfers the operand from accumulator to specified port.
E.g.: OUT 0028 H, AX
LEA Register, Src:
• It loads a 16-bit register with the offset address of the data specified
by the Src.
E.g.: LEA BX, [DI]
• This instruction loads the contents of DI (offset) into the BX register.
Arithmetic Instructions
ADD Des, Src:
Arithmetic
• It adds a byte to byte or a word to word. ➢Addition
• It effects AF, CF, OF, PF, SF, ZF flags. ➢Subtraction
E.g.:
ADD AL, 74H ➢Multiplication
ADD DX, AX ➢Division
ADD AX, [BX]
➢Increment
ADC Des, Src:
• It adds the two operands with CF (Des = Des + Src + C). ➢Decrement
• It effects AF, CF, OF, PF, SF, ZF flags.
Example:
ADC AL, 74H
ADC DX, AX
ADC AX, [BX]
Mnemonic Description Mnemonic Description
Divide A by B
ADD A,Rn AA+Rn DIV AB Aquotient
B remainder
ADD A,direct AA+(direct) DEC A AA-1
ADD A, @Ri AA+@Ri DEC Rn RnRn-1
ADDC A, direct AA+(direct)+C SUBB A,Rn AA-Rn-C
ADDC A, #data AA+data+C SUBB A,@Ri AA-@Ri-C
Multiply A by B
ADDC A,Rn AA+Rn+C MUL AB Alow byte (A*B)
B high byte (A*B)
Logical instruction
AND, OR, NOT, XOR, NEG
• AND Des, Src:
• It performs AND operation of Des and Src.
• Src can be immediate number, register or memory location.
• Des can be register or memory location.
• Both operands cannot be memory locations at the same time.
• CF and OF become zero after the operation.
• PF, SF and ZF are updated.
OR Des, Src:
• It performs OR operation of Des and Src.
• Src can be immediate number, register or memory location.
• Des can be register or memory location.
• Both operands cannot be memory locations at the same time.
• CF and OF become zero after the operation.
• PF, SF and ZF are updated.
XOR Des, Src:
• It performs XOR operation of Des and Src.
• Src can be immediate number, register or memory location.
• Des can be register or memory location.
• Both operands cannot be memory locations at the same time.
• CF and OF become zero after the operation.
• PF, SF and ZF are updated.
SHL Des, Count:
• It shift bits of byte or word left, by count.
• It puts zero(s) in LSBs.
• MSB is shifted into carry flag.
• If the number of bits desired to be shifted is 1, then the immediate number 1
can be written in Count.
SHR Des, Count:
• It shift bits of byte or word right, by count.
• It puts zero(s) in MSBs.
• LSB is shifted into carry flag.
• If the number of bits desired to be shifted is 1, then the immediate number 1
can be written in Count.
NB: However, if the number of bits to be shifted is more than 1, then the
count is put in CL register.
ROL Des, Count:
• It rotates bits of byte or word left, by count.
• MSB is transferred to LSB and also to CF.
ROR Des, Count:
• It rotates bits of byte or word right, by count.
• LSB is transferred to MSB and also to CF.
NB:
✓However, if the number of bits to be shifted is more than 1, then the count
is put in CL register.
✓If the number of bits desired to be shifted is 1, then the immediate
number 1 can be written in Count.
Logical ins.
Mnemonic Description Mnemonic Description
Divide A by B
ANL A,Rn AA ANDRn Aquotient
B remainder
ANL A,@Ri AA AND @Ri AA-1
ANL A,direct AA AND @Ri RnRn-1
ANL A, @direct AA AND @direct AA-Rn-C
ANL direct,A (direct)(direct ) AA-@Ri-C
AND A
ANL A, #data Multiply A by B
AA+Rn+C Alow byte (A*B)
B high byte (A*B)
A
N
D
O
R
Chapter 5: Control Transfer Instructions
Lesson Outlines
❖The Jump Group
✓ Unconditional Jump (JMP) ❖ Introduction to Interrupts
✓ Conditional Jumps and Conditional Sets
✓ Interrupt Vectors
❖Controlling the Flow of the Program
✓ Interrupt Instructions
✓ LOOP
✓ Interrupt Control
✓ REPEAT
❖ Machine Control and Miscellaneous Instructions
❖ Procedures
✓ Flag Control Instructions
✓ CALL
✓ RET ✓ WAIT
✓ HLT
Control Transfer Instructions
These instructions cause change in the sequence of the execution of
instruction.
✓This change can be through a condition or sometimes unconditional.
✓The conditions are represented by flags.
CALL Des:
✓This instruction is used to call a subroutine or function or procedure.
✓The address of next instruction after CALL is saved onto stack.
RET:
✓It returns the control from procedure to calling program.
✓Every CALL instruction should have a RET.
Loop Des:
• This is a looping instruction.
• The number of times looping is required is placed in the CX register.
• With each iteration, the contents of CX are decremented.
• ZF is checked whether to loop again or not.
• String in assembly language is just a sequentially stored bytes or words.
• There are very strong set of string instructions in 8086.
• By using these string instructions, the size of the program is considerably
reduced.
CMPS Des, Src:
• It compares the string bytes or words.
SCAS String:
• It scans a string.
• It compares the String with byte in AL or with word in AX.
MOVS / MOVSB / MOVSW:
• It causes moving of byte or word from one string to another.
• In this instruction, the source string is in Data Segment and
destination string is in Extra Segment.
• SI and DI store the offset values for source and destination index.
REP (Repeat):
• This is an instruction prefix.
• It causes the repetition of the instruction until CX becomes zero.
Example: REP MOVSB STR1, STR2
• It copies byte by byte contents.
• REP repeats the operation MOVSB until CX becomes zero.
STC:It sets the carry flag to 1.
CLC: It clears the carry flag to 0.
CMC: It complements the carry flag.
STD: It sets the direction flag to 1.
• If it is set, string bytes are accessed from higher memory address to lower memory address.
CLD:
• It clears the direction flag to 0.
• If it is reset, the string bytes are accessed from lower memory address to higher memory address.
THE JUMP GROUP
JUM
➔Allows programmer to skip program sections and branch to any part of
memory for the next instruction.
➔A conditional jump instruction allows decisions based upon numerical tests.
➔results are held in the flag bits, then tested by conditional jump instructions
•LOOP and conditional LOOP are also forms of the jump instruction.
Unconditional Jump (JMP)
• Three types: short jump, near jump, far jump.
• Short jump is a 2-byte instruction that allows jumps or branches to
memory locations within +127 and –128 bytes.
–> from the address following the jump
3-byte near jump allows a branch or jump within ±32K bytes from the
instruction in the current code segment.
✓5-byte far jump allows a jump to any memory location within the real
memory system.
✓The short and near jumps are often called intrasegment jumps.
✓Far jumps are called intersegment jumps
Unconditional Jump (JMP)
•Three types: short jump, near jump, far jump.
•Short jump is a 2-byte instruction that allows jumps or branches to
memory locations within +127 and –128 bytes.
–from the address following the jump
•3-byte near jump allows a branch or jump within ±32K bytes from the
instruction in the current code segment.
•5-byte far jump allows a jump to any memory location within the real
memory system.
•The short and near jumps are often called intrasegment jumps.
•Far jumps are called intersegment jumps
Short Jump
•Called relative jumpsbecause they can be moved, with related software, to
any location in the current code segment without a change.
–jump address is not stored with the opcode
–a distance, or displacement, follows the opcode
•The short jump displacement is a distance represented by a 1-byte signed
number whose value ranges between +127 and –128.
•Short jump instruction appears in Figure 2
–when the microprocessor executes a
short jump, the displacement is sign-
extended and added to the instruction
pointer (IP/EIP) to generate the jump
address within the current code segment