Instructions are used in programming think of it as an syntax

Data Transfer Group

  1. MVI (Move Immediately) - It is used to Initialize a register, or add data into a register
    • Syntax MVI (register), (data), e.g.: MVI B, 25H
  2. LXI (Load Immediately) - It is used to load data in Register Pair(If we see X in instruction it means it handles movement of register pairs not a single register)
    • Syntax LXI (register_pair), (data), e.g.: LXI B, 2000H
  3. MVI M, data - It is move Immediately but here M signifies the address location which is pointing HL Pair, e.g.: MVI M, 25H. Here 25H will be stored in the location which is point address of HL Pair
  4. MOV (Move) - It copies the data from one register to another register
    • Syntax MOV (destination_register), (source_register), e.g.: MOV B,C
  5. MOV (register), M - It is move but here M signifies the address location which is pointing HL Pair, e.g.: MOV B, M. Here the data of M will which is address pointing to HL Pair will be stored in the B register
  6. MOV M, (register) - It is move but here M signifies the address location which is pointing HL Pair, e.g.: MOV M, B. Here the data of B will be stored in the M which points to address of HL Pair
  7. LDA (Load A) - In this we will load the data into A register
    • Syntax LDA (address/data), e.g.: LDA 2000H. Here 2000H is address not data because there is no I in the instruction and 2000H is of 16-bit number it can’t be stored in 8-bit register A
  8. STA (Store A) - In this we will copy the value of A at the given address
    • Syntax STA (address), e.g.: STA 3000H. Here we store the data present in A register at the 3000H address
  9. LDAX (Load A with register pair address) - In this we will store the address location of the register pair in X
    • Syntax LDAX (register_pair), e.g.: LDAX B. Here the address of the BC Pair is stored in A register
    • LDAX H doesn’t exist as we can do the same with MOV A, M so LDAX H is an invalid Instruction
  10. STAX (Store A with register pair address) - In this we will store the data in A register into register pair
    • Syntax STAX (register_pair), e.g.: STAX B. Here the data in the A Register is stored in the BC Pair
    • STAX H doesn’t exist as we can do the same with MOV M, A so STAX H is an invalid Instruction
  11. LHLD (Load HL Direct addressing) - In this we store the data of two 8-bit address into the HL Pair
    • Syntax LHLD (address), e.g.: LHLD 2000H. Here in this we store the data at addresses 2000 and 2001 in the HL Pair.
    • It’s 2000 and 2001 addresses not 2000H data because there is no X in the instruction
    • It’s data of 2000 and 2001 address because the HL Pair is of 16-bit so we need to store data of 16-bit, so we store data from two consecutive locations
    • And the data from 2000 will go into L register and 2001 data will go into H register it is due to Little Indian Rule.
  12. SHLD (Store HL Pair Directly) - It means we store the data of HL Pair
    • Syntax SHLD (address), e.g.: SHLD 3000H. Here we store the data in HL Pair into 3000 and 3001 locations
  13. PCHL (Program Counter HL Pair) - It this we store the data of HL Pair in Program Counter
  14. SPHL (Stack Pointer HL Pair) - It this we store the data of HL Pair in Stack Pointer
  15. XCHG - It interchanges the values of HL and DE pairs
  16. XTHL (Exchange top with HL) - It’s doesn’t change the SP and HL. SP is the address of the data present in the top of the stack. Rather It means to swap the data Pointed by the SP and SP + 1 (as HL is of 16-bit and data of SP is of 8-bit) into HL Pair
    • But the interchanging happens differently here
    • In other instructions it is copy and paste but it’s not the same here
    • First the data in SP goes in Z and SP + 1 goes in W
    • Next the data in L will be overwritten in SP and data in H is overwritten in SP + 1
    • Next the data from Z will be overwritten in L and data from W will be overwritten in H. Here the W and Z are temporary register for more context see 8085 Architecture.

Arithmetic Instructions Group

  1. ADD - It is used add the value of register in the A register
    • Syntax ADD (register), e.g.: ADD B. It will accumulate the value in B register and the value in A register in A register, A = A + B
    • Here A + B can end up being 9 bits so need to handle carry bit in the code
    • We can also consider it as Half Adder
  2. ADD M - It is used to add the contents of M register into A register, e.g.: ADD M. Here it adds the value of M register and A register and put in A register. The M register holds the address of the value of HF register, A = A + M
  3. ADI - It is used to add Immediate Data into the A register
    • Syntax ADI (data), e.g.: ADI 25H. Here in this we are using Immediate Addressing Mode and Adding the Data directly into A register rather giving Address A = A + 25H
    • Here we need to handle borrows as A - B can end up giving an borrow
  4. SUB - It is used Subtract the value of register in the A register
    • Syntax SUB (register), e.g.: SUB B. It will subtract the value in B register from the value in A register in A register, A = A - B
  5. SUB M - It is used to subtract the contents of M register from A register, e.g.: SUB M. Here it subtracts the value of M register from A register and put in A register. The M register holds the address of the value of HF register, A = A - M
  6. SUI -It is used to subtract Immediate Data from the A register
    • Syntax SUI (data), e.g.: SUI 25H. Here in this we are using Immediate Addressing Mode and Subtracting the Data directly from A register rather giving Address A = A - 25H
  7. ADC - Add with Carry is used to add the number to A register which includes carry, which is generated from the Addition that took place before
    • Syntax ADD B, e.g.: Here in this B is an addition of two 8-bit numbers having a carry and we add it in A register, A = A + B + Carry_Flag
    • This will usually appear when adding two 16-bit numbers, as we need to consider carry coming from Lower two 8-bit additions
    • We can also consider it as Full Adder
  8. ADC M - It is used to Add the value of M register with A register and store it in A register. The M register holds the address of the value of HF register, A = A + M + Carry_Flag
  9. ACI - It is used to add the data directly using Immediate Addressing Mode along with the Carry Flag
    • Syntax ACI 25H, e.g.: Here we add the data 25H along with Carry in A register, A = A + 25H + Carry_Flag
  10. SBB - Subtract with Borrow is used to subtract the number from A register which includes borrow, which is generated from the Subtraction that took place before
    • Syntax SBB B, e.g.: Here in this B is an subtraction result of two 8-bit numbers having a borrow and we subtract it from A register, A = A - B - Carry_Flag
    • This will usually appear when we’re subtracting two 16-bit numbers, as we need to consider borrow coming from Lower two 8-bit subtractions
  11. SBC M - It is used to Subtract the value of M register from A register and store it in A register. The M register holds the address of the value of HF register, A = A - M - Carry_Flag
  12. SBI - It is used to subtract the data directly using Immediate Addressing Mode along with the Borrow Flag
    • Syntax SBI 25H, e.g.: Here we subtract the data 25H along with Borrow in A register, A = A - 25H - Carry_Flag
  13. INR - It is used to Increment the value in the register
    • Syntax INR (register), e.g.: INR B. Here we Increment the Value in the B register, B = B + 1
    • But If say B is an 8-bit Register and it holds value of FF then if we try to Increment it, It will again come to 00
    • INR will effect the Flags, It is because in INR is done ALU because they are 8-bit operations which change the Flags
  14. INX - It is used to Increment the value in the register pair
    • Syntax INX (register), e.g.: INR B. Here we Increment the Value in the BC register, BC = BC + 1
    • But If say BC is an 8-bit Register Pair and it holds value of FFFF then if we try to Increment it, It will again come to 0000
    • Unlike INR, INX will not effect any flags as it is done by Incrementor/Decrementor not by ALU and they don’t have authority to change the flags
  15. INR M - It is used to Increment the Data pointed by the M register. The M register holds the address of the value of HF register, M = M + 1
  16. DCR - It is used to Decrement the value in the register
    • Syntax DCR (register), e.g.: DCR B. Here we Decrement the Value in the B register, B = B - 1
    • But If say B is an 8-bit Register and it holds value of 00 then if we try to Decrement it, It will again come to FF
    • DCR will effect the Flags, It is because in DCR is done ALU because they are 8-bit operations which change the Flags
  17. DCX - It is used to Decrement the value in the register pair
    • Syntax DCX (register), e.g.: DCX B. Here we Decrement the Value in the BC register, BC = BC - 1
    • But If say BC is an 8-bit Register Pair and it holds value of 0000 then if we try to Decrement it, It will again come to FFFF
    • Unlike DCR, DCX will not effect any flags as it is done by Incrementor/Decrementor not by ALU and they don’t have authority to change the flags
  18. DCR M - It is used to Decrement the Data pointed by the M register. The M register holds the address of the value of HF register, M = M - 1
  19. DAD - Double Addition is used to add two 16-bit numbers
    • Syntax DAD (register_pair), e.g.: DAD D. Here in this we add the Values in DE Pair with HL Pair Register
    • In this Instruction X is not present but we consider that it as Register Pair
    • In this Instruction HL is default Register to store but not A
  20. DAA (Decimal Adjust After Addition) - This will adjust the result after Addition to make them compatible to real life decimal system as we deal with hexa decimal and it’s not used in real life. To convert the hexa decimal values to decimal values follows below rules
    1. If Lower Nibble After Addition is > 9 (means characters will occur) or Auxiliary_Carry = 1 then Add 6 to them
    2. If Higher Nibble After Addition is > 9 (means characters will occur) or Carry_Flag = 1 then Add 6 to them

Logic Instructions Group

  1. ANA (AND Accumulator) - It is used to perform AND operation with Register
    • Syntax AND (register), e.g.: AND B. Here in this we Perform AND Operation on A and B Register Values and store the result in A, A = A ^ B
    • This is used in some logical operations like Clearing Lower Nibble, For this we AND the lower nibble with 0 that clears it and we AND the higher nibble with 1 that keep it intact
  2. ANA M - It is used to Perform AND operation between A and M
    • Here M refers to the Address of the HF register pair, A = A ^ M
  3. ANI - It is used to Perform AND operation directly onto the data
    • Syntax ANI (data), e.g.: ANI 25H. Here we perform AND operation with the A register and data 25H, A = A ^ 25H
  4. ORA (ORA Accumulator) - It is used to perform OR operation with Register
    • Syntax ORA (register), e.g.: ORA B. Here in this we Perform OR Operation on A and B Register Values and store the result in A, A = A v B
    • This is used in some logical operations like Setting the Lower Nibble, For this we OR the lower nibble with 1 that makes the lower nibble one’s, and we OR the higher nibble with 0 that keep it intact
  5. ORA M - It is used to Perform OR operation between A and M
    • Here M refers to the Address of the HF register pair, A = A v M
  6. ORI - It is used to Perform OR operation directly onto the data
    • Syntax ORI (data), e.g.: ORI 25H. Here we perform OR operation with the A register and data 25H, A = A v 25H
  7. XRA (XRA Accumulator) - It is used to perform XOR operation with Register
    • Syntax XRA (register), e.g.: XRA B. Here in this we Perform XOR Operation on A and B Register Values and store the result in A, A = A + B
    • This is used in logical operations like Complimenting the Lower Nibble, For this we XOR the lower nibble with 1 that compliments the existing values and we XOR the higher nibble with 0 that keep it intact
  8. XRA M - It is used to Perform XOR operation between A and M
    • Here M refers to the Address of the HF register pair, A = A + M
  9. XRI - It is used to Perform XOR operation directly onto the data
    • Syntax XRI (data), e.g.: XRI 25H. Here we perform XOR operation with the A register and data 25H, A = A + 25H
  10. CMP (Compare) – Used to compare the data of a register with the contents of register A.
    • Syntax CMP (register), e.g.: CMP B. It performs A - B and updates the Zero Flag (ZF) and Carry Flag (CF) based on the result
ConditionZFCF
A == B10
A > B00
A < B01
  1. CMI – Used to compare the data with contents of register A.
    • Syntax CMI (data), e.g.: CMI 25H. It performs A - 25H and updates the Zero Flag (ZF) and Carry Flag (CF) based on the result
  2. STC (Set Carry Flag) - It is used to set the carry Flag to 1. CF = 1
  3. CMC (Compliment Carry) - It is used to compliment the carry Flag value CF(bar) = CF
  4. CMA (Compliment Accumulator) - It is used to compliment data in A register A(bar) = A

Rotation Instructions Group

  1. RLC (Rotate Left with Carry) - It is used to Rotate the Bits to left in Accumlator - A Register. It starts from Last and go until front and the first bit will go in Last bit and a copy of first bit will also go in Carry Flag
    • It is used when we need to check the value of the first bit in the register, then we perform RLC and check the value from CF
  2. RRC (Rotate Right with Carry) - It is used to Rotate the Bits to right in Accumlator - A Register. It starts from First and go until Last and the Last bit will go in First bit and a copy of last bit will also go in Carry Flag ^Rotate-Instruction-Group
    • It is used when we need to check the value of the last bit in the register, then we perform RRC and check the value from CF
  3. RAL (Rotation Athematic Left) - It is used to Rotate the Bits to Left along with the Carry. The carry will not take place in Rotation in RLC and RRC but it does in it. It starts from the left and go until front and goes into Carry Flag and the carry flag value goes into last bit
  4. RAR (Rotation Athematic Right) - It is used to Rotate the Bits to Right along with the Carry. The carry will not take place in Rotation in RLC and RRC but it does in it. It starts from the first and go until last and goes into Carry Flag and the carry flag value goes into first bit

Branch Instructions Group

  1. JMP (Jump) - Programs execute sequentially, but when it need move unevenly (not sequentially) then we use JMP Instruction, It changes the Program Counter pointing address as it holds the address of next Instruction. It is as Simple as Updating address of Program Counter
    • Syntax JMP (addr), e.g.: JMP 2000H. Let’s say in program were at location 1000H the next Instruction will be at 1001H but here it will change the address in the Program Counter to 2000H PC <- 2000H and the next sequence will be 2001H and will continue
    • Let’s understand this in more detail. In the previous point, we assumed the JMP instruction is at address 1000H. But actually, the JMP 2000H instruction takes up 3 bytes in memory:
      1. The JMP part is stored at 1000H
      2. The lower byte of the address 2000H (which is 00) is stored at 1001H
      3. The higher byte of the address 2000H (which is 20) is stored at 1002H
    • So, the full instruction JMP 2000H occupies addresses 1000H, 1001H, and 1002H.
    • This means the program does not jump directly from 1000H to 2000H. Instead, after reading the full instruction, the program counter (PC) moves to 1003H (the next instruction after the JMP instruction) and then jumps to 2000H.
    • We say it jumps from 1003H to 2000H (not from 1002H) because the program counter increments quickly and points to the next instruction address (1003H) before the jump happens.
  2. Conditional Jump - These set of jumps will execute only when the particular condition or value is set
    • JC (Jump Carry) - It will jump when the Carry_Flag = 1
    • JNC (Jump Not Carry) - It will jump when the Carry_Flag = 0
    • JZ (Jump Zero) - It will jump when the Zero_Flag = 1
    • JNZ (Jump Not Zero) - It will jump when the Zero_Flag = 0
    • JPE (Jump Parity Even) - It will jump when the Parity_Flag = 1
    • JPO (Jump parity Odd) - It will jump when the Parity_Flag = 0
    • JM (Jump Minus) - It will jump when the Sign_Flag = 1
    • JP (Jump Plus) - It will jump when the Sign_Flag = 0
    • Program for Infinite loop
       Back:
         ...
         ...
         ...
       JMP Back
    • Program for For loop
       MOV C, 05h
       Back:
         ...
         ...
         DCR C, 4
       JNZ Back
  3. CALL (Call) and RET (Return) - These are similar to JMP, but with an important difference. While JMP jumps to an address and continues from there forever, CALL jumps to a subroutine (like a function) and then comes back to the place where it was called using RET (return). Think of it as calling a function in programming, which we call a Sub-Routine in microcontrollers.
    • Syntax: CALL (function_name/address), e.g., CALL 2000H, and RET to return

    • Using the same example as JMP: Suppose the CALL instruction is at address 1000H. When the program executes CALL 2000H, it jumps to the subroutine at 2000H. But before jumping, it saves the return address (1003H). The address of the next instruction after the CALL. So it knows where to come back after finishing the subroutine

    • This return address is stored in the stack because the program might call the subroutine from many different places, each with a different return address. The stack helps keep track of all these return points

    • The return address (1003H) is stored in three parts on the stack:

      • The Stack Pointer (SP) points to the highest address where the return address is stored
      • SP - 1 stores the lower byte (00H)
      • SP - 2 stores the higher byte (20H)
    • After the subroutine finishes, the RET instruction takes the return address from these three stack locations (SP, SP + 1, and SP + 2) and loads it back into the Program Counter (PC). This makes the program continue execution from where it left off, at 1003H

    • In summary, CALL lets the program jump to a subroutine and remember where to come back, and RET makes it return to that saved address and continue running the main program sequentially

      Conditional Calls
      1. CC (Call Carry) - It will Call when the Carry_Flag = 1
      2. CNC (Call Not Carry) - It will Call when the Carry_Flag = 0
      3. CZ (Call Zero) - It will Call when the Zero_Flag = 1
      4. CNZ (Call Not Zero) - It will Call when the Zero_Flag = 0
      5. CPE (Call Parity Even) - It will Call when the Parity_Flag = 1
      6. CPO (Call parity Odd) - It will Call when the Parity_Flag = 0
      7. CM (Call Minus) - It will Call when the Sign_Flag = 1
      8. CP (Call Plus) - It will Call when the Sign_Flag = 0
      Conditional Calls
      1. RC (Return Carry) - It will Return when the Carry_Flag = 1
      2. RNC (Return Not Carry) - It will Return when the Carry_Flag = 0
      3. RZ (Return Zero) - It will Return when the Zero_Flag = 1
      4. RNZ (Return Not Zero) - It will Return when the Zero_Flag = 0
      5. RPE (Return Parity Even) - It will Return when the Parity_Flag = 1
      6. RPO (Return parity Odd) - It will Return when the Parity_Flag = 0
      7. RM (Return Minus) - It will Return when the Sign_Flag = 1
      8. RP (Return Plus) - It will Return when the Sign_Flag = 0
  4. RSTn (Restart n) - This instruction is similar to the CALL instruction because it also jumps to a subroutine and saves the return address so the program can come back later. ^RSTn-Instruction
    • The difference is that the address to jump to is not written directly in the instruction. Instead, the address is calculated using the formula: Branch Address = n x 8. where n is a number from 0 to 7.
    • For example, if the instruction is RST 3, the program will jump to address 3 x 8 = 24 (which is 18H in hexadecimal).
    • Like CALL, the current address (the return address) is saved on the stack before jumping, so the program can return to the point after the RSTn instruction when the subroutine finishes.
    • This makes RSTn a quick way to jump to one of eight fixed locations in memory, often used for handling interrupts or special routines.
    • In summary, RSTn works like a shortcut CALL to one of eight predefined addresses, calculated by multiplying ( n ) by 8, and it saves the return address on the stack to come back after the subroutine.

Stack, I/O and Machine Control Instructions Group

Stack Instructions ^Stack-Instructions
  1. PUSH - It is used to push Register Pair inside the Stack and it is a 16-bit operation - Syntax PUSH (register_pair), e.g.: PUSH B. Here we store the BC Pair in the Stack at locations SP, SP - 1, SP - 2
  2. POP - It is used to pop Register Pair from the Stack and it is a 16-bit operation - Syntax POP (register_pair), e.g.: POP B. Here we pop the BC Pair from the Stack from the locations SP, SP - 1, SP - 2
  3. PUSH PSW (PUSH Program Status Word) - It is a combination of two registers, Accumulator and Flag Register. It is used to perform Push operation on A Register - Syntax PUSH PSW. Here we push the A Register from the Stack from the locations SP, SP - 1, SP - 2
  4. POP PSW (POP Program Status Word) - It is a combination of two registers, Accumulator and Flag Register. It is used to perform Pop operation on A Register - Syntax POP PSW. Here we pop the A Register from the Stack from the locations SP, SP + 1, SP + 2
I/O Instructions

All the instructions we have done are between Memory and Microprocessor, but these instructions are between I/O and Microprocessor. For reference, here is Computer System

  1. IN (Input) - It is used to input I/O address into Microprocessor inside A Register
    • Syntax IN (device_address), e.g.: IN 20H. Here it is used to input data in I/O device 20 into A Register
  2. OUT (Output) - It is used to output I/O address data from Microprocessor from A Register
    • Syntax OUT (device_address), e.g.: OUT 20H. Here it is used to output data from A Register to I/O device 20
Machine Control Instructions
  1. SIM (Set Interrupt Mask) - The SIM instruction is a 1-byte multi-purpose instruction used in the 8085 microprocessor for controlling interrupt operations and serial data output. It has the opcode 30H and requires 4 T-states for execution. Key Functions of SIM:
    • Masking/unmasking of RST7.5, RST6.5, and RST5.5 interrupts
    • Resetting the RST7.5 flip-flop to 0
    • Performing serial output of data through the SOD pin
    • SIM Instruction Format: Before executing SIM, the accumulator must be loaded with a specific bit pattern that determines the operation to be performed. The bit pattern in the accumulator is interpreted as follows:
Bit PositionPurpose
Bit 7 (D7)Serial Output Data (SOD) - meaningful only if bit 6 is set to 1[
Bit 6 (D6)Serial Output Enable (SOE) - enables serial data output when set to 1
Bit 5 (D5)Don’t care bit
Bit 4 (D4)Reset RST7.5 flip-flop when set to 1
Bit 3 (D3)Mask Set Enable (MSE) - must be 1 to enable masking/unmasking
Bit 2 (D2)Mask for RST7.5 - 1 to mask, 0 to unmask (if MSE=1)
Bit 1 (D1)Mask for RST6.5 - 1 to mask, 0 to unmask (if MSE=1)
Bit 0 (D0)Mask for RST5.5 - 1 to mask, 0 to unmask (if MSE=1)
Example:
This example resets the RST7.5 flip-flop, enables masking operations, unmasks RST7.5 and RST6.5, but masks RST5.5

2. RIM (Read Interrupt Mask) - The RIM instruction is a 1-byte instruction with opcode 20H used to read the status of the interrupt system and for serial input of data Key Functions of RIM: - Reading the mask status of RST7.5, RST6.5, and RST5.5 interrupts - Checking if interrupts are enabled or disabled - Checking for pending interrupts - Reading serial input data from the SID pin - Unlike SIM, RIM only reads the status and doesn’t modify any settings - RIM Instruction Format: After executing RIM, the accumulator is loaded with the following information

Bit PositionInformation
Bit 7 (D7)Serial Input Data (SID) bit
Bit 6 (D6)Pending status of RST7.5 (1 if pending)
Bit 5 (D5)Pending status of RST6.5 (1 if pending)
Bit 4 (D4)Pending status of RST5.5 (1 if pending)
Bit 3 (D3)Interrupt Enable flag status (1 if enabled)
Bit 2 (D2)Mask status of RST7.5 (1 if masked)
Bit 1 (D1)Mask status of RST6.5 (1 if masked)
Bit 0 (D0)Mask status of RST5.5 (1 if masked)
  1. EI (Enable Interrupt) - By setting this Interrupt will be enabled, by default it will be disabled and again get enabled via OS when system boots up
  2. DI (Disable Interrupt) - By setting this Interrupt will not be enabled
  3. NOD (No Operation Delay) - It does nothing, thus it can be used to create delay
  4. HLT (Halt) - It is written in the last of the program which will lead the Microprocessor into HALT state and Microprocessor will stop working, It will set HALT_Flag = 1 by default it will be zero. If we want Microprocessor to work we need to restart it, after it moving in HALT state