You are on page 1of 25

The 8051 MICROCONTROLLER Instruction set …….. 

By:Hitesh Tejwani Gurpreet Kaur Rai Abhinav Biyani

The C8051 instructions are divided into five functional groups: Arithmetic operations Logical operations Data transfer operations Boolean variable operations Program branching operations .

etc.which allows the user software to manage the different data formats (carry. ASCII.    With arithmetic instructions. signed/unsigned binary. overflow etc…) [@Ri] implies contents of memory location pointed to by R0 or R1 Rn refers to registers R0-R7 of the currently selected register .) The appropriate status bits in the PSW are set when specific conditions are met. the C8051 CPU has no special knowledge of the dataformat (e.g. binary coded decimal.

 The CY flag is set/reset appropriately. a second operand and the previous value of the CY flag. ADD  8-bit addition between the accumulator (A) and a second operand.  The CY flag is set/reset appropriately. .  ADDC  8-bit addition between the accumulator.  The result is always in the accumulator.  Useful for 16-bit addition in two steps.

The lower 8-bits of the 2nd . The lower 8-bits of the 1st number . Clear the CY flag . CAH number MOV R1. The upper 8-bits of the 1st number . 44H ADD A. CY = 0. CY = . .Add 1E44H to 56CAH CLR C MOV A. The result 0EH will be in R1. MOV A. A . The upper 8-bits of the 2nd . 1EH ADDC A. 56H number MOV R2. A 1. The result of the addition is 75H The overall result: 750EH will be in R2:R1.

 Works only after the ADD instruction. .  A  A .  Format the accumulator into a proper 2 digit packed BCD number.<operand> .  The CY flag is set/reset appropriately. DA  Decimal adjust the accumulator.  Subtract an operand and the previous value of the borrow (carry) flag from the accumulator.  Operates only on the accumulator.  SUBB  Subtract with Borrow.CY.  The result is always saved in the accumulator.

address. . an indirect  MUL AB / DIV AB   Multiply A by B and place result in A:B. Divide A by B and place result in A:B. INC  Increment the operand by one. address.  The operand can be a register.  The operand can be a register. the data pointer. an indirect  DEC  Decrement the operand by one. a direct address. a direct address.

XOR. OR.Logical instructions perform Boolean operations (AND.2 . Work on the accumulator or a bit. CPL / CLR Complement / Clear.  CLR P1. and NOT) on data bytes on a bit-by-bit basis.

RR – RL – RRC – RLC A EXAMPLE: RR RR: RRC: RL: RLC: C C A .

.

      CLR .clear RL – rotate left RLC – rotate left through Carry RR – rotate right RRC – rotate right through Carry SWAP – swap accumulator nibbles .

.

direct  XCH A. @Ri  The lower 4-bits of the accumulator are exchanged with the lower 4bits of the internal memory location identified indirectly by the index register. Rn  XCH A. PUSH / POP   Push and Pop a data byte onto the stack.  XCHD A. @Ri  XCH   XCHD  Exchange lower digit of accumulator with the lower digit of the memory location specified. . The data byte is identified by a direct address from the internal RAM locations. Exchange accumulator and a byte variable  XCH A.  The upper 4-bits of each are not modified.

.

 Program branching instructions are used to control the flow of program execution  Some instructions provide decision making capabilities before transferring control to other parts of the program (conditional branches). .

The relative address range of 00FFH is divided into forward and backward jumps. AJMP(absolute jump) In this 2-byte instruction. that is . SJMP(short jump) In this 2-byte instruction. It allows a jump to any memory location from 0000 to FFFFH. It allows a jump to any memory location within the 2k block of program memory.LJMP(long jump) LJMP is an unconditional jump. It is a 3-byte instruction. . within -128 to +127 bytes of memory relative to the address of the current PC.

#data JC Decrement and jump if A/=0 Jump if A/=byte Jump if byte/=#data Jump if CY=1 JNC JB Jump if CY=0 Jump if bit=1 JNB Jump if bit=0 JBC Jump if bit=1 and clear bit .JZ Jump if A=0 JNZ Jump if A/=0 DJNZ CJNE A.byte CJNE reg.

.  Long Call – LCALL  Uses a 16-bit address similar to LJMP  The subroutine can be anywhere. The 8051 provides 2 forms for the CALL instruction:  Absolute Call – ACALL  Uses an 11-bit address similar to AJMP  The subroutine must be within the same 2K page.  Both forms push the 16-bit address of the next instruction on the stack and update the stack pointer.

but  Return instruction pops PC from stack to get address to jump to . Return is also similar to a jump. PC  stack ret .

• ACALL (absolute call) ACALL is 2-byte instruction. .Another control transfer instruction is the CALL instruction. the target address of the subroutine must be within 2K byte range.  LCALL(long call) This 3-byte instruction can be used to call subroutines located anywhere within the 64K byte address space of the 8051. which is used to call a subroutine.

. sublabel:. the subroutine .. acall sublabel ..... ret Main: .call to the subroutine .... ..

. It saves code space when subroutines can be called many times in the same program.   Subroutines allow us to have "structured" assembly language programs. This is useful for breaking a large design into manageable parts.

Right Through Carry SETB: Set Bit SJMP: Short Jump SUBB: Sub. (With Carry) AJMP: Absolute Jump ANL: Bitwise AND CJNE: Compare & Jump if Not Equal CLR: Clear Register CPL: Complement Register DA: Decimal Adjust DEC: Decrement Register DIV: Divide Accumulator by B DJNZ: Dec. Reg. ADDC: Add Acc. & Jump if Not Zero INC: Increment Register JB: Jump if Bit Set JBC: Jump if Bit Set and Clear Bit JC: Jump if Carry Set JMP: Jump to Address JNB: Jump if Bit Not Set JNC: Jump if Carry Not Set JNZ: Jump if Acc. With Borrow SWAP: Swap Accumulator Nibbles XCH: Exchange Bytes XCHD: Exchange Digits XRL: Bitwise Exclusive OR Undefined: Undefined Instruction . Left Through Carry RR: Rotate Accumulator Right RRC: Rotate Acc. Not Zero JZ: Jump if Accumulator Zero LCALL: Long Call LJMP: Long Jump MOV: Move Memory MOVC: Move Code Memory MOVX: Move Extended Memory MUL: Multiply Accumulator by B NOP: No Operation ORL: Bitwise OR POP: Pop Value From Stack PUSH: Push Value Onto Stack RET: Return From Subroutine RETI: Return From Interrupt RL: Rotate Accumulator Left RLC: Rotate Acc.ACALL: Absolute Call ADD. From Acc.

-908-0147097.08 .43974944907 5.200.2 . !747.3.3810773.3.:943  $4203897:./0/0.79841905747..439749014415747.8432.-7.5.33897:.9438.43/943.70:80/94 .9438574.2-7.3 .

! 43:25 !8.320247 4.3202474.7/.3:3.-84:90:25 398 -903897:. -903897:..415747.9439390-4.220247 $! 8479:25 398 -903897:.943 9.3/-.3041 8/.09490.48.98  93 94 -908412024770..:25 98.9431742 94 ! .:2594.48.9.9..43/943.7/:258 9.943 9 .0.//7088 4190.:2594.:77039! ..943 %070./0/394147.//70887.

 :251  :251.

3/:251.   -90 70 /.702039.9.  0.

 :251.

-90 :251-90.

/.0. :251   :251 :251-9  :251-9  :251-9.9.7-9 .3/.

/081472814790 3897:.//708882.909089..794! %08:-74:930.//708882.543907 .0 S 43.  &808. %0 574. -9.3/:5/.794! %08:-74:9302:89-093908.3070 S 49147285:890 -9.3 -9.3-0..//70884190309 3897:.  &808.205..943439089.943 S -84:90..

8482.//7088 94:2594 ! 89.9435458!174289. 709 . #09:738.:25 -:9 S #09:733897:..794..9409.

...//708885.30 . %8 -903897:. 8 -903897:..//708841908:-74:9302:89-093 -907..30709390-90 .709 .943.8:-74:930   43.3-0:80/94.90/.34907.-84:90..4397497.381073897:.8:80/94.04190  W  .943 909..943  ..9438903897:. 8:-74:93084.

-0 8:-..8:-..-0 908:-74:930 709 .94908:-74:930 .3 ...

-05.4/085.798  98.2 .28  %88:801:147-70.205747..3.3.70/083394 2...   $:-74:9308..9:70/ .392083908.8802-.3-0 .4:894.3:.05747..0/2.0038:-74:9308.0897:..0.08.

49074 :251.90. !43:25  '4.  //../:89 0.04/00247  '4.:2:. 94774 $!$.702039#08907 '.947#9 ###49.0903/0/0247 &:95.90.:0 394$9.70 :251496:.77 !-84:90:25 980 425.5..947-  !4 507.77$09 !:2594//7088 :251949$09 :251..77 ###49..90. !&$!:8'.3098 #980..:2:...:2:...947019 ##49.947074 43.3/0.30908 .90.702039#08907 :2519$09 :2519$09.0 # &3/0130/&3/0130/3897:.:2:. #0  :25149074 3.  9./0. #9%74:....947--08 . #%#09:73742$:-74:930 #%#09:7374239077:59 ##49.2.77 $%$099 $!$479:25 $&$:- 742.00247  '4.:2:.-84:90. 019%74:.:0742$9.7749$09 :251..:2:.79 :251.943 #980 # ! !!45'.. #0.7#08907 !42502039#08907 0.943 .947- 0..:8.