Module-3 - Addressing Mode and Instruction Sets
Module-3 - Addressing Mode and Instruction Sets
• These instruction are used to transfer the data from source operand to
destination operand. All the store, move, load, exchange input and output
instructions belong to this to this group.
• MOV A, Rn // Move Reg to Acc
• MOVX A,@DPTR // Move external RAM to Accumulator
• PUSH direct // PUSH direct byte on to stack ( Ex. - PUSH 0E0H/05)
• POP direct // POP direct byte from stack ( Ex. - POP 0F0H/06)
8051 Instruction Set
Branch and Looping Instructions
• These instructions are used for both branching as well as looping.
• These instructions include conditional & unconditional jump or loop instructions.
Conditional Jump Instructions
• JC // Jump if carry equal to one
• JNC // Jump if carry equal to zero
• JB // Jump if bit equal to one
• JNB // Jump if bit equal to zero
• JBC // Jump if bit equal to one and clear bit
• JZ // Jump if A=Zero
• JNZ // Jump if A not equal to zero
• DJNZ // Decrement and Jump if not equal to zero.
8051 Instruction Set
Unconditional Jump Instructions
• SJMP // Short jump { SJMP (address)}
• LJMP // Long jump { LJMP (address 16)}
• AJMP // absolute jump to memory location {AJMP (address 11)}
• ajmp 2000h or ajmp next
• JMP @A+DPTR
• LCALL // long call - allows to jump to a subroutine anywhere in the 64K code
space.
• ACALL //absolute call - allows to jump to a subroutine within the same 2K page
• JMP //jump
• Examples:
• ANL C, bit (and carry with bit)
• CLR C
• SETB C
• SETB bit (SETB PSW.3)
Add values at location 78h, 79h and store at 7Ah (z= x+y)
x equ 78h
Y equ 79h
Z equ 7Ah
org 00h
ljmp main
org 0100h
main: mov a, x
add a, y
mov z, a
end
16 –bit addition using LJMP
x equ 78h
Y equ 7Ah
Z equ 7Ch
org 00h
ljmp main
org 0100h
main: mov a, x
add a, y
mov z, a
mov a, x+1
addc a, y+1
mov z+1, a
end
Increment of 16 –bit word/number
• Assume 16-bit number in r3:r2
org 0000h
mov a, r2
add a, #01
mov r2, a
mov a, r3
addc a, # 0
mov r3, a
end
Decimal adjust for BCD addition
• DA a; decimal adjust a
• Used for BCD addition . Add 6 to either higher or lower nibble after an
addition to create a valid BCD number.
• Example:
Mov a, #23h
mov b, #29h
add a, b // a= 23h+29h = 4ch (wanted 52)
DA a // a= a+ 6 = 52
To add 3 to accumulator 4 times
• DJNZ Rx, add // repeat the label add till Rx=0
• CJNE
• Example
Mov a , #0 // clear accumulator
Mov r2, #04 //load counter r2=4
Again:
add a, #03h //add 03 to accumulator
DJNZ r2, Again //repeat until r2=0
mov r5, a // save in R5