Sunday 19 June 2016

Instruction Set 8085

  1. Control
  2. Logical
  3. Branching
  4. Arithmetic
  5. Data Transfer




Control Instructions


 Opcode OperandExplanation of Instruction Description
 NOPnoneNo operationNo operation is performed. The instruction is fetched and decoded. However no operation is executed.
Example: NOP
HLTnoneHalt and enter wait stateThe CPU finishes executing the current instruction and halts any further execution. An interrupt or reset is necessary to exit from the halt state.
Example: HLT
 DInoneDisable interrupts
The interrupt enable flip-flop is reset and all the interrupts except the TRAP are disabled. No flags are affected.
Example: DI
EInoneEnable interrupts
The interrupt enable flip-flop is set and all interrupts are enabled. No flags are affected. After a system reset or the acknowledgement of an interrupt, the interrupt enable flipflop is reset, thus disabling the interrupts. This instruction is
necessary to reenable the interrupts (except TRAP).
Example: EI
 RIMnoneRead interrupt mas
This is a multipurpose instruction used to read the status of interrupts 7.5, 6.5, 5.5 and read serial data input bit. The instruction loads eight bits in the accumulator with the following interpretations.
Example: RIM
SIMnoneSet interrupt mask
This is a multipurpose instruction and used to implement the 8085 interrupts 7.5, 6.5, 5.5, and serial data output. The instruction interprets the accumulator contents as follows.
Example: SIM


LOGICAL INSTRUCTIONS


 Opcode OperandExplanation of Instruction Description
 CMP
R
M
Compare register or memory with accumulator
The contents of the operand (register or memory) are M compared with the contents of the accumulator. Both contents are preserved . The result of the comparison is shown by setting the flags of the PSW as follows:
if (A) < (reg/mem): carry flag is set
if (A) = (reg/mem): zero flag is set
if (A) > (reg/mem): carry and zero flags are reset
Example: CMP B or CMP M
CPI8-bit dataCompare immediate with accumulator
The second byte (8-bit data) is compared with the contents of the accumulator. The values being compared remain unchanged. The result of the comparison is shown by setting the flags of the PSW as follows:
if (A) < data: carry flag is set
if (A) = data: zero flag is set
if (A) > data: carry and zero flags are reset
Example: CPI 89H
 ANA
R
M
Logical AND register or memory with accumulator
The contents of the accumulator are logically ANDed with M the contents of the operand (register or memory), and the result is placed in the accumulator. If the operand is a memory location, its address is specified by the contents of HL registers. S, Z, P are modified to reflect the result of the operation. CY is reset. AC is set.
Example: ANA B or ANA M
 ANI 8-bit dataLogical AND immediate with accumulator
The contents of the accumulator are logically ANDed with the
8-bit data (operand) and the result is placed in the
accumulator. S, Z, P are modified to reflect the result of the
operation. CY is reset. AC is set.
Example: ANI 86H
 XRA
R
M
Exclusive OR register or memory with accumulator
The contents of the accumulator are Exclusive ORed with M the contents of the operand (register or memory), and the result is placed in the accumulator. If the operand is a memory location, its address is specified by the contents of HL registers. S, Z, P are modified to reflect the result of the operation. CY and AC are reset.
Example: XRA B or XRA M
 XRI 8-bit dataExclusive OR immediate with accumulator
The contents of the accumulator are Exclusive ORed with the 8-bit data (operand) and the result is placed in the accumulator. S, Z, P are modified to reflect the result of the operation. CY and AC are reset.
Example: XRI 86H
ORA
R
M
Logical OR register or memory with accumulator
The contents of the accumulator are logically ORed with M the contents of the operand (register or memory), and the result is placed in the accumulator. If the operand is a memory location, its address is specified by the contents of HL registers. S, Z, P are modified to reflect the result of the operation. CY and AC are reset.
Example: ORA B or ORA M
ORI 8-bit dataLogical OR immediate with accumulator
The contents of the accumulator are logically ORed with the 8-bit data (operand) and the result is placed in the accumulator. S, Z, P are modified to reflect the result of the operation. CY and AC are reset.
Example: ORI 86H
RLC  noneRotate accumulator left
Each binary bit of the accumulator is rotated left by one position. Bit D7 is placed in the position of D0 as well as in the Carry flag. CY is modified according to bit D7. S, Z, P, AC are not affected.
Example: RLC
RRCnone Rotate accumulator right
Each binary bit of the accumulator is rotated right by one position. Bit D0 is placed in the position of D7 as well as in the Carry flag. CY is modified according to bit D0. S, Z, P, AC are not affected.
Example: RRC
 RAL noneRotate accumulator left through carry
Each binary bit of the accumulator is rotated left by one position through the Carry flag. Bit D7 is placed in the Carry flag, and the Carry flag is placed in the least significant position D0. CY is modified according to bit D7. S, Z, P, AC are not affected.
Example: RAL
 RAR  noneRotate accumulator right through carry
Each binary bit of the accumulator is rotated right by one position through the Carry flag. Bit D0 is placed in the Carry flag, and the Carry flag is placed in the most significant position D7. CY is modified according to bit D0. S, Z, P, AC are not affected.
Example: RAR
 CMA noneComplement accumulator
The contents of the accumulator are complemented. No flags are affected.
Example: CMA
CMC  noneComplement carry
The Carry flag is complemented. No other flags are affected.
Example: CMC
 STC noneSet Carry
Set Carry
Example: STC


BRANCHING INSTRUCTIONS


 Opcode OperandExplanation of Instruction Description
 JMP16-bit addressJump unconditionally
The program sequence is transferred to the memory location specified by the 16-bit address given in the operand.
Example: JMP 2034H or JMP XYZ

OpcodeDescriptionFlag Status
JCJump on CarryCY = 1
JNCJump on no CarryCY = 0
JPJump on positiveS = 0
JMJump on minusS = 1
JZJump on zeroZ = 1
JNZJump on no zeroZ = 0
JPEJump on parity evenP = 1
JPOJump on parity oddP = 0

 16-bit address
Jump conditionally
The program sequence is transferred to the memory location specified by the 16-bit address given in the operand based on the specified flag of the PSW as described below.
Example: JZ 2034H or JZ XYZ

OpcodeDescriptionFlag Status
CCCall on CarryCY = 1
CNCCall on no CarryCY = 0
CPCall on positiveS = 0
CMCall on minusS = 1
CZCall on zeroZ = 1
CNZCall on no zeroZ = 0
CPECall on parity evenP = 1
CPOCall on parity oddP = 0

 16-bit addressUnconditional subroutine call
The program sequence is transferred to the memory location specified by the 16-bit address given in the operand. Before the transfer, the address of the next instruction after CALL (the contents of the program counter) is pushed onto the stack.
Example: CALL 2034H or CALL XYZ
 RETnoneReturn from subroutine unconditionally
The program sequence is transferred from the subroutine to the calling program. The two bytes from the top of the stack are copied into the program counter,and program execution begins at the new address.
Example: RET

OpcodeDescriptionFlag Status
RCReturn on CarryCY = 1
RNCReturn on no CarryCY = 0
RPReturn on positiveS = 0
RMReturn on minusS = 1
RZReturn on zeroZ = 1
RNZReturn on no zeroZ = 0
RPEReturn on parity evenP = 1
RPOReturn on parity oddP = 0

noneReturn from subroutine conditionally
The program sequence is transferred from the subroutine to the calling program based on the specified flag of the PSW as described below. The two bytes from the top of the stack are copied into the program counter, and program execution begins at the new address.
Example: RZ
 PCHL noneLoad program counter with HL contents
 The contents of registers H and L are copied into the program counter. The contents of H are placed as the high-order byte and the contents of L as the low-order byte.
Example: PCHL
 RST

0-7Restart
The RST instruction is equivalent to a 1-byte call instruction to one of eight memory locations depending upon the number. The instructions are generally used in conjunction with interrupts and inserted using external hardware. However these can be used as software instructions in a program to transfer program execution to one of the eight locations. The addresses are:
InstructionRestart Address
RST 00000H
RST10008H
RST 20010H
RST 30018H
RST 40020H
RST 50028H
RST 60030H
RST 70038H

The 8085 has four additional interrupts and these interrupts generate RST instructions internally and thus do not require any external hardware. These instructions and their Restart addresses are:
InterruptRestart Address
TRAP0024H
RST 5.5002CH
RST 6.50034H
RST 7.5003CH



Arithmetic Instructions


 Opcode OperandExplanation of Instruction Description
 ADD
 R
M
Add register or memory, to accumulator
The contents of the operand (register or memory) are added to the contents of the accumulator and the result is stored in the accumulator. If the operand is a memory location, its location is specified by the contents of the HL registers. All flags are modified to reflect the result of the addition.
Example: ADD B or ADD M
 ADC
 R
M
Add register to accumulator with carry
The contents of the operand (register or memory) and M the Carry flag are added to the contents of the accumulator and the result is stored in the accumulator. If the operand is a memory location, its location is specified by the contents of the HL registers. All flags are modified to reflect the result of the addition.
Example: ADC B or ADC M
 ADI 8-bit dataAdd immediate to accumulator
The 8-bit data (operand) is added to the contents of the accumulator and the result is stored in the accumulator. All flags are modified to reflect the result of the addition.
Example: ADI 45H
 ACI8-bit dataAdd immediate to accumulator with carry
The 8-bit data (operand) and the Carry flag are added to the contents of the accumulator and the result is stored in the accumulator. All flags are modified to reflect the result of the addition.
Example: ACI 45H
 LXI Reg. pair, 16-bit dataLoad register pair immediate
The instruction loads 16-bit data in the register pair designated in the operand.
Example: LXI H, 2034H or LXI H, XYZ
 DAD Reg. pairAdd register pair to H and L registers
The 16-bit contents of the specified register pair are added to the contents of the HL register and the sum is stored in the HL register. The contents of the source register pair are not altered. If the result is larger than 16 bits, the CY flag is set. No other flags are affected.
Example: DAD H
SUB
 R
M
Subtract register or memory from accumulator
The contents of the operand (register or memory ) are subtracted from the contents of the accumulator, and the result is stored in the accumulator. If the operand is a memory location, its location is specified by the contents of the HL registers. All flags are modified to reflect the result of the subtraction.
Example: SUB B or SUB M
 SBB
 R
M
Subtract source and borrow from accumulator
The contents of the operand (register or memory ) and M the Borrow flag are subtracted from the contents of the accumulator and the result is placed in the accumulator. If the operand is a memory location, its location is specified by the contents of the HL registers. All flags are modified to reflect the result of the subtraction.
Example: SBB B or SBB M
 SUI 8-bit dataSubtract immediate from accumulator
The 8-bit data (operand) is subtracted from the contents of the accumulator and the result is stored in the accumulator. All flags are modified to reflect the result of the subtraction.
Example: SUI 45H
SBI  8-bit dataSubtract immediate from accumulator with borrow
The contents of register H are exchanged with the contents of register D, and the contents of register L are exchanged with the contents of register E.
Example: XCHG
 INR
 R
M
Increment register or memory by 1
The contents of the designated register or memory) are incremented by 1 and the result is stored in the same place. If the operand is a memory location, its location is specified by the contents of the HL registers.
Example: INR B or INR M
INX RIncrement register pair by 1
The contents of the designated register pair are incremented by 1 and the result is stored in the same place.
Example: INX H
 DCR
 R
M
Decrement register or memory by 1
The contents of the designated register or memory are M decremented by 1 and the result is stored in the same place. If the operand is a memory location, its location is specified by the contents of the HL registers.
Example: DCR B or DCR M
DCX RDecrement register pair by 1
The contents of the designated register pair are decremented by 1 and the result is stored in the same place.
Example: DCX H
DAA  noneDecimal adjust accumulator
The contents of the accumulator are changed from a binary value to two 4-bit binary coded decimal (BCD) digits. This is the only instruction that uses the auxiliary flag to perform the binary to BCD conversion, and the conversion procedure is described below. S, Z, AC, P, CY flags are altered to reflect the results of the operation.
If the value of the low-order 4-bits in the accumulator is greater than 9 or if AC flag is set, the instruction adds 6 to the low-order four bits.
If the value of the high-order 4-bits in the accumulator is greater than 9 or if the Carry flag is set, the instruction adds 6 to the high-order four bits.
Example: DAA


Data Transfer Instructions


 Opcode OperandExplanation of Instruction Description
 MOV
 Rd, Rs
M, Rs
Rd, M
Copy from source(Rs) to destination(Rd)
 This instruction copies the contents of the source register into the destination register; the contents of the source register are not altered. If one of the operands is a memory location, its location is specified by the contents of the HL registers.
Example: MOV B, C or MOV B, M
 MVI
 Rd, data
M, data
Move immediate 8-bit
The 8-bit data is stored in the destination register or memory. If the operand is a memory location, its location is specified by the contents of the HL registers.
Example: MVI B, 57H or MVI M, 57H
 LDA 16-bit addressLoad accumulator
The contents of a memory location, specified by a 16-bit address in the operand, are copied to the accumulator. The contents of the source are not altered.
Example: LDA 2034H
 LDAX B/D Reg. pairLoad accumulator indirect
The contents of the designated register pair point to a memory location. This instruction copies the contents of that memory location into the accumulator. The contents of either the register pair or the memory location are not altered.
Example: LDAX B
 LXI Reg. pair, 16-bit dataLoad register pair immediate
The instruction loads 16-bit data in the register pair designated in the operand.
Example: LXI H, 2034H or LXI H, XYZ
 LHLD 16-bit addressLoad H and L registers direct
 The instruction copies the contents of the memory location pointed out by the 16-bit address into register L and copies the contents of the next memory location into register H. The contents of source memory locations are not altered.
Example: LHLD 2040H
 STA 16-bit address16-bit address
The contents of the accumulator are copied into the memory location specified by the operand. This is a 3-byte instruction, the second byte specifies the low-order address and the third byte specifies the high-order address.
Example: STA 4350H
 STAX Reg. pairStore accumulator indirect
The contents of the accumulator are copied into the memory location specified by the contents of the operand (register pair). The contents of the accumulator are not altered.
Example: STAX B
 SHLD 16-bit addressStore H and L registers direct
The contents of register L are stored into the memory location specified by the 16-bit address in the operand and the contents of H register are stored into the next memory location by incrementing the operand. The contents of registers HL are not altered. This is a 3-byte instruction, the second byte specifies the low-order address and the third byte specifies the high-order address.
Example: SHLD 2470H
XCHG  noneExchange H and L with D and E
The contents of register H are exchanged with the contents of register D, and the contents of register L are exchanged with the contents of register E.
Example: XCHG
 SPHLnone Copy H and L registers to the stack pointer
The instruction loads the contents of the H and L registers into
the stack pointer register, the contents of the H register provide the high-order address and the contents of the L register provide the low-order address. The contents of the H
and L registers are not altered.
Example: SPHL
 XTHL noneExchange H and L with top of stack
The contents of the L register are exchanged with the stack location pointed out by the contents of the stack pointer register. The contents of the H register are exchanged with the next stack location (SP+1); however, the contents of the stack pointer register are not altered.
Example: XTHL
 PUSH Reg. pairPush register pair onto stack
The contents of the register pair designated in the operand are copied onto the stack in the following sequence. The stack pointer register is decremented and the contents of the highorder register (B, D, H, A) are copied into that location. The stack pointer register is decremented again and the contents of the low-order register (C, E, L, flags) are copied to that location.
Example: PUSH B or PUSH A
 POP Reg. pairPop off stack to register pair
The contents of the memory location pointed out by the stack pointer register are copied to the low-order register (C, E, L, status flags) of the operand. The stack pointer is incremented by 1 and the contents of that memory location are copied to the high-order register (B, D, H, A) of the operand. The stack pointer register is again incremented by 1.
Example: POP H or POP A
OUT  8-bit port addressOutput data from accumulator to a port with 8-bit address
 The contents of the accumulator are copied into the I/O port specified by the operand.
Example: OUT F8H
 IN 8-bit port addressInput data to accumulator from a port with 8-bit address
The contents of the input port designated in the operand are read and loaded into the accumulator.
Example: IN 8CH

Store 8-bit data in memory


  1. Program 1:
  2. MVI A, 52H : "Store 32H in the accumulator"
  3. STA 4000H : "Copy accumulator contents at address 4000H"
  4. HLT : "Terminate program execution"
  1. Program 2:
  2. LXI H : "Load HL with 4000H"
  3. MVI M : "Store 32H in memory location pointed by HL register pair (4000H)"
  4. HLT : "Terminate program execution"
Note: The result of both programs will be the same. In program 1 direct addressing instruction is used, whereas in program 2 indirect addressing instruction is used. 

Exchange the contents of memory locations


Statement: Exchange the contents of memory locations 2000H and 4000H.
  1. Program 1:
  2. LDA 2000H : "Get the contents of memory location 2000H into accumulator"
  3. MOV B, A : "Save the contents into B register"
  4. LDA 4000H : "Get the contents of memory location 4000Hinto accumulator"
  5. STA 2000H : "Store the contents of accumulator at address 2000H"
  6. MOV A, B : "Get the saved contents back into A register"
  7. STA 4000H : "Store the contents of accumulator at address 4000H"
  1. Program 2:
  2. LXI H 2000H : "Initialize HL register pair as a pointer to memory location 2000H."
  3. LXI D 4000H : "Initialize DE register pair as a pointer to memory location 4000H."
  4. MOV B, M : "Get the contents of memory location 2000H into B register."
  5. LDAX D : "Get the contents of memory location 4000H into A register."
  6. MOV M, A : "Store the contents of A register into memory location 2000H."
  7. MOV A, B : "Copy the contents of B register into accumulator."
  8. STAX D : "Store the contents of A register into memory location 4000H."
  9. HLT : "Terminate program execution."
Note: In Program 1, direct addressing instructions are used, whereas in Program 2, indirect addressing instructions are used. 

Add two 8-bit numbers


Statement: Add the contents of memory locations 4000H and 4001H and place the result in memory location 4002H.
  1. Sample problem
  2. (4000H) = 14H
  3. (4001H) = 89H
  4. Result = 14H + 89H = 9DH
  5. Source program
  6. LXI H 4000H : "HL points 4000H"
  7. MOV A, M : "Get first operand"
  8. INX H : "HL points 4001H"
  9. ADD M : "Add second operand"
  10. INX H : "HL points 4002H"
  11. MOV M, A : "Store result at 4002H"
  12. HLT : "Terminate program execution"


Subtract two 8-bit numbers


Statement: Subtract the contents of memory location 4001H from the memory location 2000H and place the result in memory location 4002H.
  1. Program –: Subtract two 8-bit numbers
  2. Sample problem:
  3. (4000H) = 51H
  4. (4001H) = 19H
  5. Result = 51H 19H = 38H
  6.  
  7. Source program:
  8. LXI H, 4000H : "HL points 4000H"
  9. MOV A, M : "Get first operand"
  10. INX H : "HL points 4001H"
  11. SUB M : "Subtract second operand"
  12. INX H : "HL points 4002H"
  13. MOV M, A : "Store result at 4002H"
  14. HLT : "Terminate program execution"


Add two 16-bit numbers


Statement: Add the 16-bit number in memory locations 4000H and 4001H to the 16-bit number in memory locations 4002H and 4003H. The most significant eight bits of the two numbers to be added are in memory locations 4001H and 4003H. Store the result in memory locations 4004H and 4005H with the most significant byte in memory location 4005H.
  1. Sample problem:
  2. (4000H) = 15H
  3. (4001H) = 1CH
  4. (4002H) = B7H
  5. (4003H) = 5AH
  6. Result = 1C15 + 5AB7H = 76CCH
  7. (4004H) = CCH
  8. (4005H) = 76H
  9.  
  10. Source Program 1:
  11. LHLD 4000H : "Get first I6-bit number in HL"
  12. XCHG : "Save first I6-bit number in DE"
  13. LHLD 4002H : "Get second I6-bit number in HL"
  14. MOV A, E : "Get lower byte of the first number"
  15. ADD L : "Add lower byte of the second number"
  16. MOV L, A : "Store result in L register"
  17. MOV A, D : "Get higher byte of the first number"
  18. ADC H : "Add higher byte of the second number with CARRY"
  19. MOV H, A : "Store result in H register"
  20. SHLD 4004H : "Store I6-bit result in memory locations 4004H and 4005H"
  21. HLT : "Terminate program execution"
  1. Source program 2:
  2. LHLD 4000H : Get first I6-bit number
  3. XCHG : Save first I6-bit number in DE
  4. LHLD 4002H : Get second I6-bit number in HL
  5. DAD D : Add DE and HL
  6. SHLD 4004H : Store I6-bit result in memory locations 4004H and 4005H.
  7. HLT : Terminate program execution
NOTE: In program 1, eight bit addition instructions are used (ADD and ADC) and addition is performed in two steps. First lower byte addition using ADD instruction and then higher byte addition using ADC instruction.In program 2, 16-bit addition instruction (DAD) is used. 

Add contents of two memory locations


Statement: Add the contents of memory locations 40001H and 4001H and place the result in the memory locations 4002Hand 4003H.
  1. Sample problem:
  2. (4000H) = 7FH
  3. (400lH) = 89H
  4. Result = 7FH + 89H = lO8H
  5. (4002H) = 08H
  6. (4003H) = 0lH
  7. Source program:
  8. LXI H, 4000H : "HL Points 4000H"
  9. MOV A, M : "Get first operand"
  10. INX H : "HL Points 4001H"
  11. ADD M : "Add second operand"
  12. INX H : "HL Points 4002H"
  13. MOV M, A : "Store the lower byte of result at 4002H"
  14. MVIA, 00 : "Initialize higher byte result with 00H"
  15. ADC A : "Add carry in the high byte result"
  16. INX H : "HL Points 4003H"
  17. MOV M, A : "Store the higher byte of result at 4003H"
  18. HLT : "Terminate program execution"


Subtract two 16-bit numbers


Statement: Subtract the 16-bit number in memory locations 4002H and 4003H from the 16-bit number in memory locations 4000H and 4001H. The most significant eight bits of the two numbers are in memory locations 4001H and 4003H. Store the result in memory locations 4004H and 4005H with the most significant byte in memory location 4005H.
  1. Sample problem:
  2. (4000H) = 19H
  3. (400IH) = 6AH
  4. (4004H) = I5H (4003H) = 5CH
  5. Result = 6A19H 5C15H = OE04H
  6. (4004H) = 04H
  7. (4005H) = OEH
  8. Source program:
  9. LHLD 4000H : "Get first 16-bit number in HL"
  10. XCHG : "Save first 16-bit number in DE"
  11. LHLD 4002H : "Get second 16-bit number in HL"
  12. MOV A, E : "Get lower byte of the first number"
  13. SUB L : "Subtract lower byte of the second number"
  14. MOV L, A : "Store the result in L register"
  15. MOV A, D : "Get higher byte of the first number"
  16. SBB H : "Subtract higher byte of second number with borrow"
  17. MOV H, A : "Store l6-bit result in memory locations 4004H and 4005H"
  18. SHLD 4004H : "Store l6-bit result in memory locations 4004H and 4005H"
  19. HLT : "Terminate program execution"



Finding one’s complement of a number


Statement: Find the l’s complement of the number stored at memory location 4400H and store the complemented number at memory location 4300H.
  1. Sample problem:
  2. (4400H) = 55H
  3. Result = (4300B) = AAB
  4. Source program:
  5. LDA 4400B : "Get the number"
  6. CMA : "Complement number"
  7. STA 4300H : "Store the result"
  8. HLT : "Terminate program execution"


Finding Two’s complement of a number


Statement: Find the 2′s complement of the number stored at memory location 4200H and store the complemented number at memory location 4300H
  1. Sample problem:
  2. (4200H) = 55H
  3. Result = (4300H) = AAH + 1 = ABH
  4. Source program:
  5. LDA 4200H : "Get the number"
  6. CMA : "Complement the number"
  7. ADI, 01 H : "Add one in the number"
  8. STA 4300H : "Store the result"
  9. HLT : "Terminate program execution"


Pack the unpacked BCD numbers


Statement: Pack the two unpacked BCD numbers stored in memory locations 4200H and 4201H and store result in memory location 4300H. Assume the least significant digit is stored at 4200H.
  1. Sample problem:
  2. (4200H) = 04
  3. (4201H) = 09
  4. Result = (4300H) = 94
  5. Source program:
  6. LDA 4201H : "Get the Most significant BCD digit"
  7. RLC
  8. RLC
  9. RLC
  10. RLC : "Adjust the position of the second digit (09 is changed to 90)"
  11. ANI FOH : "Make least significant BCD digit zero"
  12. MOV C, A : "store the partial result"
  13. LDA 4200H : "Get the lower BCD digit"
  14. ADD C : "Add lower BCD digit"
  15. STA 4300H : "Store the result"
  16. HLT : "Terminate program execution"


Unpack a BCD number


Statement: Two digit BCD number is stored in memory location 4200H. Unpack the BCD number and store the two digits in memory locations 4300H and 4301H such that memory location 4300H will have lower BCD digit.
  1. Sample problem:
  2. (4200H) = 58
  3. Result = (4300H) = 08 and
  4. (4301H) = 05
  5. Source program:
  6. LDA 4200H : "Get the packed BCD number"
  7. ANI FOH : "Mask lower nibble"
  8. RRC
  9. RRC
  10. RRC
  11. RRC : "Adjust higher BCD digit as a lower digit"
  12. STA 4301H : "Store the partial result"
  13. LDA 4200H : "Get the original BCD number"
  14. ANI OFH : "Mask higher nibble"
  15. STA 4201H : "Store the result"
  16. HLT : "Terminate program execution"


Execution format of instructions


Statement: Read the program given below and state the contents of all registers after the execution of each instruction in sequence.
  1. Main program:
  2. 4000H LXI SP, 27FFH
  3. 4003H LXI H, 2000H
  4. 4006H LXI B, 1020H
  5. 4009H CALL SUB
  6. 400CH HLT
  7. Subroutine program:
  8. 4100H SUB: PUSH B
  9. 4101H PUSH H
  10. 4102H LXI B, 4080H
  11. 4105H LXI H, 4090H
  12. 4108H SHLD 2200H
  13. 4109H DAD B
  14. 410CH POP H
  15. 410DH POP B
  16. 410EH RET


Right shift, bit of data( 8 bit and 16 bit)


Statement: Write a program to shift an eight bit data four bits right. Assume data is in register C.
  1. Sample problem:
  2. (4200H) = 58
  3. Result = (4300H) = 08 and
  4. (4301H) = 05
  5.  
  6. Source program 1:
  7. MOV A, C
  8. RAR
  9. RAR
  10. RAR
  11. RAR
  12. MOV C, A
  13. HLT
Statement: Write a program to shift a 16 bit data, 1 bit right. Assume that data is in BC register pair.
  1. Source program 2
  2. MOV A, B
  3. RAR
  4. MOV B, A
  5. MOV A, C
  6. RAR
  7. MOV C, A
  8. HLT


Left Shifting of a 16-bit data


Statement: Program to shift a 16-bit data 1 bit left. Assume data is in the HL register
  1. HL = 1025 = 0001 0000 0010 0101
  2.  
  3. HL = 0001 0000 0010 0101
  4. + HL = 0001 0000 0010 0101
  5. ----------------------------
  6. Result = 0010 0000 0100 1010


Alter the contents of flag register in 8085


Statement: Write a set of instructions to alter the contents of flag register in 8085.
  1. PUSH PSW : "Save flags on stack"
  2. POP H : "Retrieve flags in ‘L’"
  3. MOV A, L : "Flags in accumulator"
  4. CMA : "Complement accumulator"
  5. MOV L, A : "Accumulator in ‘L’"
  6. PUSH H : "Save on stack"
  7. POP PSW : "Back to flag register"
  8. HLT : "Terminate program execution"

Programs For 8085 Microprocessor Level 2

Count number of one’s in a number


Statement: Write a program to count number of l’s in the contents of D register and store the count in the B register.
Sample problem
(2200H) =  04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) = 56H
Result = (2202H) = A9H
  1. MVI B, 00H
  2. MVI C, 08H
  3. MOV A, D
  4. BACK: RAR
  5. JNC SKIP
  6. INR B
  7. SKIP: DCR C
  8. JNZ BACK
  9. HLT


Arrange in ascending order


Statement: Write a program to sort given 10 numbers from memory location 2200H in the ascending order.
  1. MVI B, 09 :"Initialize counter"
  2. START :"LXI H, 2200H: Initialize memory pointer"
  3. MVI C, 09H :"Initialize counter 2"
  4. BACK: MOV A, M :"Get the number"
  5. INX H :"Increment memory pointer"
  6. CMP M :"Compare number with next number"
  7. JC SKIP :"If less, don’t interchange"
  8. JZ SKIP :"If equal, don’t interchange"
  9. MOV D, M
  10. MOV M, A
  11. DCX H
  12. MOV M, D
  13. INX H :"Interchange two numbers"
  14. SKIP:DCR C :"Decrement counter 2"
  15. JNZ BACK :"If not zero, repeat"
  16. DCR B :"Decrement counter 1"
  17. JNZ START
  18. HLT :"Terminate program execution"

Calculate the sum of series of even numbers


Statement: Calculate the sum of series of even numbers from the list of numbers. The length of the list is in memory location 2200H and the series itself begins from memory location 2201H. Assume the sum to be 8 bit number so you can ignore carries and store the sum at memory location 2210H.
Sample problem
2200H= 4H
2201H= 20H
2202H= l5H
2203H= l3H
2204H= 22H
Result 22l0H= 20 + 22 = 42H
= 42H
  1. LDA 2200H
  2. MOV C, A :"Initialize counter"
  3. MVI B, 00H :"sum = 0"
  4. LXI H, 2201H :"Initialize pointer"
  5. BACK: MOV A, M :"Get the number"
  6. ANI 0lH :"Mask Bit l to Bit7"
  7. JNZ SKIP :"Don’t add if number is ODD"
  8. MOV A, B :"Get the sum"
  9. ADD M :"SUM = SUM + data"
  10. MOV B, A :"Store result in B register"
  11. SKIP: INX H :"increment pointer"
  12. DCR C :"Decrement counter"
  13. JNZ BACK :"if counter 0 repeat"
  14. STA 2210H :"store sum"
  15. HLT :"Terminate program execution"


Calculate the sum of series of odd numbers


Statement: Calculate the sum of series of odd numbers from the list of numbers. The length of the list is in memory location 2200H and the series itself begins from memory location 2201H. Assume the sum to be 16-bit. Store the sum at memory locations 2300H and 2301H.
Sample problem
2200H = 4H
2201H= 9AH
2202H= 52H
2203H= 89H
2204H= 3FH
Result = 89H + 3FH = C8H
2300H= H Lower byte
2301H = H Higher byte
  1. Source program :
  2. LDA 2200H
  3. MOV C, A :"Initialize counter"
  4. LXI H, 2201H :"Initialize pointer"
  5. MVI E, 00 :"Sum low = 0"
  6. MOV D, E :"Sum high = 0"
  7. BACK: MOV A, M :"Get the number"
  8. ANI 0lH :"Mask Bit 1 to Bit7"
  9. JZ SKIP :"Don’t add if number is even"
  10. MOV A, E :"Get the lower byte of sum"
  11. ADD M :"Sum = sum + data"
  12. MOV E, A :"Store result in E register"
  13. JNC SKIP
  14. INR D :"Add carry to MSB of SUM"
  15. SKIP: INX H :"Increment pointer"


Find the square of given number


Statement: Find the square of the given numbers from memory location 6100H and store the result from memory location 7000H.
Sample problem
2200H = 4H
2201H= 9AH
2202H= 52H
2203H= 89H
2204H= 3FH
Result = 89H + 3FH = C8H
2300H= H Lower byte
2301H = H Higher byte
  1. LXI H, 6200H :"Initialize lookup table pointer"
  2. LXI D, 6100H :"Initialize source memory pointer"
  3. LXI B, 7000H :"Initialize destination memory pointer"
  4. BACK: LDAX D :"Get the number"
  5. MOV L, A :"A point to the square"
  6. MOV A, M :"Get the square"
  7. STAX B :"Store the result at destination memory location"
  8. INX D :"Increment source memory pointer"
  9. INX B :"Increment destination memory pointer"
  10. MOV A, C
  11. CPI 05H :"Check for last number"
  12. JNZ BACK :"If not repeat"
  13. HLT :"Terminate program execution"

Search a byte in a given number


Statement: Search the given byte in the list of 50 numbers stored in the consecutive memory locations and store the address of memory location in the memory locations 2200H and 2201H. Assume byte is in the C register and starting address of the list is 2000H. If byte is not found store 00 at 2200H and 2201H.
  1. LX I H, 2000H :"Initialize memory pointer 52H"
  2. MVI B, 52H :"Initialize counter"
  3. BACK: MOV A, M :"Get the number"
  4. CMP C :"Compare with the given byte"
  5. JZ LAST :"Go last if match occurs"
  6. INX H :"Increment memory pointer"
  7. DCR B :"Decrement counter"
  8. JNZ B :"If not zero, repeat"
  9. LXI H, 0000H
  10. SHLD 2200H
  11. JMP END :"Store 00 at 2200H and 2201H"
  12. LAST: SHLD 2200H :"Store memory address"
  13. END: HLT :"Stop"


Add two decimal numbers of 6 digit each


Statement: Two decimal numbers six digits each, are stored in BCD package form. Each number occupies a sequence of byte in the memory. The starting address of first number is 6000H Write an assembly language program that adds these two numbers and stores the sum in the same format starting from memory location 6200H.
  1. LXI H, 6000H :"Initialize pointer l to first number"
  2. LXI D, 6l00H :"Initialize pointer2 to second number"
  3. LXI B, 6200H :"Initialize pointer3 to result"
  4. STC
  5. CMC :"Carry = 0"
  6. BACK: LDAX D :"Get the digit"
  7. ADD M :"Add two digits"
  8. DAA :"Adjust for decimal"
  9. STAX.B :"Store the result"
  10. INX H :"Increment pointer 1"
  11. INX D :"Increment pointer2"
  12. INX B :"Increment result pointer"
  13. MOV A, L
  14. CPI 06H :"Check for last digit"
  15. JNZ BACK :"If not last digit repeat"
  16. HLT :"Terminate program execution"

Separate even numbers from given numbers


Statement: Write an assembly language program to separate even numbers from the given list of 50 numbers and store them in the another list starting from 2300H. Assume starting address of 50 number list is 2200H.
  1. LXI H, 2200H :"Initialize memory pointer l"
  2. LXI D, 2300H :"Initialize memory pointer2"
  3. MVI C, 32H :"Initialize counter"
  4. BACK:MOV A, M :"Get the number"
  5. ANI 0lH :"Check for even number"
  6. JNZ SKIP :"If ODD, don’t store"
  7. MOV A, M :"Get the number"
  8. STAX D :"Store the number in result list"
  9. INX D :"Increment pointer 2"
  10. SKIP: INX H :"Increment pointer l"
  11. DCR C :"Decrement counter"
  12. JNZ BACK :"If not zero, repeat"
  13. HLT :"Stop


Transfer contents to overlapping memory blocks


Statement: Write assembly language program with proper comments for the following:
A block of data consisting of 256 bytes is stored in memory starting at 3000H. This block is to be shifted (relocated) in memory from 3050H onwards. Do not shift the block or part of the block anywhere else in the memory.
Two blocks (3000 – 30FF and 3050 – 314F) are overlapping. Therefore it is necessary to transfer last byte first and first byte last.
  1. MVI C, FFH :"Initialize counter"
  2. LX I H, 30FFH :"Initialize source memory pointer 3l4FH"
  3. LXI D, 314FH :"Initialize destination memory pointer"
  4. BACK: MOV A, M :"Get byte from source memory block"
  5. STAX D :"Store byte in the destination memory block"
  6. DCX H :"Decrement source memory pointer"
  7. DCX :"Decrement destination memory pointer"
  8. DCR C :"Decrement counter"
  9. JNZ BACK :"If counter 0 repeat"
  10. HLT :"Stop execution"