Professional Documents
Culture Documents
Home
Contact
Links Assembly Reference
The 8051 Programmer's Reference: A must have for Assembly Programming
This guide hel Understanding Visualisation o instruction Se (Compare the Mnemonic and Description) Internal RAM Accumulator A (add) Register Banks Rn (add) Rest Of The Bytes add External RAM
Program Memory
Moving Data in Arithmetic ope Logic Operatio Moving Data in Bit Operations No operations!
Indirect Addressing R0 R1
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
B C Flags
93 83
movC move Code into A ,from the address given by A+DPTR (@A+DPTR) A,@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 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) movX A,@Rp MOVING DATA INTO EXTERNAL RAM
1 2 P 1 2 P
F0 F2+p
movX @DPTR,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 movX @Rp,A MOVING A WORD INTO DPTR
1 2 1 2
90
mov DPTR, # w
3 2
Opcode Mnemonic
B C Flags
C0 D0
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
xchA, Rn
1 1 P
C5 C6+p D6+p
Exchange the values in A and dir. Addr. add (name) 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
2 1 P 1 1 P 1 1 P
C4
swap A
1 1
E4
clr A
1 1 P
23 03 33 13
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 2 1 2 1 1 1 1 1 B C Flags
2 1 C AC OV 1 1 C AC OV
2 1 C AC OV
1 1 C AC OV
C AC OV C AC OV C AC OV C AC OV
94 98+n 95 96+p
sub borrow (C) from the value in A,and also the number n( #n) . 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
2 1 2 1
1 1 1 1
C C C C
AC AC AC AC
O O O O
A4
mulAB
1 4 C OV P
84
divAB
1 4 C OV P
Opcode Mnemonic
Description INCREMENT
B C Flags
04 08+n 05 06+p A3
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
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
1 1 CP
LOGIC OPERATIONS
Opcode Mnemonic
B C Flags
54 58+n 55 56+p
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
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
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
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
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
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
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 cjne A,#n,slabel comp.& jump if not equal, the val. in A and the number n (#n)to slabel cjne Rn,#n,slabel comp. & jump if not equal, the val. in Rn and the number n (#n)to slabel cjne comp.& jmp if not eq, the val.in addr.pntd by Rp and numr. #n to slabel @Rp,#n,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
A2 92
move into Carry,the value in bit address(name) bit move into the bit address(name) bit,the value in the Carry bit SETTING BITS
2 1 C 2 2
D2 D3
Set bit in the bit address(name) bit Set bit Carry CLEARING BITS
2 1 1 1 C
C2 C3
Clear bit in the bit address(name) bit Clear the Carry bit BIT LOGIC, AND
2 1 1 1 C
82 B0
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
2 2 C 2 2 C
72 A0
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
2 2 C 2 2 C
B2 B3
cplbit cpl C
Complement the value in bit address(name) bit Complement the value in the Carry bit CONDITIONAL JUMPS
2 1 1 1 C
20 10 30 40 50
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
Opcode Mnemonic
Description NO OPERATION
B C Flags
00
nop
No operation
1 1
Contact: praveensss@netscape.net
Reading C Declarations