UMBC | CMSC 391 -- Programming Microcontrollers |
The address register for 8-bit addresses can be R0 or R1 of the selected bank, or the Stack Pointer. The address register for 16-bit addresses can only be the 16-bit "data pointer" register, DPTR.
The address of the table entry in Program Memory is formed by adding the Accumulator to the base pointer.
Another type of indexed addressing is used in the "case jump" instruction. In this case the destination address of a jump instruction is computed as the sum of the base pointer and the Accumulator data.
UNQUOTE
mov a, #0h ; put 0 into the accumulator mov a, #11h ; put 11h into the accumulator mov a, #27 ; put 27 (decimal) = 1bh into the accumulator
mov 90h, a ; copy the accumulator contents to SFR 90h (Port 1)
Connect Port 4 bits to eight pushbuttons. Type, assemble, and download the following program. Port4 equ 0E8h ; Port 4 Port1 equ 090h ; Port 1 org 8000h ; set the origin mov a, Port4 ; copy the contents of Port 4 mov Port1, a ; copy the accumulator contents to Port 1 ljmp 8000h ; repeat This program reads the pushbuttons connected to Port 4 and copies their states to the LEDs connected to Port 1 bits. Press the RESET button to abort the program
org 8000h ; set the origin mov PSW, #10h ; select register bank 2 mov R0, a ; copy the contents of the accumulator into register 0 mov R7, b ; copy the contents of the B register into register 7 ljmp 0 ; return to the monitor
org 8000h ; set the origin mov a, #1 ; move the constant 1 into the accumulator mov 0E0h, 1 ; mov the constant 1 into SFR E0h ljmp 0 ; return to the monitor
Type and assemble the program. Then view the list file (with the .LST extension). Observe that the first move instruction is a 2-byte instruction, consisting of the bytes 74 and 01 (in hexadecimal). Note that the first 74 is interpreted as "take the following byte and place into the accumulator." That is the accumulator being the destination is implicitly coded in the instruction.
The second instruction moves the constant 1 into the SFR E0. This SFR is the accumulator. Therefore, effectively the two move instructions accomplish the same task. This instruction consists of three bytes: 75, E0, and 01, in hexadecimal. The first byte, 75, is interpreted as "of the following 2 bytes, the first is the address of a register, into which put the second byte." That is, the instruction "75" does not implicitly specify a target, rather it indicates that the address of the target is following.
org 8000h ; set the origin mov PSW, #0 ; select register bank 0 mov r0, #78 ; move 78h into register 0 mov @r0,#1 ; set the register whose address is specified ; in the R0 register to to the constant 1 ljmp 0
org 8000h ; set the origin mov a, #1 ; put the constant 1 into the accumulator mov DPTR, #9000h ; set the data pointer to 9000h movx @DPTR, a ; copy the accumulator into external data ; at the address specified by the data ; pointer. In this case, the 1 is copied ; into external memory location 9000h mov DPTR, #9001h ; set the data pointer to 9001h movx a, @DPTR ; copy the contents of external data ; memory at location 9001 into the ; accumulator mov a, #1 ; put the constant 1 into the accumulator mov R0, #0 ; put 0 into register 0 of the current ; bank ljmp 0
The following program evaluates the pattern of a seven-segment display given a single hexadecimal digit. It is assumed that the accumulator holds a value between 0 and Fh (15). The pattern is intended to be output from a port that is connected to a seven-segment display. The least significant bit is connected to segment1, and bit 6 is connected to segment g.
org 8000h ; set the origin mov DPTR, #8100h ; put the table base address into the ; data pointer mov a, #0 ; get the pattern 0 movc a, @a+DPTR ; a contains the pattern for 0 ljmp 0 ; return to the monitor org 8100h ; the table starts at 8100h db 0c0h ; 0 db 0f9h ; 1 db 0a4h ; 2 db 0b0h ; 3 db 99h ; 4 db 92h ; 5 db 82h ; 6 db 0f8h ; 7 db 80h ; 8 db 90h ; 9 db 88h ; a db 83h ; b db 0c6 ; c db 0a1h ; d db 86h ; e db 8eh ; f