Академический Документы
Профессиональный Документы
Культура Документы
Allison
FFFF
Lower 128 bytes (00-7F) Directly & Indirectly Addressable Upper 128 bytes (80-FF) Indirectly Addressable Only Special Function Registers (80-FF) Directly Addressable Only Expanded RAM Bytes (000-6FF) Indirectly Addressable Only by MOVX instructions with EXTRAM bit cleared in AUXR
6FF
FF
Upper 128
(Indirect Access)
FF
SFR
(Direct Access)
80 7F
80
Lower 128
Dir./Indir. Access
ACC, PSW, SP, Status and Control bits, Ports, Timers, Serial Control, etc.
0000
000
00
7F
General Purpose RAM
D0 B8 B0
7F 7E 7D 7C 7B 7A 79 78
D7 D6 D5 D4 D3 D2 -
BC BB BA B9 B8
30 2F 2E 2D 2C 2B 24 23 22 21 20
1F 18 17 10 0F 08 07 00
B7 B6 B5 B4 B3 B2 B1 B0 AF AC AB AA A9 A8
A8
A0 99 98 90 8D 8C 8B 8A 89 88 87 83 82 81 80
77 76 75 74 73 72 71 70 6F 6E 6D 6C 6B 6A 69 68
A7 A6 A5 A4 A3 A2 A1 A0 9F SBUF 9E 9D 9C 9B 9A 99 98
67 66 65 64 63 62 61 60
1F
1E 1D 1C 1B 1A 19 18
17 16 15 14 13 12 11 10 0F 0E 0D 0C 0B 0A 09 08
8F
TCON
P0
CPU can access data three ways Register Access Memory Access Immediate Access CPU has Eight Addressing Modes Immediate: operand is constant w/in instruction Register: operand is a register Direct: on-chip variable or hardware register Indirect: R0 and R1 may point to RAM Relative: Certain Jump Instructions Only Absolute: ACALL and AJMP only Long: LCALL and LJMP only Register Indirect Indexed Uses base register (PC or DPTR) and an offset to form the effective address
Immediate
operand is constant w/in instruction E.g. mov A, #12 operand is a register E.g. add A, R7
Register Addressing
Direct Addressing (for accessing all the SFRs)
on-chip variable or hardware register E.g. mov P1, A mov 90h, A E.g. mov SCON, #55h mov 98h, #55h
R0, R1 and DPTR may point to RAM/XRAM locations E.g. mov A, @R1 E.g. mov A, @DPTR
Relative Addressing
Two-byte instruction (2nd byte specifies PC relative offset -128 to +127) E.g. sjmp Inner_Loop (see previous slides)
Absolute Addressing
ACALL and AJMP instructions only Two byte instructions allow branch within 2k page of code memory by providing 11 lsb's of destination address (see previous slides)
(only for jump or call instructions)
Long Addressing
Indexed Addressing
LCALL and LJMP only Three byte instructions provide complete 16-bit destination address E.g. ljmp 8AF2h
(only for jump or movc instructions)
Uses a base register (PC or DPTR) and an offset (ACC) to form 16bit effective address for a JMP or MOVC Use to access data elements or tables in ROM E.g. movc A, @A+DPTR
Table-lookup Functions
Example: create a table of all the values of x2 (where 0 x 15) Write a subroutine that returns the square of x, where x is in ACC.
ORG db ljmp ..... lcall ..... ..... ORG mov movc ret ORG 0000h 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225 Main
X_Squared
Main:
Calc_x2
Calc_x2:
db
Example: create a table of all the values of sin (x) (where 0 x 90) Write a subroutine that returns sin(x), where x is in ACC.
;sin(x) values scaled by 255 ORG 0000h4, 9, 13, 18, 22, 27, 31, 35, 40 db 0, ljmp Main49, 53, 57, 62, 66, 70, 75, 79, 83 db 44, ..... ..... ..... 251,252,253,253,254,254,254,255,255,255,255 db lcall Calc_sin_x ..... ..... ORG 1E00h mov DPTR, #1E10h movc A, @A+DPTR ret ORG 1E10h db 0, 4, 9, 13, 18, 22, 27, 31, 35, 40 db 44, 49, 53, 57, 62, 66, 70, 75, 79, 83 ..... ..... db 251,252,253,253,254,254,254,255,255,255,255 ; 0 to 9 ; 10 to 19 ; ..... ; 80 to 90
sin_table Main:
Calc_sin_x:
; 0 to 9 ; 10 to 19 ; ..... ; 80 to 90
No_call: Exit:
3Fh Phone_bit, No_call Phone_bit DPTR, #400h Display Exit DPTR, #420h Display
;check to see if Phone_bit is high ;got a new message, so clear the bit ; load address of Yes_Msg ; and display the message ; and then exit ;Phone_bit was low, so load address ; of No_Msg and display it ;Now we will ......
Yes_Msg: No_Msg:
400h New Message Waiting, 0Dh, 0Ah, 0 420h No New Messages For You, 0Dh, 0Ah, 0
10