Instructions are used in programming think of it as an syntax
Data Transfer Group
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
- Syntax
LXI(Load Immediately) - It is used to load data inRegister 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
- Syntax
MVI M, data- It is move Immediately but hereMsignifies the address location which is pointingHLPair, e.g.: MVI M, 25H. Here 25H will be stored in the location which is point address ofHL PairMOV(Move) - Itcopiesthe data from one register to another register- Syntax
MOV (destination_register), (source_register), e.g.: MOV B,C
- Syntax
MOV (register), M- It is move but hereMsignifies the address location which is pointingHLPair, e.g.: MOV B, M. Here the data ofMwill which is address pointing toHL Pairwill be stored in theBregisterMOV M, (register)- It is move but hereMsignifies the address location which is pointingHLPair, e.g.: MOV M, B. Here the data ofBwill be stored in theMwhich points to address ofHL PairLDA(Load A) - In this we will load the data intoAregister- Syntax
LDA (address/data), e.g.: LDA 2000H. Here2000His address not data because there is noIin the instruction and2000His of 16-bit number it can’t be stored in 8-bit register A
- Syntax
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 inAregister at the 3000H address
- Syntax
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 theBC Pairis stored inAregister LDAX Hdoesn’t exist as we can do the same withMOV A, MsoLDAX His an invalid Instruction
- Syntax
STAX(Store A with register pair address) - In this we will store the data inAregister into register pair- Syntax
STAX (register_pair), e.g.: STAX B. Here the data in theA Registeris stored in theBC Pair STAX Hdoesn’t exist as we can do the same withMOV M, AsoSTAX His an invalid Instruction
- Syntax
LHLD(Load HL Direct addressing) - In this we store the data oftwo 8-bit addressinto theHL Pair- Syntax
LHLD (address), e.g.: LHLD 2000H. Here in this we store the data at addresses 2000 and 2001 in theHL Pair. - It’s 2000 and 2001 addresses not 2000H data because there is no
Xin the instruction - It’s data of 2000 and 2001 address because the
HL Pairis 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
Lregister and 2001 data will go intoHregister it is due to Little Indian Rule.
- Syntax
SHLD(Store HL Pair Directly) - It means we store the data ofHL Pair- Syntax
SHLD (address), e.g.: SHLD 3000H. Here we store the data in HL Pair into3000and3001locations
- Syntax
PCHL(Program Counter HL Pair) - It this we store the data ofHL Pairin Program CounterSPHL(Stack Pointer HL Pair) - It this we store the data ofHL Pairin Stack PointerXCHG- It interchanges the values ofHLandDEpairsXTHL(Exchange top with HL) - It’s doesn’t change theSPandHL.SPis the address of the data present in the top of the stack. Rather It means to swap thedata Pointed by the SP and SP + 1(as HL is of 16-bit and data of SP is of 8-bit) intoHL Pair- But the interchanging happens differently here
- In
other instructionsit iscopy and pastebut it’s not the same here - First the data in
SPgoes inZandSP + 1goes inW - Next the data in
Lwill beoverwritteninSPand data inHisoverwritteninSP + 1 - Next the data from
Zwill beoverwritteninLand data fromWwill beoverwritteninH. Here theWandZare temporary register for more context see 8085 Architecture.
Arithmetic Instructions Group
ADD- It is used add the value of register in theAregister- Syntax
ADD (register), e.g.: ADD B. It will accumulate the value inBregister and the value inAregister inAregister,A = A + B - Here
A + Bcan end up being9 bitsso need to handle carry bit in the code - We can also consider it as Half Adder
- Syntax
ADD M- It is used to add the contents ofMregister intoAregister, e.g.:ADD M. Here it adds the value ofMregister andAregister and put inAregister. TheMregister holds the address of the value ofHFregister,A = A + MADI- It is used to add Immediate Data into theAregister- Syntax
ADI (data), e.g.: ADI 25H. Here in this we are using Immediate Addressing Mode and Adding the Data directly intoAregister rather giving AddressA = A + 25H - Here we need to handle borrows as
A - Bcan end up giving an borrow
- Syntax
SUB- It is used Subtract the value of register in theAregister- Syntax
SUB (register), e.g.: SUB B. It will subtract the value inBregister from the value inAregister inAregister,A = A - B
- Syntax
SUB M- It is used to subtract the contents ofMregister fromAregister, e.g.:SUB M. Here it subtracts the value ofMregister fromAregister and put inAregister. TheMregister holds the address of the value ofHFregister,A = A - MSUI-It is used to subtract Immediate Data from theAregister- Syntax
SUI (data), e.g.: SUI 25H. Here in this we are using Immediate Addressing Mode and Subtracting the Data directly fromAregister rather giving AddressA = A - 25H
- Syntax
ADC- Add with Carry is used to add the number toAregister which includes carry, which is generated from the Addition that took place before- Syntax
ADD B, e.g.: Here in thisBis an addition of two 8-bit numbers having a carry and we add it inAregister,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
- Syntax
ADC M- It is used to Add the value ofMregister withAregister and store it inAregister. TheMregister holds the address of the value ofHFregister,A = A + M + Carry_FlagACI- 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 inAregister,A = A + 25H + Carry_Flag
- Syntax
SBB- Subtract with Borrow is used to subtract the number fromAregister which includes borrow, which is generated from the Subtraction that took place before- Syntax
SBB B, e.g.: Here in thisBis an subtraction result of two 8-bit numbers having a borrow and we subtract it fromAregister,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
- Syntax
SBC M- It is used to Subtract the value ofMregister fromAregister and store it inAregister. TheMregister holds the address of the value ofHFregister,A = A - M - Carry_FlagSBI- 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 inAregister,A = A - 25H - Carry_Flag
- Syntax
INR- It is used to Increment the value in the register- Syntax
INR (register), e.g.: INR B. Here we Increment the Value in theBregister,B = B + 1 - But If say
Bis an 8-bit Register and it holds value ofFFthen if we try to Increment it, It will again come to00 INRwill effect the Flags, It is because inINRis doneALUbecause they are8-bitoperations which change the Flags
- Syntax
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 theBCregister,BC = BC + 1 - But If say
BCis an 8-bit Register Pair and it holds value ofFFFFthen if we try to Increment it, It will again come to0000 - Unlike
INR,INXwill not effect any flags as it is done byIncrementor/Decrementornot byALUand they don’t have authority to change the flags
- Syntax
INR M- It is used to Increment the Data pointed by theMregister. TheMregister holds the address of the value ofHFregister,M = M + 1DCR- It is used to Decrement the value in the register- Syntax
DCR (register), e.g.: DCR B. Here we Decrement the Value in theBregister,B = B - 1 - But If say
Bis an 8-bit Register and it holds value of00then if we try to Decrement it, It will again come toFF DCRwill effect the Flags, It is because inDCRis doneALUbecause they are8-bitoperations which change the Flags
- Syntax
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 theBCregister,BC = BC - 1 - But If say
BCis an 8-bit Register Pair and it holds value of0000then if we try to Decrement it, It will again come toFFFF - Unlike
DCR,DCXwill not effect any flags as it is done byIncrementor/Decrementornot byALUand they don’t have authority to change the flags
- Syntax
DCR M- It is used to Decrement the Data pointed by theMregister. TheMregister holds the address of the value ofHFregister,M = M - 1DAD- 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 inDE PairwithHL Pair Register - In this Instruction X is not present but we consider that it as
Register Pair - In this Instruction
HLis default Register to store but notA
- Syntax
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- If Lower Nibble After Addition is
> 9(means characters will occur) orAuxiliary_Carry = 1thenAdd 6 to them - If Higher Nibble After Addition is
> 9(means characters will occur) orCarry_Flag = 1thenAdd 6 to them
- If Lower Nibble After Addition is
Logic Instructions Group
ANA(AND Accumulator) - It is used to performANDoperation with Register- Syntax
AND (register), e.g.: AND B. Here in this we PerformANDOperation onAandBRegister Values and store the result inA,A = A ^ B - This is used in some logical operations like
Clearing Lower Nibble, For this weANDthe lower nibble with0that clears it and weANDthe higher nibble with1that keep it intact
- Syntax
ANA M- It is used to PerformANDoperation betweenAandM- Here
Mrefers to the Address of theHFregister pair,A = A ^ M
- Here
ANI- It is used to PerformANDoperation directly onto the data- Syntax
ANI (data), e.g.: ANI 25H. Here we performANDoperation with theAregister and data25H,A = A ^ 25H
- Syntax
ORA(ORA Accumulator) - It is used to performORoperation with Register- Syntax
ORA (register), e.g.: ORA B. Here in this we PerformOROperation onAandBRegister Values and store the result inA,A = A v B - This is used in some logical operations like
Setting the Lower Nibble, For this weORthe lower nibble with1that makes the lower nibble one’s, and weORthe higher nibble with0that keep it intact
- Syntax
ORA M- It is used to PerformORoperation betweenAandM- Here
Mrefers to the Address of theHFregister pair,A = A v M
- Here
ORI- It is used to PerformORoperation directly onto the data- Syntax
ORI (data), e.g.: ORI 25H. Here we performORoperation with theAregister and data25H,A = A v 25H
- Syntax
XRA(XRA Accumulator) - It is used to performXORoperation with Register- Syntax
XRA (register), e.g.: XRA B. Here in this we PerformXOROperation onAandBRegister Values and store the result inA,A = A + B - This is used in logical operations like
Complimenting the Lower Nibble, For this weXORthe lower nibble with1that compliments the existing values and weXORthe higher nibble with0that keep it intact
- Syntax
XRA M- It is used to PerformXORoperation betweenAandM- Here
Mrefers to the Address of theHFregister pair,A = A + M
- Here
XRI- It is used to PerformXORoperation directly onto the data- Syntax
XRI (data), e.g.: XRI 25H. Here we performXORoperation with theAregister and data25H,A = A + 25H
- Syntax
CMP(Compare) – Used to compare the data of a register with the contents of registerA.- Syntax
CMP (register), e.g.: CMP B. It performsA - Band updates the Zero Flag (ZF) and Carry Flag (CF) based on the result
- Syntax
| Condition | ZF | CF |
|---|---|---|
| A == B | 1 | 0 |
| A > B | 0 | 0 |
| A < B | 0 | 1 |
CMI– Used to compare the data with contents of registerA.- Syntax
CMI (data), e.g.: CMI 25H. It performsA - 25Hand updates the Zero Flag (ZF) and Carry Flag (CF) based on the result
- Syntax
STC(Set Carry Flag) - It is used to set the carry Flag to1.CF = 1CMC(Compliment Carry) - It is used to compliment the carry Flag valueCF(bar) = CFCMA(Compliment Accumulator) - It is used to compliment data in A registerA(bar) = A
Rotation Instructions Group
RLC(Rotate Left with Carry) - It is used to Rotate the Bits to left inAccumlator - A Register. It starts from Last and go until front and the first bit will go inLast 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
RLCand check the value fromCF
- It is used when we need to check the value of the first bit in the register, then we perform
RRC(Rotate Right with Carry) - It is used to Rotate the Bits to right inAccumlator - A Register. It starts from First and go until Last and the Last bit will go inFirst 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
RRCand check the value fromCF
- It is used when we need to check the value of the last bit in the register, then we perform
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 inRLCandRRCbut it does in it. It starts from the left and go until front and goes intoCarry Flagand the carry flag value goes into last bitRAR(Rotation Athematic Right) - It is used to Rotate the Bits to Right along with the Carry. The carry will not take place in Rotation inRLCandRRCbut it does in it. It starts from the first and go until last and goes intoCarry Flagand the carry flag value goes into first bit
Branch Instructions Group
JMP(Jump) - Programs execute sequentially, but when it need move unevenly (not sequentially) then we use JMP Instruction, It changes theProgram Counterpointing 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 location1000Hthe next Instruction will be at1001Hbut here it will change the address in the Program Counter to 2000HPC <- 2000Hand the next sequence will be2001Hand will continue - Let’s understand this in more detail. In the previous point, we assumed the
JMPinstruction is at address1000H. But actually, theJMP 2000Hinstruction takes up 3 bytes in memory:- The
JMPpart is stored at1000H - The lower byte of the address
2000H(which is00) is stored at1001H - The higher byte of the address
2000H(which is20) is stored at1002H
- The
- So, the full instruction
JMP 2000Hoccupies addresses1000H,1001H, and1002H. - This means the program does not jump directly from
1000Hto2000H. Instead, after reading the full instruction, the program counter (PC) moves to1003H(the next instruction after theJMPinstruction) and then jumps to2000H. - We say it jumps from
1003Hto2000H(not from1002H) because the program counter increments quickly and points to the next instruction address (1003H) before the jump happens.
- Syntax
- Conditional Jump - These set of jumps will execute only when the particular condition or value is set
JC(Jump Carry) - It will jump when theCarry_Flag = 1JNC(Jump Not Carry) - It will jump when theCarry_Flag = 0JZ(Jump Zero) - It will jump when theZero_Flag = 1JNZ(Jump Not Zero) - It will jump when theZero_Flag = 0JPE(Jump Parity Even) - It will jump when theParity_Flag = 1JPO(Jump parity Odd) - It will jump when theParity_Flag = 0JM(Jump Minus) - It will jump when theSign_Flag = 1JP(Jump Plus) - It will jump when theSign_Flag = 0- Program for Infinite loop
Back: ... ... ... JMP Back - Program for For loop
MOV C, 05h Back: ... ... DCR C, 4 JNZ Back
CALL(Call) andRET(Return) - These are similar toJMP, but with an important difference. WhileJMPjumps to an address and continues from there forever,CALLjumps to a subroutine (like a function) and then comes back to the place where it was called usingRET(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, andRETto return -
Using the same example as
JMP: Suppose theCALLinstruction is at address1000H. When the program executesCALL 2000H, it jumps to the subroutine at2000H. But before jumping, it saves the return address (1003H). The address of the next instruction after theCALL. 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 - 1stores the lower byte (00H)SP - 2stores the higher byte (20H)
- The Stack Pointer (
-
After the subroutine finishes, the
RETinstruction takes the return address from these three stack locations (SP,SP + 1, andSP + 2) and loads it back into the Program Counter (PC). This makes the program continue execution from where it left off, at1003H -
In summary,
CALLlets the program jump to a subroutine and remember where to come back, andRETmakes it return to that saved address and continue running the main program sequentiallyConditional Calls
CC(Call Carry) - It will Call when theCarry_Flag = 1CNC(Call Not Carry) - It will Call when theCarry_Flag = 0CZ(Call Zero) - It will Call when theZero_Flag = 1CNZ(Call Not Zero) - It will Call when theZero_Flag = 0CPE(Call Parity Even) - It will Call when theParity_Flag = 1CPO(Call parity Odd) - It will Call when theParity_Flag = 0CM(Call Minus) - It will Call when theSign_Flag = 1CP(Call Plus) - It will Call when theSign_Flag = 0
Conditional Calls
RC(Return Carry) - It will Return when theCarry_Flag = 1RNC(Return Not Carry) - It will Return when theCarry_Flag = 0RZ(Return Zero) - It will Return when theZero_Flag = 1RNZ(Return Not Zero) - It will Return when theZero_Flag = 0RPE(Return Parity Even) - It will Return when theParity_Flag = 1RPO(Return parity Odd) - It will Return when theParity_Flag = 0RM(Return Minus) - It will Return when theSign_Flag = 1RP(Return Plus) - It will Return when theSign_Flag = 0
-
RSTn(Restart n) - This instruction is similar to theCALLinstruction 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. wherenis a number from 0 to 7. - For example, if the instruction is
RST 3, the program will jump to address3 x 8 = 24(which is18Hin 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 theRSTninstruction when the subroutine finishes. - This makes
RSTna quick way to jump to one of eight fixed locations in memory, often used for handling interrupts or special routines. - In summary,
RSTnworks like a shortcutCALLto 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.
- The difference is that the address to jump to is not written directly in the instruction. Instead, the address is calculated using the formula:
Stack, I/O and Machine Control Instructions Group
Stack Instructions ^Stack-Instructions
PUSH- It is used to pushRegister Pairinside the Stack and it is a 16-bit operation - SyntaxPUSH (register_pair), e.g.: PUSH B. Here we store theBCPair in the Stack at locationsSP,SP - 1,SP - 2POP- It is used to popRegister Pairfrom the Stack and it is a 16-bit operation - SyntaxPOP (register_pair), e.g.: POP B. Here we pop theBCPair from the Stack from the locationsSP,SP - 1,SP - 2PUSH PSW(PUSH Program Status Word) - It is a combination of two registers,AccumulatorandFlag Register. It is used to perform Push operation onA Register- SyntaxPUSH PSW. Here we push theA Registerfrom the Stack from the locationsSP,SP - 1,SP - 2POP PSW(POP Program Status Word) - It is a combination of two registers,AccumulatorandFlag Register. It is used to perform Pop operation onA Register- SyntaxPOP PSW. Here we pop theA Registerfrom the Stack from the locationsSP,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
IN(Input) - It is used to inputI/O addressinto Microprocessor insideA Register- Syntax
IN (device_address), e.g.: IN 20H. Here it is used to input data inI/O device 20intoA Register
- Syntax
OUT(Output) - It is used to outputI/O addressdata from Microprocessor fromA Register- Syntax
OUT (device_address), e.g.: OUT 20H. Here it is used to output data fromA RegistertoI/O device 20
- Syntax
Machine Control Instructions
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 Position | Purpose |
|---|---|
| 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 Position | Information |
|---|---|
| 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) |
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 upDI(Disable Interrupt) - By setting this Interrupt will not be enabledNOD(No Operation Delay) - It does nothing, thus it can be used to create delayHLT(Halt) - It is written in the last of the program which will lead the Microprocessor intoHALTstate and Microprocessor will stop working, It will setHALT_Flag = 1by default it will bezero. If we want Microprocessor to work we need to restart it, after it moving inHALTstate