Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ch 03 8051 的組合語言與系統發展.

Similar presentations


Presentation on theme: "Ch 03 8051 的組合語言與系統發展."— Presentation transcript:

1 Ch 的組合語言與系統發展

2 3.1 Instruction Format Instruction content: opcode + operand
Label: opcode destination operand , source oprand Example: MOV A, R1 Effect: (A)  (R1) Source operand: R1 Destination operand: A Operand type: memory location, register, constant, Number of operands: NOP 1 INC A 2 MOV R1, A 3 CJNE A,30H,NEXT [Jump to NEXT if (A) ≠ (30H)]

3 Assembly language vs machine code
MOV A, #60H “MOV” is a mnemonic, 給人看的。 74H 60H 74H is the opcode, 給 processsor 看的。

4 Label opcode operands comment
ORG 043H ; Program starts from 0043H START: MOV DPTR,#TABLE MOV R0,#6 N_BYTE: MOV A,#0 MOVC MOV P1,A CALL DELAY INC DPTR DJNZ R0,N_BYTE JMP START DELAY: MOV R7,#0 DL1: MOV R6,#0 DJNZ R6,$ DJNZ R7,DL1 RET TABLE: DB 00H,33H,66H,99H,0CCH,0FFH DS 3 DW 1234H,0ABCDH END

5 1 ;Label opcode operands comment
2 ORG 043H ; Program starts from 0043H START: E MOV DPTR,#TABLE MOV R0,#6 N_BYTE: MOV A,#0 A MOVC B F MOV P1,A D CALL DELAY A INC DPTR 13 D8 F DJNZ R0,N_BYTE JMP START DELAY: F MOV R7,#0 DL1: E MOV R6,#0 DE FE DJNZ R6,$ B DF FA DJNZ R7,DL1 D RET 23 E TABLE: E CC DB 00H,33H,66H,99H,0CCH,0FFH FF DS 3 ABCD DW 1234H,0ABCDH B END

6 3.2 Addressing Modes Example: 中壢市中大路300號 中央大學 Zip code = 32001

7 Addressing Modes Immediate data: MOV A, #60H (A)  #60H #: constant
“Immediate” means the data is in the instruction and can be accessed by the CPU immediately. The processor: Reads the opcode into the CPU Acts according to the opcode

8 Addressing Modes Direct addressing: MOV A,60H [ (A)  (60H) ]
60H = memory address E5H opcode 60H Address of data A CPU “Direct” means the data address is contained in the instruction and the CPU can access the data directly with the data address.

9 Addressing Modes Register addressing: MOV A,R3 [ (A)  (R3) ]
MOV A,13H [ (A)  (13H) ] R3 = register name 13H = register R3’s address (when RS1=1, RS0=0) (Register addressing 是direct addressing的一種) R2 R3 R4 12H 13H 14H

10 Address of R0 ~ R7 RS1, RS0 0, 0 0, 1 1, 0 1, 1 Register bank, selected RB0 RB1 RB2 RB3 R0 00H 08H 10H 18H R1 01H 09H 11H 19H R2 02H 0AH 12H 1AH R3 03H 0BH 13H 1BH R4 04H 0CH 14H 1CH R5 05H 0DH 15H 1DH R6 06H 0EH 16H 1EH R7 07H 0FH 17H 1FH PSW (Program Status Word) CY AC F0 RS1 RS0 OV P

11 Addressing Modes Indirect addressing: MOV A,@R0 @: pointer
@R0 = an address whose value is stored at R0 MOV DPTR, #1234H MOV    MOV SP,#30H PUSH H 5FH 28H 60H 3FH Data to be accessed 61H 41H R0 60H (3) (2) E6H opcode (1) A “Indirect” means the data address is not contained in the instruction CPU

12 Addressing Modes 30H  31H SP before & after pushing
Indirect addressing: MOV @: pointer @R0 = an address whose value is stored at R0 類似: 托人帶來支票 MOV DPTR, #1234H MOV    MOV SP,#30H PUSH H 30H 25H Top of stack before pushing 31H 38H Top of stack after pushing 60H Data to be pushed (3) 75H Opcode of mov SP,#30H 81H 30H C0H Opcode of push 60H 60H “Indirect” means the data address is not contained in the instruction (1) A (2) CPU

13 Addressing Modes Index addressing (只能用於程式記憶體) MOVC A , @A + DPTR
Possible base registers: DPTR, PC Possible index register: A

14 Addressing Modes 定址法 資料所在 Immediate 程式記憶體 Direct 資料記憶體 Register
Indirect Index

15 (SP) = the content of SP ((SP)) = the content of (SP) 30H SP 2FH 1AH 30H 85H 31H 69H

16 3-3 8051 指令集 49 one-operand 111 instructions 46 two-operand
指令集 49 one-operand 111 instructions 46 two-operand 16 three-operand

17

18

19

20

21

22 Instructions that can modify flags

23 3.4 Program Development 標記 Label 運算碼Opcode 運算元Operand(s) 註解 Comment
32 letters max. Label 加 : Label 不加 (定義data時); 被組譯成記憶體的位址值。 Opcode A mnemonic Operand Comment ;(分號) 之後的文字,給人看,組譯器不看。

24 5_1_1.asm Pseudo instruction,指示 assembler 的動作。 ORG 000H
MOV A,# B NEXT: MOV P2,A CALL DELAY RR A JMP NEXT ;============================== ; DELAY 0.1S DELAY: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 RET END Instruction, 給 processor 執行的。 # B 可寫成 #80H或 #128 A = B, B, B, B … Pseudo instruction,指示 assembler 不必組譯”END”之後的文字。

25 MOV A,1H MOV A,2H MOV A,3H . MOV A,99H END “END” 可以讓組譯程式停止組譯 “END”之後的程式。

26 Number Systems Number System Symbol Example Binary B Octal O Decimal
D, (Default) Hex H ASCII ‘ ’ or “ ”

27 虛擬指令 給組譯程式看的,指示如何組譯。 不是給 processor 執行的。 ORG n END EQU
To define a constant. e.g. LF EQU 0AH DB DW DS n REG

28

29 End of Lecture,

30 進入 DOS 視窗 打開 DOS 視窗的步驟: 所有程式  附屬應用程式  命令提示字元

31 DOS Commands Command >cd Change directory >dir Show directory

32 1 ;Label opcode operands comment
2 ORG 043H ; Program starts from 0043H START: E MOV DPTR,#TABLE MOV R0,#6 N_BYTE: MOV A,#0 A MOVC B F MOV P1,A D CALL DELAY A INC DPTR 13 D8 F DJNZ R0,N_BYTE JMP START DELAY: F MOV R7,#0 DL1: E MOV R6,#0 DE FE DJNZ R6,$ B DF FA DJNZ R7,DL1 D RET 23 E TABLE: E CC DB 00H,33H,66H,99H,0CCH,0FFH FF DS 3 ABCD DW 1234H,0ABCDH B END Thu Oct : Page 2 Why, jumping to F5H? Ans: PC = 0053H Destination = N_BYTE = 0048H 0048H -0053H FFF5H = F5H (以後再詳述。)

33

34 : E F A3D8F5 DE : F007E00DEFEDFFA CC 87 : FF 9D : ABCD D7 : FF

35 Format of Intel HEX file

36 3-5 系統發展的流程 圖3-5-1 (a) 非 ISP 之8051系統
將程式燒錄到 8051 較麻煩與耗時;所以最好先用ICE來驗證程式已經是正確的,才進行燒錄到 8051 的動作。 圖3-5-1 (b) 具 ISP 之8051系統 將程式燒錄到 8051 很簡易與快速,所以直接將程式燒錄到 8051以進行驗證;經過多次燒錄、除錯、修改以確定程式完全正確。 ICE (In-Circuit Emulator): price > NT$ Emulation 用另一套硬體去驗證目標硬體。 Simulation 用軟體模擬去驗證目標硬體。

37

38


Download ppt "Ch 03 8051 的組合語言與系統發展."

Similar presentations


Ads by Google