SLIDE 1
Assembly Language Techniques Programming the MCS51 Microcontroller - - PowerPoint PPT Presentation
Assembly Language Techniques Programming the MCS51 Microcontroller - - PowerPoint PPT Presentation
Assembly Language Techniques Programming the MCS51 Microcontroller Background Data Transfer Instructions Data Processing Instructions Program Flow Control Instructions Interrupts Chatchai Jantaraprim (cj@coe.psu.ac.th) Program Flow Control
SLIDE 2
SLIDE 3
Program Flow Control Instructions
Unconditional Jump Instructions SJMP<rel>
Short jump, 127 byte ahead, 128 byte behind
AJMP<addr11>
Absolute jump, 11-bit (2K Block)
LJMP<addr16>
Long jump, 16-bit (Entire 64K address space)
JMP@A+DPTR
Long jump, from lookup table
- rg 8000horg 8000h
mov C, P1.0start:mov C, P1.0 mov P1.1, Cmov P1.1, C ljmp 8000hsjmp start
SLIDE 4
Program Flow Control Instructions
Unconditional Jump Instructions (cont.)
80001org8000h 8000 A2902start:movC, P1.0 8002 92913movP1.1, C 8004 0280004ljmpstart 0000=5end 80001org8000h 8000 A2902start:movC, P1.0 8002 92913movP1.1, C 8004 80FA4sjmpstart 0000=5end 80001org8000h 8000 A2902start:movC, P1.0 8002 92913movP1.1, C 8004 01004ajmpstart 0000=5end
SLIDE 5
Program Flow Control Instructions
Unconditional Jump Instructions (cont.)
90001org9000h 9000 A2902start:movC, P1.0 9002 92913movP1.1, C 9004 0290004ljmpstart 0000=5end 90001org9000h 9000 A2902start:movC, P1.0 9002 92913movP1.1, C 9004 80FA4sjmpstart 0000=5end 90001org9000h 9000 A2902start:movC, P1.0 9002 92913movP1.1, C 9004 01004ajmpstart 0000=5end
SLIDE 6
Program Flow Control Instructions
Unconditional Jump Instructions (cont.) Indexed Jump jump @a+dptr
... anl a, #3 rl a rl a mov dptr, #jump_table jmp @a+dptr jump_table: ljmp routine_0 nop ljmp routine_1 nop ljmp routine_2 nop ljmp routine_3 ...
SLIDE 7
Program Flow Control Instructions
Unconditional Jump Instructions (cont.) Short jump and Absolute jump is relocatable, but with limited jump range Long jump is not relocatable, but provides program to jump to anywhere Indexed jump provides a convenient means to construct a jump table
SLIDE 8
Program Flow Control Instructions
Conditional Jump Instructions JZ<rel> JNZ<rel> JC<rel> JNC<rel> JB<bit>, <rel> JNB<bit>, <rel> JBC<bit>, <rel> CJNEA, direct, <rel> CJNEA, #data, <rel> CJNERn, #data, <rel> CJNE@Ri, #data, <rel> DJNZRn, <rel> DJNZdirect, <rel>
SLIDE 9
Program Flow Control Instructions
Conditional Jump Instructions (cont.)
delay: mov r7, #0 mov r6, #0 delay0: djnz r6, $ djnz r7, delay0 ret
SLIDE 10
Program Flow Control Instructions
Call and Return Instructions
Call push PC on stack before branch Return pop PC off stack
Call and return are necessary to implement subroutines. ACALL<addr11>
branch within 2K block
LCALL<addr16>
branch anywhere in 64K
RET
pop PC
RETI
pop PC and reset interrupt hardware
SLIDE 11
Program Flow Control Instructions
Call and Return Instructions (cont.)
LED_flagequ0Fh
- rg8000h
start: jbLED_flag, LED_OFF setbLED_flag clrP1.0 lcalldelay sjmpstart LED_OFF: clrLED_flag setbP1.0 lcalldelay sjmpstart
SLIDE 12
Program Flow Control Instructions
Call and Return Instructions (cont.) Computed goto techniques:
- rg8000h
movdptr, #next pushdph pushdpl mova, #81h pushacc clra pushacc ret next: ljmp8000h
- rg8100h