Professional Documents
Culture Documents
Overview
Data transfer instructions Addressing modes Data processing (arithmetic and logic) Program flow instructions
dest source
pointer, on stack to byte, stack pointer
Exchange instructions
XCH a, byte XCHD a, byte ;exchange accumulator and byte ;exchange low nibbles of ;accumulator and byte
mov B, #11
mov DPTR,#7521h
;DPTR = 0111010100100001
COUNT EGU 30
~ ~
MOV DPTR,#MYDATA
~ ~
Addressing Modes
Register Addressing either source or destination is one of CPU register
MOV R0,A
Addressing Modes
MOV A,R4 MOV A,R7 MOV R7,R6 ;Put 5 in R2 ;Put content of RAM at 5 in R2
Addressing Modes
Register Indirect the address of the source or destination is specified in registers Uses registers R0 or R1 for 8-bit address:
mov psw, #0 mov r0, #0x3C mov @r0, #3 ; use register bank 0
Addressing Modes
Register Indexed Mode source or destination address is the sum of the base address and the accumulator(Index)
;a M[4005]
Addressing Modes
;a M[1008]
Acc Register
A register can be accessed by direct and register mode This 3 instruction has same function with different code
0703 E500 0705 8500E0 0708 8500E0 mov a,00h mov acc,00h mov 0e0h,00h
SFRs Address
B always direct mode - except in MUL & DIV
0703 8500F0 0706 8500F0 0709 8CF0 070B 8CF0 mov b,00h mov 0f0h,00h mov b,r4 mov 0f0h,r4
SFRs Address
All SFRs such as
(ACC, B, PCON, TMOD, PSW, P0~P3, )
are accessible by name and direct address But both of them Must be coded as direct address
Direct addressing
Op code mov r3,0E8h
Direct address
;machine code=ABE8
070D 070E 070F 0710 0711 0712 0713 0714 0715 0716 0717
OpE8 code
E9 EA ED EF 2F F8 F9 FA FD FD
mov mov mov mov mov add mov mov mov mov mov
n n n a,r0
a,r1 a,r2 a,r5 a,r7 a,r7 r0,a r1,a r2,a r5,a r5,a
= = = = =
i
; i = 0 or 1
E7 93 83 E0 F0 F2 E3
Op code
Relative address
Op code
E106 00 00 00 00
1 2 3 4 5 6 7 8
A7-A0
07FEh
;next=706h
next:
020707 00 00 00 00
;next=0707h
Stacks
pop push
Stack
Stack-oriented data transfer
Only one operand (direct addressing) SP is other operand register indirect - implied
pop b
Note: can only specify RAM or SFRs (direct mode) to push or pop. Therefore, to push/pop the accumulator, must use acc, not a
Stack (push,pop)
Therefore
Push Push Push push Push Push Push Push Push Pop Pop Push Pop a r0 r1 acc psw b 13h 0 1 7 8 0e0h 0f0h ;is ;is ;is ;is ;is ;is invalid invalid invalid correct correct correct
;acc ;b
Exchange Instructions
two way data transfer
XCH a, 30h XCH a, R0 XCH a, @R0 XCHD a, R0 ; a M[30] ; a R0 ; a M[R0] ; exchange digit
a[7..4] a[3..0]
R0[7..4] R0[3..0]
mov C, 67h
mov C, 2ch.7