黄英_《单片机原理及应用》讲义_第1页
黄英_《单片机原理及应用》讲义_第2页
黄英_《单片机原理及应用》讲义_第3页
黄英_《单片机原理及应用》讲义_第4页
黄英_《单片机原理及应用》讲义_第5页
已阅读5页,还剩52页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1Chapter 3 : Instruction systemMicrocontroller Principle and Application主讲教师:黄英主讲教师:黄英2Contents: 3.1 Instruction format and Addressing Modes 3.2 Instruction Introduction Chapter 3 Instruction system3 Assemble Language: symbolic language Assembler: A computer program used to assemble Source Program A

2、ssembler Object program (Source codes) (Machine codes) Instruction Set: can not transplant directlyChapter 3 Instruction system3.1 Instruction format and Addressing Modes43.1 Instruction format and Addressing Modes3.1.1 Instruction format Instruction = opcode operand = opcode destination operand, so

3、urce operand Instruction types: 1-byte Instruction: includes opcode and operand 2-byte Instruction: 1th byte is opcode 2th byte is operand 3-byte Instruction: 1th byte is opcode 2th, 3th byte are operands53.1 Instruction format and Addressing Modes Addressing: how to get the location of (source) ope

4、rand. Addressing Modes: 7 types 1. Register Addressing 2. Direct Addressing 3. Register Indirect Addressing 4. Immediate Constants Addressing 5. Indexed Addressing 6. Boolean Addressing 3.1.2 Addressing Modes 7. Relative Addressing (get the jumping destination address of PC )63.1.2 Addressing Modes1

5、. Register Addressing Operand: denoted by register. For example: MOV A, R0 Addressing Range: General register: 4 banks 8( R0 R7 ) 32 registers Some SFRs: A, AB, DPTR, etc.73.1.2 Addressing Modes Operand: denoted directly by 8-bit address. For example: MOV A, 3AH Addressing Range: Lower 128 bytes of

6、internal RAM SFRs2. Direct Addressing83.1.2 Addressing Modes Operand: specifies a register to contain operand address with the prefix “” . Addressing Range: Lower 128 bytes of internal RAM (8-bit address ) 64KB of external RAM (16-bit address )3. Register Indirect Addressing address register of 8-bi

7、t address: Ri(i = 0, 1) SP (PUSH, POP) address register of 16-bit address: DPTR For example: MOV A, R0 MOVX A, DPTR93.1.2 Addressing Modes Operand: specifies the value of a 8-bit or 16-bit constant with the prefix “#” . For example: MOV A, #3AH MOV DPTR, # 0200H4. Immediate Constants Addressing103.1

8、.2 Addressing Modes Only three instruction: MOVC A, A+DPTR MOVC A, A+PCJMP A+DPTR Addressing Range: Program Memory (ROM)5. Indexed Addressing Program Memory can only be accessed via this mode. Designed for reading look-up tables in Program Memory or executing unconditional jumps. A 16-bit base regis

9、ter (DPTR or PC)points to the base address of table, and A is set up with the table entry number. The 16-bit address in ROM is formed by adding the A data to the base pointer.113.1.2 Addressing Modes Addressing Range: 1. Bit addressable area in Internal RAM cell address: 20H2FH, bit address: 00H7FH

10、2 ways to specifies the addressing bit: Cell address + bit: 20H.6 Bit address: 06H 6. Boolean Addressing2. Addressable bit in SFRs 4 ways to specifies the addressing bit SFR symbol + bit: PSW.5 Bit address: 0D5H Cell address + bit: 0D0H.5 Bit name: F0123.1.2 Addressing Modes offset Range: - 128(back

11、ward) + 127(forward) 7. Relative Addressing Used for getting the jumping destination address of PC in Jump Instruction. Destination address = PC + rel PC = (address + byte number ) of Jump instruction rel = 8-bit relative offset byteReturn13Chapter 3 Instruction system3.2 Instruction Introduction (1

12、11 items) Data transfer instructions (29 items) Arithmetic instructions (24 items) Logical instructions (24 items) Jump instructions (17 items) Boolean instructions (17 items) Port Access instructions The symbol meaning of Instruction formatReturn143.2 Instruction Introduction3.2.1 The symbol meanin

13、g of Instruction formatReturn See P45153.2 Instruction Introduction General format: MOV , Source operand: A, Rn, Direct address, Indirect address register, #data, #data16 Destination operand: A, Rn, Direct address, Indirect address register 3.2.2 Data transfer instructions (29 items)16 8-bit data: M

14、OV A, #data MOV A, 00H MOV direct, #dataMOV 3CH, 0FFH MOV Rn, #dataMOV R5, 0FH MOV Ri, #dataMOV R1, 0CH 16-bit data: MOV DPTR, #data16 MOV DPTR, 0200H3.2.2 Data transfer instructions1. Data Transfer of internal RAM(1) Transfer immediate Constants17 MOV direct2, direct1 MOV 50H,30H MOV direct, RnMOV

15、32H, R1 MOV Rn, directMOV R0, 33H MOV Ri, directMOV R1, 0D0H MOV direct, Ri MOV 0D0H, R1 3.2.2 Data transfer instructions (2) Transfer data among internal RAM cells18 MOV A, Rn MOV A, R3 MOV Rn, AMOV R2, A MOV A, directMOV A, 0E0H MOV direct, A MOV 30H, A MOV A, Ri MOV A, R0 MOV Ri, AMOV R1, A 3.2.2

16、 Data transfer instructions (3) Transfer data by A19 (1) Transfer data by DPTR MOVX A, DPTR MOVX DPTR, A (2) Transfer data by Ri MOVX A, Ri MOVX Ri, A They are Read/Write instructions of external RAM.3.2.2 Data transfer instructions2. Data Transfer of external RAM20 MOVC A, A+DPTR MOVC A, A+PC Read

17、instructions of program memory. Indexed addressing mode Designed for reading look-up tables in Program Memory3.2.2 Data transfer instructions For example: PC A 2000 HBA: INC A ; 2001 01H 2001 MOVC A, A+PC; 2002 30H 2002 RET; 2003 2003 DB 30H 2004 DB 31H 2005 DB 32H 3. Data Transfer of Program Memory

18、21 XCH A, Rn XCH A, direct XCH A, Ri XCHD A, Ri ;(A3A0) (Ri3Ri0) SWAP A ; (A3A0) (A7A4) 3.2.2 Data transfer instructions4. Data Exchange Instruction For example: MOV R0, #20H ; R0 = 20H MOV A, #3FH; A = 3FH MOV 20H, #75H; (20H)= 75H XCHD A, R0; A = 35H, (20H)= 7FH SWAP A ; A = 53H 22 PUSH direct ; S

19、P SP+1, (SP)(direct) POP direct; (direct)(SP), SP SP - 1 3.2.2 Data transfer instructions5. Stack operation InstructionReturn233.2 Instruction Introduction For unsigned constants Including the following 7 types: 3.2.3 Arithmetic Instructions(24 items) 1. Addition Instructions2. Addition Instructions

20、 with carry bit3. Subtraction Instructions with carry bit4. Increment Instructions5. Decrement Instructions6. Multiplication/Division Instructions 7. Decimal-Adjust Instructions243.2.3 Arithmetic InstructionsADD A, RnADD A, R6ADD A, directADD A, 30HADD A, RiADD A, R1 ; A A +(R1) ADD A, #dataADD A, #

21、0FH1. Addition Instructions Affect PSW If bit 3 has carry bit, then AC=1, else AC=0. If bit 7 has carry bit, then CY=1, else CY=0. If bit 6 has carry bit but not bit 7, or If bit 7 has carry bit but not bit 6, then OV=1, else OV=0. 253.2.3 Arithmetic InstructionsADDC A, RnADDC A, R6 ; A A + R6 + CY

22、ADDC A, directADDC A, 30HADDC A, RiADDC A, R1 ; A A +(R1)+ CY ADDC A, #dataADDC A, #0FH2. Addition Instructions with carry bit263.2.3 Arithmetic InstructionsSUBB A, Rn SUBB A, R6 ; A A R6 CY SUBB A, direct SUBB A, 30HSUBB A, Ri SUBB A, R1 ; A A (R1) CY SUBB A, #data SUBB A, #0FH3. Subtraction Instru

23、ctions with carry bit Affect PSW If bit 3 has carry bit, then AC=1, else AC=0. If bit 7 has carry bit, then CY=1, else CY=0. If bit 6 has carry bit but not bit 7, or If bit 7 has carry bit but not bit 6, then OV=1, else OV=0. 273.2.3 Arithmetic InstructionsINC A ; A A + 1 INC Rn INC R6INC direct INC

24、 50H ; (50H) (50H)+ 1INC Ri INC R0 ; (R0) (R0)+ 1INC DPTR ; DPTR DPTR + 1 4. Increment Instructions NOT Affect PSW, except “P” flag bit. 283.2.3 Arithmetic InstructionsDEC A ; A A 1 DEC Rn DEC R6DEC direct DEC 50H ; (50H) (50H) 1DEC Ri DEC R1 ; (R1) (R1) 1 NOT Affect PSW, except “P” flag bit. 5. Dec

25、rement Instructions293.2.3 Arithmetic Instructions (1)MUL AB ; A low byte of product ; B high byte of product Affect PSW : P, OV, CY=0 If the product is greater than 255(0FFH), then OV=1, else OV=0. 6. Multiplication/Division Instructions(2)DIV AB ; A dividend B divisor (Before) ; A quotient B remai

26、nder (After) Affect PSW : If CY=0 If divisor B is 00H, then OV=1, else OV=0. 303.2.3 Arithmetic Instructions DA A Affect PSW:P, AC, CY ONLY apply to decimal addition, not decimal subtraction. 7. Decimal-Adjust InstructionsFor example:Assumed that: A = 56H, R5=67HExecute: ADD A, R5 DA APlease fill re

27、sults in the blanks: A = 23H, CY = 1Return313.2 Instruction Introduction Including the following 5 types: 1. ANL operation Instructions2. ORL operation Instructions3. XRL operation Instructions4. CLR/CPL operation Instructions5. Rotation bits Instructions3.2.4 Logical instructions(24 items)323.2.4 L

28、ogical instructions1. ANL operation InstructionsANL A, Rn; A A Rn ANL A, direct; A A (direct) ANL A, Ri ; A A (Ri) ANL A, #data; A A data ANL direct, A; direct direct AANL direct, #data; direct direct data333.2.4 Logical instructionsORL A, Rn; A A Rn ORL A, direct; A A (direct) ORL A, Ri ; A A (Ri)

29、ORL A, #data; A A data ORL direct, A; direct direct AORL direct, #data; direct direct data2. ORL operation Instructions343.2.4 Logical instructionsXRL A, Rn; A A Rn XRL A, direct; A A (direct) XRL A, Ri ; A A (Ri) XRL A, #data; A A data XRL direct, A; direct direct AXRL direct, #data; direct direct

30、data3. XRL operation Instructions 0101 1100 = 1001 (rule:different = 1,same = 0)353.2.4 Logical instructionsCLR A; A 0 CPL A; A A 4. CLR/CPL operation InstructionsRL A; An+1 An , A0 A7 RR A; An An1 , A7 A0 RLC A; An+1 An , CY A7 , A0 CY RRC A ; An An1 , CY A0 , A7 CY 5. Rotation bits Instructions Re

31、turn363.2 Instruction Introduction Including the following 4 types: 1. Unconditional Jump Instructions(4 items)3.2.5 Jump instructions(17 items)2. Conditional Jump Instructions (8 items)3. Call/Return Instructions (4 items)4. No operation Instructions (1 item)Return373.2.5 Jump instructions1. Uncond

32、itional Jump Instructions Including the following 4 types: 1-1 Long Jump Instructions1-2 Absolute Jump Instructions1-3 Short Jump Instructions1-4 Indexed Addressing Jump Instructions Jump location: in the program memory. 383.2.5 Jump instructions Jump Address Range: 64KB (216 ) 1-1 Long Jump Instruc

33、tionsLJMP address16; PC address16 393.2.5 Jump instructions Jump Address Range: 2KB (211 ) AJMP address11; PC PC + 2 ; PC10-0 address11 1-2 Absolute Jump InstructionsFor example:2070H AJMP 16AH ; PC = 2070H + 2 = 2072H ; PC: 2072 0010 0000 0111 0010 ; address11: 16A 0000 0001 0110 1010 ; new PC = 00

34、10 0001 0110 1010 = 216AH403.2.5 Jump instructions rel = 8-bit signed relative offset byte Jump Address Range: -128B+127B(256Byte, 28 ) SJMP rel; PC PC + 2 ; PC PC + rel1-3 Short Jump InstructionsFor example: 835AH SJMP 35H ; PC = 835AH + 2 + 35H = 8391H 835AH SJMP 0E7H ; PC = 835AH + 2 - 19H = 8343

35、HSTOP: SJMP STOPSTOP: SJMP $413.2.5 Jump instructionsJMP A+DPTR; PC = A + DPTR1-4 Indexed Addressing Jump InstructionsReturn423.2.5 Jump instructions Including the following 3 types: 2-1 Judgement A Jump Instructions2-2 Comparison Jump Instructions2-3 Decrement Jump Instructions2. Conditional Jump I

36、nstructions NOT affect PSW433.2.5 Jump instructionsJZ rel; if A 0, then PC PC + 2 + rel ; if A 0, then PC PC + 22-1 Judgement A Jump InstructionsJNZ rel ; if A 0, then PC PC + 2 + rel ; if A 0, then PC PC + 2443.2.5 Jump instructionsCJNE A, #data, rel ; if A data, then PC PC + 3 + rel if A data, the

37、n CY 1 if A data, then CY 02-2 Comparison Jump InstructionsCJNE A, direct, rel ; if A (direct), then PC PC + 3 + rel if A (direct), then CY 1 if A (direct), then CY 0CJNE Rn, #data, rel ; if Rn data, then PC PC + 3 + rel if Rn data, then CY 1 if Rn data, then CY 0CJNE Ri, #data, rel ; if (Ri) data,

38、then PC PC + 3 + rel if (Ri) data, then CY 1 if (Ri) data, then CY 0453.2.5 Jump instructionsDJNZ Rn, rel ; Rn Rn - 1 if Rn 0, then PC PC + 2 + rel if Rn 0, then PC PC + 2 2-3 Decrement Jump InstructionsDJNZ direct, rel ; (direct) (direct)- 1if (direct) 0, then PC PC + 3 + relif (direct) 0, then PC

39、PC + 3 Return463.2.5 Jump instructions Including the following 3 types: 3-1 Absolute Call Instructions3-2 Long Call Instructions3-3 Return Instructions3. Call/Return Instructions473.2.5 Jump instructionsACALL ; PC PC + 2 SP SP + 1 SP PC7-0 (low 8-bit breakpoint address)SP SP + 1 SP PC15-8 (high 8-bi

40、t breakpoint address) PC10-0 address11 3-1 Absolute Call Instructions Subroutine Call Range: 2KB (211) For example: ACALL SUBRTN_NAME1483.2.5 Jump instructionsLCALL ; PC PC + 3 SP SP + 1 SP PC7-0 (low 8-bit breakpoint address)SP SP + 1 SP PC15-8 (high 8-bit breakpoint address) PC address16 Subroutin

41、e Call Range: 64KB (216) 3-2 Long Call InstructionsFor example: LCALL SUBRTN_NAME2493.2.5 Jump instructionsRET ; PC15-8 SP (Fetch high 8-bit breakpoint address) SP SP - 1 PC7-0 SP (Fetch low 8-bit breakpoint address)SP SP - 1 Return from Subroutine 3-3 Return InstructionsRETI ; PC15-8 SP (Fetch high

42、 8-bit breakpoint address) SP SP - 1 PC7-0 SP (Fetch low 8-bit breakpoint address) SP SP - 1 Return from Interrupt Return504. No operation InstructionsNOP; PC PC + 1, one machine cycle instruction3.2.5 Jump instructionsReturn513.2 Instruction Introduction Including the following 4 types instructions: 1. Bit Transfer Instructions2. Bit SETB/CLR Instructions3. Bit logical operation Instructions4. Bit Jump Instructions Hardware resources of bit processor:

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论