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.

-908-0147097.08 .43974944907 5.200.2 . !747.3.3810773.3.:943  \$4203897:./0/0.79841905747..439749014415747.8432.-7.5.33897:.9438.43/943.70:80/94 .9438574.2-7.3 .

! 43:25 !8.320247 4.3202474.7/.3:3.-84:90:25 398 -903897:. -903897:..415747.9439390-4.220247 \$! 8479:25 398 -903897:.943 9.3/-.3041 8/.09490.48.98  93 94 -908412024770..:25 98.9431742 94 ! .:2594.48.9.9..43/943.7/:258 9.943 9 .0.//7088 4190.:2594.:77039! ..943 %070./0/394147.//70887.

 :251  :251.

3/:251.   -90 70 /.702039.9.  0.

 :251.

-90 :251-90.

/.0. :251   :251 :251-9  :251-9  :251-9.9.7-9 .3/.

/081472814790 3897:.//708882.909089..794! %08:-74:930.//708882.543907 .0 S 43.  &808. %0 574. -9.3/:5/.794! %08:-74:9302:89-093908.3070 S 49147285:890 -9.3 -9.3-0..//70884190309 3897:.  &808.205..943439089.943 S -84:90..

8482.//7088 94:2594 ! 89.9435458!174289. 709 . #09:738.:25 -:9 S #09:733897:..794..9409.

...//708885.30 . %8 -903897:. 8 -903897:..//708841908:-74:9302:89-093 -907..30709390-90 .709 .943.8:-74:930   43.3-0:80/94.90/.34907.-84:90..4397497.381073897:.8:80/94.04190  W  .943 909..943  ..9438903897:. 8:-74:93084.

-0 8:-..8:-..-0 908:-74:930 709 .94908:-74:930 .3 ...

-05.4/085.798  98.2 .28  %88:801:147-70.205747..3.3.70/083394 2...   \$:-74:9308..9:70/ .392083908.8802-.3-0 .4:894.3:.05747..0/2.0038:-74:9308.0897:..0.08.

49074 :251.90. !43:25  '4.  //../:89 0.04/00247  '4.:2:. 94774 \$!\$.702039#08907 '.947#9 ###49.0903/0/0247 &:95.90.:0 394\$9.70 :251496:.77 !-84:90:25 980 425.5..947-  !4 507.77\$09 !:2594//7088 :251949\$09 :251..77 ###49..90. !&\$!:8'.3098 #980..:2:...:2:...947019 ##49.947074 43.3/0.30908 .90.702039#08907 :2519\$09 :2519\$09.0 # &3/0130/&3/0130/3897:.:2:. #0  :25149074 3.  9./0. #9%74:....947--08 . #%#09:73742\$:-74:930 #%#09:7374239077:59 ##49.2.77 \$%\$099 \$!\$479:25 \$&\$:- 742.00247  '4.:2:.-84:90. 019%74:.:0742\$9.7749\$09 :251..:2:.79 :251.943 #980 # ! !!45'.. #0.7#08907 !42502039#08907 0.943 .947- 0..:8.