0% found this document useful (0 votes)
75 views

Introduction To Address Modes

This guide provides an overview of assembly programming for the 8051 microcontroller. It explains the basic concepts like internal and external RAM, accumulator, registers, and addressing modes. It then provides a reference of assembly instructions including data movement operations, arithmetic, logic, and bitwise operations. It also covers pushing and popping values on the stack, exchanging registers, and moving zero into the accumulator.

Uploaded by

kamalakarb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Introduction To Address Modes

This guide provides an overview of assembly programming for the 8051 microcontroller. It explains the basic concepts like internal and external RAM, accumulator, registers, and addressing modes. It then provides a reference of assembly instructions including data movement operations, arithmetic, logic, and bitwise operations. It also covers pushing and popping values on the stack, exchanging registers, and moving zero into the accumulator.

Uploaded by

kamalakarb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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   External RAM


Any Program can be
Accumulator     written using the
following operations:
A  (add)    
        Moving Data in RAM
Register Banks   Arithmetic operations
Rn  (add) Program Memory Logic Operations
      Moving Data in ROM
Rest Of The Bytes     Bit Operations and 
add     No operations!
       
          Comments Welcome!
The 8051 programmer's model

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 B C Flags


           
    MOVING NUMBERS      
           
74 mov A, # n move into A , a number n(#n) 2 1 P
78+n mov Rn, # n move into a register R0 to R7 (Rn), a number n(#n) 2 1  
75 mov add, # n move into a direct address(name) ,a number n(#n) 3 2  
76+p mov  @ Rp, # n move into an  address pointed by R0 or R1( @Rp) , a number n(#n) 2 1  
           
    MOVING ACCUMLATOR VALUES      
           
F8+n mov Rn,A move into a register R0 to R7(Rn) the value in A 1 1  
F5 mov add,A move into a direct address(name) , the value in A 2 1  
F6+p mov @ Rp,A move into an  address pointed by R0 or R1 (@Rp) , the value in A 1 1  
           
    MOVING REGISTERS VALUES      
           
E8+n mov A,Rn move into A , the value in the register R0 to R7(Rn) 1 1 P
88+n mov add,Rn move into a direct address(name) , the value in the register Rn 2 2  
           
    MOVING DIRECT ADDRESSES (NAME) VALUES      
           
E5 mov A,add move into A , the value in the  direct address(name) 2 1 P
A8+n mov Rn,add move into a register R0 to R7(Rn),the value in the  direct address(name) 2 2  
85 mov add1,add2 move into the direct address(name)1, the value in  address(name) 2 3 2  
A6+p mov @ Rp,add move into an address pointed by R0 or R1 (@Rp),the value in address 2 2  
           
    MOVING VALUES IN ADDRESSES POINTED BY R0 AND R1/PSW      
           
E6+p mov A,@Rp move into A , the value in the address pointed by R0 or R1(@Rp) 1 1 P
86+p mov add,@Rp move into the dir. Addr.add, value in the addr. pointed by R0 R1( @Rp)  2 2  
           
Opcode Mnemonic Description B C Flags
           
    MOVING DATA FROM ROM      
           
93 movC A,@A+DPTRmove Code into A ,from the address given by A+DPTR (@A+DPTR) 1 2 P
83 movC A,@A+PC move Code into A ,from the address given by A+PC (@A+PC) 1 2 P
           
    MOVING DATA FROM EXTERNAL RAM      
           
E0 movX A,@DPTR move from eXt.RAM into A, the value in the addr. pointed by DPTR  1 2 P
E2+p movX A,@Rp move from eXt.RAM into A, the val. in the addr. pointed by R0 or R1(@Rp)  1 2 P
           
    MOVING DATA INTO EXTERNAL RAM      
           
F0 movX @DPTR,A move into eXt.RAM at the addr. pointed by DPTR ,the value in A 1 2  
F2+p movX @Rp,A move into eXt.RAM at the addr. pointed by R0 or R1( @Rp),the value in A 1 2  
           
    MOVING A WORD INTO DPTR      
           
90 mov DPTR, # w move into DPTR, a word(two bytes) (# w) 3 2  
           

Opcode Mnemonic Description B C Flags


           
    Push and Pop      
           
C0 Push add Push value in dir.addr. add into addr. pointed by SP+1(push on stack)  2 2 SP
D0 Pop add Pop into the dir.addr.add,value in addr.pointed by SP  (pop from stack) 2 2 SP
           
    EXCHANGE      
           
C8+n xchA, Rn Exchange the values in A and Rn  1 1 P
C5 xch A, add Exchange the values in A and dir. Addr. add (name) 2 1 P
C6+p xch A, @Rp Exchange the values in A and the address pointed by R0 or R1 (@Rp) 1 1 P
D6+p xchD A, @Rp Exchange the LSDs of A and the value in addr.pointed by R0 or R1 (@Rp) 1 1 P
           
    SWAP      
C4 swap A Swap the nibbles(hex digits) in A 1 1  
           
    MOVE ZERO INTO A      
           
E4 clr A Clear the Accumulator 1 1 P
           
    ROTATION      
           
23 rlA Rotate left the contents of A(bits moved left once,msb into lsb) 1 1  
03 rr A Rotate right the contents of A(bits moved rt. once,lsb into msb) 1 1  
33 rlc A Rotate left into carry the contents of A (move msb into carry) 1 1 C  P
13 rrc A Rotate right into carry the contents of A (move lsb into carry)  1 1 C  P
           

ARITHMETIC OPERATIONS

Opcode Mnemonic Description B C Flags


           
    ADDITION      
           
24 add A,#n add value in A with the number n(#n) and store in A 2 1 C AC OV P
28+n add A,Rn add value in A with value in register Rn and store in A 1 1 C AC OV P
add value in A with value in dir.addr.add(name) and
25 add A,add    2 1 C AC OV P
store in A
add value in A with value in addr.pointed by R0 or
26+p add A,@Rp    1 1 C AC OV P
R1(@Rp) and store in A
           
    ADDITION WITH CARRY      
           
34 addcA,#n add carry,the value in A , and the number n(#n) . store  in A 2 1 C AC OV P
38+n addc A,Rn add carry, the value in A, and the value in Rn. store  in A 1 1 C AC OV P
35 addc A,add add carry,the value in A,and the value in dir. Addr.add. store  in A 2 1 C AC OV P
36+p addcA,@Rp add carry,the value in A,and the value in addr.pointed by R0 or R1(@Rp). 1 1 C AC OV P
           
    SUBTRACTION      
           
94 subbA,#n  sub borrow (C) from the value in A,and also the number n( #n) . 2 1 C  AC  OV  P
98+n subb A,Rn  sub borrow (C) from the value in A, and also the value in Rn. 1 1 C  AC  OV  P
95 subb A,add  sub borrow (C) from the value inA,and also the value in add. 2 1 C  AC  OV  P
96+p subb A,@Rp  sub borrow (C) from the val. in A,and also the val. pntd by R0 or R1(@Rp) 1 1 C  AC  OV  P
           
    MULTIPLICATION      
           
A4 mulAB Multiply the values in  A and B . store lsbyte in A,msbyte in B 1 4 C  OV  P
           
    DIVISION      
           
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 B C Flags


           
    INCREMENT      
           
04 incA Increment the value in A by 1 1 1 P
08+n inc Rn Increment the value in Register Rn by 1 1 1  
05 inc add Increment the value in dir.addr.add(name) by 1 2 1  
06+p inc @Rp Increment the value in the addr.pointed by R0 or R1(@Rp) by 1 1 1  
A3 inc DPTR Increment the value in DPTR by 1 1 2  
           
    DECREMENT      
           
14 dec A Decrement the value in A by 1 1 1 P
18+n dec Rn Decrement the value in Register Rn by 1 1 1  
15 dec add Decrement the value in dir.addr.add(name) by 1 2 1  
16+p dec @Rp Decrement the value in the addr.pointed by R0 or R1(@Rp) by 1 1 1  
           
    DECIMAL ADJUST ACCUMULATOR      
           
D4 da A Decimal adjust the Accumulator(BCD adjustment) 1 1 C P
           

LOGIC OPERATIONS

Opcode Mnemonic Description B C Flags


           
    AND LOGIC, IN ACCUMULATOR      
           
54 anl A,#n Apply AND Logic to value in A and the number n(#n).  2 1 P
58+n anl A,Rn Apply AND Logic to value in A and value in Rn.  1 1 P
55 anl A,add Apply AND Logic to value in A and value in addr.add.(name)  2 1 P
56+p anl A,@Rp Apply AND Logic to val. in A and val. in addr.pointed by R0 or R1(@Rp) 1 1 P
           
    OR LOGIC, IN ACCUMULATOR      
           
44 orl A,#n Apply OR Logic to value in A and the number n(#n).  2 1 P
48+n orlA,Rn Apply OR Logic to value in A and value in Rn.  1 1 P
45 orl A,add Apply OR Logic to value in A and value in addr.add (name)  2 1 P
46+p orlA,@Rp Apply OR Logic to val. in A and val. in addr.pointed by R0 or R1(@Rp). 1 1 P
           
    EXCLUSIVE OR LOGIC, IN ACCUMULATOR      
           
64 xrl A,#n Apply EX OR Logic to value in A and the number n(#n).  2 1 P
68+n xrl A,Rn Apply EX OR Logic to value in A and value in Rn.  1 1 P
65 xrl A,add Apply EX OR Logic to value in A and value in addr.add (name).  2 1 P
66+p xrl A,@Rp Apply EX OR Logic to val. in A and val. in addr.pointed by R0 or R1(@Rp). 1 1 P
           
    AND LOGIC, IN DIRECT ADDRESS      
           
53 anl add,#n Apply AND Logic to value in the dir.addr.add and the number n(#n).  3 2  
52 anl add,A Apply AND Logic to value in the dir.addr.add (name)and value in A. 2 1  
           
    OR LOGIC, IN DIRECT ADDRESS      
           
43 orl add,#n Apply OR Logic to value in the dir. Addr.add and the number n(#n).  3 2  
42 orl add,A Apply OR Logic to value in the dir.addr.add (name)and value in A. 2 1  
           
    EXCLUSIVE OR LOGIC, IN DIRECT ADDRESS      
           
63 xrl add,#n Apply EX OR Logic to value in the dir. Addr.add and the number n(#n).  3 2  
62 xrl add,A Apply EX OR Logic to value in the dir.addr. add (name)and value in A. 2 1  
           
    COMPLEMENTING ACCUMULATOR      
           
F4 cpl A Compliment the value in A 1 1 P
           

MOVING ABOUT IN THE ROM

Opcode Mnemonic Description B C Flags


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

BIT OPERATIONS

Opcode Mnemonic Description B C Flags


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

Opcode Mnemonic Description B C Flags


           
    NO OPERATION      
           
00 nop No operation 1 1  
           

Contact:
[email protected]

Reading C 
Declarations

You might also like