You are on page 1of 9

Introduction Concept 1 Concept 2 Concept 3 Concept 4

Home
Contact
Links Assembly Reference
The 8051 Programmer's Reference: A must have for Assembly Programming

This guide helps in easy Understanding and Visualisation of the instruction Set (Compare the Mnemonic and the Description) Internal RAM Accumulator A (add) Register Banks Rn (add) Rest Of The Bytes add Moving Data in RAM Arithmetic operations Logic Operations Moving Data in ROM Bit Operations and No operations! Comments Welcome! The 8051 programmer's model External RAM Any Program can be written using the following operations:

Program Memory

Direct addressing Register Name Address

Immediate Addressing Numbers(bin,hex,dec)

Indirect Addressing R0 R1

PSW Addressing Methods for the above blocks

Data Movement Opcode Mnemonic Description MOVING NUMBERS 74 78+n 75 76+p mov A, # n mov Rn, # n mov add, # n mov @ Rp, # n move into A , a number n(#n) move into a register R0 to R7 (Rn), a number n(#n) move into a direct address(name) ,a number n(#n) move into an address pointed by R0 or R1( @Rp) , a number n(#n) MOVING ACCUMLATOR VALUES F8+n F5 F6+p mov Rn,A mov add,A mov @ Rp,A move into a register R0 to R7(Rn) the value in A move into a direct address(name) , the value in A move into an address pointed by R0 or R1 (@Rp) , the value in A MOVING REGISTERS VALUES E8+n 88+n mov A,Rn mov add,Rn move into A , the value in the register R0 to R7(Rn) move into a direct address(name) , the value in the register Rn MOVING DIRECT ADDRESSES (NAME) VALUES E5 A8+n 85 A6+p mov A,add mov Rn,add mov add1,add2 mov @ Rp,add move into A , the value in the direct address(name) move into a register R0 to R7(Rn),the value in the direct address(name) move into the direct address(name)1, the value in address(name) 2 move into an address pointed by R0 or R1 (@Rp),the value in address MOVING VALUES IN ADDRESSES POINTED BY R0 AND R1/PSW E6+p 86+p mov A,@Rp mov add,@Rp move into A , the value in the address pointed by R0 or R1(@Rp) move into the dir. Addr.add, value in the addr. pointed by R0 R1( @Rp) 1 1 P 2 2 2 2 3 2 1 P 2 2 2 1 1 P 2 2 1 1 2 1 1 1 2 2 3 2 1 P 1 2 1 B C Flags

Opcode Mnemonic

Description MOVING DATA FROM ROM

B C Flags

93 83

movC A,@A+DPTR move Code into A ,from the address given by A+DPTR (@A+DPTR) movC A,@A+PC move Code into A ,from the address given by A+PC (@A+PC) MOVING DATA FROM EXTERNAL RAM

1 2 P 1 2 P

E0 E2+p

movX A,@DPTR movX A,@Rp

move from eXt.RAM into A, the value in the addr. pointed by DPTR move from eXt.RAM into A, the val. in the addr. pointed by R0 or R1(@Rp) MOVING DATA INTO EXTERNAL RAM

1 2 P 1 2 P

F0 F2+p

movX @DPTR,A movX @Rp,A

move into eXt.RAM at the addr. pointed by DPTR ,the value in A move into eXt.RAM at the addr. pointed by R0 or R1( @Rp),the value in A MOVING A WORD INTO DPTR

1 2 1 2

90

mov DPTR, # w

move into DPTR, a word(two bytes) (# w)

3 2

Opcode Mnemonic

Description Push and Pop

B C Flags

C0 D0

Push add Pop add

Push value in dir.addr. add into addr. pointed by SP+1(push on stack) Pop into the dir.addr.add,value in addr.pointed by SP (pop from stack) EXCHANGE

2 2 SP 2 2 SP

C8+n C5

xchA, Rn xch A, add

Exchange the values in A and Rn Exchange the values in A and dir. Addr. add (name)

1 1 P 2 1 P

C6+p D6+p

xch A, @Rp xchD A, @Rp

Exchange the values in A and the address pointed by R0 or R1 (@Rp) Exchange the LSDs of A and the value in addr.pointed by R0 or R1 (@Rp) SWAP Swap the nibbles(hex digits) in A MOVE ZERO INTO A

1 1 P 1 1 P

C4

swap A

1 1

E4

clr A

Clear the Accumulator ROTATION

1 1 P

23 03 33 13

rlA rr A rlc A rrc A

Rotate left the contents of A(bits moved left once,msb into lsb) Rotate right the contents of A(bits moved rt. once,lsb into msb) Rotate left into carry the contents of A (move msb into carry) Rotate right into carry the contents of A (move lsb into carry)

1 1 1 1

1 1 1 C P 1 C P

ARITHMETIC OPERATIONS Opcode Mnemonic Description ADDITION 24 28+n 25 26+p add A,#n add A,Rn add A,add add A,@Rp add value in A with the number n(#n) and store in A add value in A with value in register Rn and store in A add value in A with value in dir.addr.add(name) and store in A add value in A with value in addr.pointed by R0 or R1(@Rp) and store in A ADDITION WITH CARRY 34 38+n 35 36+p addcA,#n addc A,Rn addc A,add addcA,@Rp add carry,the value in A , and the number n(#n) . store in A add carry, the value in A, and the value in Rn. store in A add carry,the value in A,and the value in dir. Addr.add. store in A add carry,the value in A,and the value in addr.pointed by R0 or R1(@Rp). SUBTRACTION 94 subbA,#n sub borrow (C) from the value in A,and also the number n( #n) . 2 1 C AC OV P 2 1 2 1 1 1 1 1 C AC OV P C AC OV P C AC OV P C AC OV P 2 1 C AC OV P 1 1 C AC OV P 2 1 C AC OV P 1 1 C AC OV P B C Flags

98+n 95 96+p

subb A,Rn subb A,add subb A,@Rp

sub borrow (C) from the value in A, and also the value in Rn. sub borrow (C) from the value inA,and also the value in add. sub borrow (C) from the val. in A,and also the val. pntd by R0 or R1(@Rp) MULTIPLICATION

1 1 C AC OV P 2 1 C AC OV P 1 1 C AC OV P

A4

mulAB

Multiply the values in A and B . store lsbyte in A,msbyte in B DIVISION

1 4 C OV P

84

divAB

Divide the value in A by the value in B.store quotient in A,remainder in B

1 4 C OV P

Opcode Mnemonic

Description INCREMENT

B C Flags

04 08+n 05 06+p A3

incA inc Rn inc add inc @Rp inc DPTR

Increment the value in A by 1 Increment the value in Register Rn by 1 Increment the value in dir.addr.add(name) by 1 Increment the value in the addr.pointed by R0 or R1(@Rp) by 1 Increment the value in DPTR by 1 DECREMENT

1 1 2 1 1

1 P 1 1 1 2

14 18+n 15 16+p

dec A dec Rn dec add dec @Rp

Decrement the value in A by 1 Decrement the value in Register Rn by 1 Decrement the value in dir.addr.add(name) by 1 Decrement the value in the addr.pointed by R0 or R1(@Rp) by 1 DECIMAL ADJUST ACCUMULATOR

1 1 2 1

1 P 1 1 1

D4

da A

Decimal adjust the Accumulator(BCD adjustment)

1 1 CP

LOGIC OPERATIONS

Opcode Mnemonic

Description AND LOGIC, IN ACCUMULATOR

B C Flags

54 58+n 55 56+p

anl A,#n anl A,Rn anl A,add anl A,@Rp

Apply AND Logic to value in A and the number n(#n). Apply AND Logic to value in A and value in Rn. Apply AND Logic to value in A and value in addr.add.(name) Apply AND Logic to val. in A and val. in addr.pointed by R0 or R1(@Rp) OR LOGIC, IN ACCUMULATOR

2 1 2 1

1 1 1 1

P P P P

44 48+n 45 46+p

orl A,#n orlA,Rn orl A,add orlA,@Rp

Apply OR Logic to value in A and the number n(#n). Apply OR Logic to value in A and value in Rn. Apply OR Logic to value in A and value in addr.add (name) Apply OR Logic to val. in A and val. in addr.pointed by R0 or R1(@Rp). EXCLUSIVE OR LOGIC, IN ACCUMULATOR

2 1 2 1

1 1 1 1

P P P P

64 68+n 65 66+p

xrl A,#n xrl A,Rn xrl A,add xrl A,@Rp

Apply EX OR Logic to value in A and the number n(#n). Apply EX OR Logic to value in A and value in Rn. Apply EX OR Logic to value in A and value in addr.add (name). Apply EX OR Logic to val. in A and val. in addr.pointed by R0 or R1(@Rp). AND LOGIC, IN DIRECT ADDRESS

2 1 2 1

1 1 1 1

P P P P

53 52

anl add,#n anl add,A

Apply AND Logic to value in the dir.addr.add and the number n(#n). Apply AND Logic to value in the dir.addr.add (name)and value in A. OR LOGIC, IN DIRECT ADDRESS

3 2 2 1

43 42

orl add,#n orl add,A

Apply OR Logic to value in the dir. Addr.add and the number n(#n). Apply OR Logic to value in the dir.addr.add (name)and value in A. EXCLUSIVE OR LOGIC, IN DIRECT ADDRESS

3 2 2 1

63 62

xrl add,#n xrl add,A

Apply EX OR Logic to value in the dir. Addr.add and the number n(#n). Apply EX OR Logic to value in the dir.addr. add (name)and value in A. COMPLEMENTING ACCUMULATOR

3 2 2 1

F4

cpl A

Compliment the value in A

1 1 P

MOVING ABOUT IN THE ROM Opcode Mnemonic Description UNCONDITIONAL JUMPS 80 01+a 02 73 sjmpslabel ajmp plabel ljmp label jmp @A+DPTR Take a short jump to slabel (within + -128 bytes from PC) Take an absolute jump to plabel (within the same 2k page) Take a long jump to label (anywhere you like!,0000 to FFFFh) Take a jump to the address pointed by the sum of A + DPTR CONDITIONAL JUMPS ,NUMBERS B4 B8+N B6+p comp.& jump if not equal, the val. in A and the number n (#n)to slabel cjne A,#n,slabel cjne Rn,#n,slabel comp. & jump if not equal, the val. in Rn and the number n (#n)to slabel cjne@Rp,#n,slabel comp.& jmp if not eq, the val.in addr.pntd by Rp and numr. #n to slabel CONDITIONAL JUMPS,VALUES IN ADDRESSES B5 cjne A,add,slabel comp. & jump if not equal,the values in A and dir.addr. add to slabel CONDITIONAL JUMPS,AFTER DECREMENTING D5 D8+n djnzadd,slabel djnz Rn,slabel Decrement and jump if not zero,the value in dir. addr.add to slabel Decrement and jump if not zero,the value in Rn to slabel CONDITIONAL JUMPS ,ZERO IN ACCUMULATOR 70 60 jnzslabel jz slabel Jump if not zero,the value in A to slabel Jump if zero,the value in A to slabel SUBROUTINES, CALLS AND RETURNS 11+a 12 22 32 acall plabel lcall label ret reti An absolute call to the subroutine plabel (within 2k page) A long call to the subroutine label (0000 to FFFFh) Return from a subroutine Return from an Interrupt Service Routine 2 3 1 1 2 2 2 2 SP SP SP SP 2 2 2 2 3 2 2 2 3 2 C 3 2 C 3 2 C 3 2 C 2 2 3 1 2 2 2 2 B C Flags

BIT OPERATIONS Opcode Mnemonic Description BIT MOVEMENT A2 92 mov C,bit movbit, C move into Carry,the value in bit address(name) bit move into the bit address(name) bit,the value in the Carry bit 2 1 C 2 2 B C Flags

SETTING BITS D2 D3 setb bit setb C Set bit in the bit address(name) bit Set bit Carry CLEARING BITS C2 C3 clr bit clr C Clear bit in the bit address(name) bit Clear the Carry bit BIT LOGIC, AND 82 B0 anlC,bit anl C,^bit Apply and logic to the value in Carry and the value in bit address,bit Apply and logic to the val. in Carry and the inv.(^) val. in bit address,bit BIT LOGIC, OR 72 A0 orlC,bit orl C,^bit Apply or logic to the value in Carry and the value in bit address,bit Apply or logic to the val. in Carry and the inv.(^) value in bit address,bit COMPLEMENTS B2 B3 cplbit cpl C Complement the value in bit address(name) bit Complement the value in the Carry bit CONDITIONAL JUMPS 20 10 30 40 50 jb bit,slabel jbc bit,slabel jnb bit,slabel jC slabel jnC slabel Jump if bit is set in the bit address(name) bit toslabel Jump if bit is set in the bit address bit to slabel after clearing the bit Jump if not set, the bit in bit address(name) bit to slabel Jump if Carry is set to the address slabel (jump on carry to slabel) Jmp if not set, the Carry to the addr.slabel (jump on no carry to slabel) 3 2 3 2 3 2 2 2 2 2 2 1 1 1 C 2 2 C 2 2 C 2 2 C 2 2 C 2 1 1 1 C 2 1 1 1 C

Opcode Mnemonic

Description NO OPERATION

B C Flags

00

nop

No operation

1 1

Contact: praveensss@netscape.net

Reading C Declarations