The 8051 Assembly Language
The 8051 Assembly Language
The 8051 Assembly Language
Address
• EQU
– Used to create symbols that can be used to represent
registers, numbers, and addresses
LIMIT EQU 2000
VALUE EQU LIMIT – 200 + 'A'
SERIAL EQU SBUF
COUNT EQU R5
MY_VAL EQU 0x44
Registers, numbers, addresses
mov R0, a
mov a, R0
• B – address 0F0h
Note: can only specify RAM or SFRs (direct mode) to push or pop.
Therefore, to push/pop the accumulator, must use acc, not a:
push acc
push a
stack pointer
stack
Arithmetic Instructions
Logic Instructions
Example:
SUBB A, #0x4F ; A A – 4F – C
mov a, r2
add a, #1 ; use add rather than increment to affect C
mov r2, a
mov a, r3
addc a, #0 ; add C to most significant byte
mov r3, a
MUL AB ; BA A * B
Integer Division
DIV AB ; divide A by B
A Quotient(A/B), B Remainder(A/B)
Example:
mov a, #0x23
mov b, #0x29
add a, b ; a 23 + 29 = 4C (wanted 52)
DA a ; a a + 6 = 52
XRL – eXclusive OR
00001111
CPL – Complement ORL 10101100
10101111
00001111
XRL 10101100
10100011
CPL 10101100
01010011
byte, #constant
rl a
C
rrc a
mov a, #0A9h ; a A9
add a, #14h ; a BD (10111101), C0
rrc a ; a 01011110, C1
mov a, #72h
swap a ; a 27h
clr c
rl a ;multiply by 2
inc a ;and add one
loop: mov a, P1
jz loop ; if a=0, goto loop,
; else goto next
; instruction
mov b, a
jz led_off
setb C
if a = 0 is true mov P1.6, C
send a 0 to LED sjmp skipover
else led_off: clr C
mov P1.6, C
send a 1 to LED skipover: mov A, P0
Absolute call
acall <address ll> ; stack PC
; PC address 11
Long call
lcall <address 16> ; stack PC
; PC address 16
ret ; PC stack
Main: ...
acall sublabel
...
...
sublabel:...
... the subroutine
ret
djnz
djnz
R5, $
R6, Loop0
subroutine
djnz R7, Loop1
ret
END
External ADC 1
Clock
source Serial Timer 4
Valid (UART) 1 ADC 0
External
7 External 6 Timer 3