Computers essentially understand machine codes which are long binary sequences of 0 and 1. For every unique operation, there is a unique sequence of 0s and 1s which makes the processor perform the required operation.  As a programmer, writing code in machine language is very tedious and you wouldn’t want to spend time remembering those codes either.

Assembly language is a low-level language which is architecture specific, i.e. different architectures will have different Mnemonics defined for them. A Mnemonic is kind of a tag which helps you remember the characteristics or role of something. Eg ADD, SUB, MUL. These Mnemonics along with the operand in machine language are hexadecimal numbers. E.g. CE, 8F which are called opcodes. Eg (In 8081) DEC A has opcode 14. Similarly, ADD A, R2 has opcode 2A.

In 8051 there are different ways in which you can address or use these instructions. These are called addressing modes.

 

Immediate addressing mode

In this addressing mode, the data is specified in the instruction itself.
The # symbol specifies the value being data.
E.g. MOV A, #35H (Value 35 is moved in Accumulator).
MOV DPTR, #3000H (value 3000 is moved in Accumulator).

 

Register addressing mode

In this addressing mode, data is specified using registers in the instruction. The permitted registers are A, R7 to R0 of each memory bank.
E.g. MOV A, R0
If R0 contains 25H. Then the value 25H will be copied in A.
Data transfer between two RAM registers is not allowed
E.g. MOV Rx, Ry

 

Direct addressing mode.

In this addressing mode, the address of the operand is specified in the instruction.
MOV A, 35H
Contents of RAM location 35H are copied in A
MOV 20H, 30H
Contents of RAM location 30H are copied to the location of 30H

 

Indirect addressing mode

In this addressing mode, the address of the operand is specified in a register. Only R1 and R0 can be used for this purpose and are called data pointers. Using this addressing mode internal as well as external RAM can be accessed.

E.g. MOV R0, 30h
MOV A, @R0
A gets the value stored at location 30h.

For external RAM
MOVX A, @DPTR (X indicates eternal RAM)
DPTR can be used to point to 16-bit addresses since DPTR is 16-bit in size.

 

Indexed Addressing mode.

In this addressing mode, the address is indirectly specified as the sum of A and DPTR or A and PC.
E.g. MOVC A, @A+DPTR where C indicates code memory.
Here content of memory location pointed by A+DPTR is moved to A.

 

The following are the different data move, Arithmetic, logical, Call and jump, and Boolean instruction. Before we go into these instructions, I will be using the following mnemonics acronyms.

  • add – Address of internal RAM from 00h to FFh
  • n – Any immediate data eg. #33H, #2Fh, #04H etc
  • Rr – Any of the eight registers for R0 to R7, in the selected bank
  • Rp – Pointing registers i.e either R0 or R1 in the selected bank.
  • ladd – Long address (16 bits).
  • sadd – Short address (11 bits).
  • radd – Relative address (A signed number within the range -128d to +127d from the current position of Program counter).

 

Data moves

OperationExplanationBytes Cycles
MOV A, RrContent of register (either R0, R1 .... R7) will be copied in accumulator11
MOV A, adddata contained at the address will be copied to accumulator. eg MOV A, 20H21
MOV A, @RpContent of memory location pointed by Rp will be Copied to A11
MOV A, #nImmediate data will be copied to Accumulator e.g. MOV A, #10h21
MOV Rr, A
Content of Accumulator will be copied to register11
MOV Rr, addContent of address will be copied to register22
MOV Rr, #nImmediate data will be copied to Register21
MOV add, AContent of Accumulator will be copied to specified address21
MOV add, RrContent of register will be copied to the specified address22
MOV add1, add2Content stored in add2 will be copied to add132
MOV add, @RpContent of memory location pointed by Rp will be copied at the specified address22
MOV add, #nimmediate data will be moved to specified address32
MOV @Rp, AContent of accumulator will be copied to the memory location pointed by Rp.11
MOV @Rp, addcontent of specified address will be copied to the memory location pointed by Rp.22
MOV @Rp, #nImmediate data will be copied to the memory location pointed by Rp.21
MOV DPTR, #nnImmediate data of 2 bytes will be stored in DPTR. E.g MOV DPTR, #4000H32
MOVC A, @A+DPTRContent of memory location pointed by the address of A+DPTR will be copied in accumulator.12
MOVC A, @A+PCContent of memory location pointed by the address of A+PC will be copied in accumulator.12
MOVX A, @DPTRContent of Memory location point by DPTR will be copied to A, (External memory).12
MOVX A, @RpContent of Memory location point by Rp will be copied to A, (External memory).12
MOVX @Rp, AContent of A will be copied to the memory location point by Rp. (External memory).12
MOVX @DPTR, AContent of A will be copied to the memory location point by DPTR. (External memory)12
POP addContent point by SP is poped to the address and SP is decremented by 1.22
PUSH addSP is incremented by 1 and content of address is pushed into the stack.22
XCH A, RrContent of A and Rr are exchanged.11
XCH A, addContent of A and add are exchanged.21
XCH A, @RpContent of A and memory location pointed by Rp are exchanged.11

 

Arithematic operations

OperationExplanationBytesCycle
ADD A, Rr
A = A + Content of register (either R0, R1 .... R7).
11
ADD A, addA = A + Content stored at the specified address.21
ADD A, @RpA = A + Content of memory location pointed by Rp.11
ADD A, #nA = A + immediate data.21
ADDC A, RrSame as basic addition with carry being added.11
ADDC A, addSame as basic addition with carry being added.21
ADDC A, @RpSame as basic addition with carry being added.11
ADDC A, #nSame as basic addition with carry being added.21
DA ADecimal adjust accumulator.11
DEC AContent of A is decremented by 1.11
DEC RrContent of Rr is decremented by 1.11
DEC addContent of specified address is decremented by 1.21
DEC @RpContent of memory location pointed by Rp is decremented by 1.11
DIV ABA is divided by B. Quotient is stored in A. Remainder in B.14
INC AContent of A is incremented by 1.11
INC RrContent of Rr is incremented by 1.11
INC addContent of specified address is incremented by 1.21
INC @RpContent of memory location pointed by Rp is incremented by 1.11
INC DPTRDPTR is incremented by 1.12
MUL ABMultiplies A and B. Lower byte is stored in A and higher byte in B.14
SUBB A, RrContent of A is subtracted with Rr along with borrow.11
SUBB A, addContent of A is subtracted with content of specified address.21
SUBB A, @RpContent of A is subtracted with content of memory location pointed by Rp.11
SUBB A, #nContent of A is subtracted with immediate data (#n, e.g. SUBB A, #40h).21

 

CALL and JUMP instructions

OperationExplanationBytesCycles
ACALL saddUsed to 'call' subroutine. Can call within 11 bit address range i.e 2K.22
CJNE A, add, raddCompare content of A with content of specified address, Jump if they are not equal.32
CJNE A, #n, raddCompare A with immediate data. Jump if not equal.32
CJNE Rr, #n, raddCompare content of Register with immediate. Jump if not equal.32
CJNE @Rp, #n, raddCompare content of memory location pointed by Rp with immediate data. jump if not equal.32
DJNZ Rr, raddDecrement Rr by 1. Jump if it is not equal to zero.22
DJNZ add, raddDecrement Rr by 1. Jump if it is not equal to zero.32
LCALL, laddUsed to 'call' subroutine. Can call within 16 bit address range i.e 64K.32
AJMP saddAbsolute jump to any location withing 11 bit address.22
LJMP laddLong jump to the specified long address (0000-FFFFh).32
SJMP raddShort jump to the specified relative address.22
JMP @A+DPTRJumps to the location pointed by A+DPTR.12
JC raddJump if carry flag is set.22
JNC raddJump if carry flag is not set.22
JB b, raddJump if bit is set.32
JNB b, raddJump if bit is not set.32
JBC b, raddJump if bit is set. Clears the bit after jump.
If bit is already cleared, it continues with the next instruction.
32
JZ raddJump if zero flag is set.22
JNZ raddJump if zero flag is not set.22
RETReturns from subroutine. Used at the end of a subroutine.1
RETIReturns from interrupt subroutine.12

 

Logical Operations

OperationExplanation Bytes Cycles
ANL A, RrA (AND) Rr (either of R0 to R7). Result stored in A.
11
ANL A, addA (AND) add. Result stored in A.21
ANL A, @RpA (AND) @Rp. 11
ANL A, #nA (AND) immediate data.21
ANL add, Aadd (AND) A.
Result stored in specified address.
21
ANL add, #nadd (AND) immediate data.
Result stored in specified address.
32
CLR AAccumulator is cleared i.e. A = 00h.11
CPL AContents of A are complemented.11
ORL A, RrA (OR) Rr.
Result stored in A.
11
ORL A, addA (OR) add.
Result stored in A.
21
ORL A, @RpA (OR) @Rp.
Result stored in A.
11
ORL A, #nA (OR) immediate data.
Result stored at A.
21
ORL add, Aadd (OR) Rr.
Result stored at specified address.
21
ORL add, #nadd (OR) immediate data.
Result stored at specified address.
32
XRL A, RrA (XOR) Rr.
Result stored in A.
11
XRL A, addA (XOR) add.
Result stored in A.
21
XRL A, @RpA (XOR) @Rp.
Result stored in A.
11
XRL A, #nA (XOR) Immediate data.
Result stored in A.
21
XRL add, Aadd (XOR) A.
Result stored at specified address.
21
XRL add, #nadd (XOR) immediate data.
Result stored at specified address.
32
NOPNo operation. PC is incremented by 1. 11
RL ARotate content of accumulator to the left by 1. 11
RLC ARotate content of accumulator along with carry to the left by 1. 11
RR ARotate content of accumulator to the right by 1. 11
RRC ARotate content of accumulator along with carry to the right by 1. 11
SWAP ASwap lower 4 bits with upper 4 bits of accumulator.11

 

Boolean Operation

OperationExplanationBytesCycles
ANL C, BitCarry flag (AND) with specified bit. 22
CLR CCarry flag is cleared.11
CLR BitSpecified bit is cleared.21
CPL CCarry flag is complemented.11
CPL BitSpecified bit is complemented.21
ORL C, BitCarry flag (OR) specified bit.22
Mov C, BitValue of bit (0 or 1) is moved to carry flag.21
Mov Bit, CValue if carry flag is moved to specified bit.22
SETB CCarry flag is set.11
SETB BitSpecified bit is set.21

Moiz

Electronics engineer graduated from M.H. Saboo Siddik college of engineering. Currently working as Jr. Innovative engineer. Skilled in 8051, PIC and ARM microcontrollers. Circuit analyzation and Debugging. Constantly looking to acquire more skills which would help myself to become more proficient in embedded domain. Founder and blogger at techetrx.com LinkedIn profile: https://www.linkedin.com/in/moiz-shaikh-305294137

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *