1 / 66

第四章 微处理器结构和指令集

第四章 微处理器结构和指令集. 4.1 微处理器的内部寄存器结构 4.2 S12 汇编指令集 4.3 指令按功能分类 4.4 指令按寻址方式分类 4.5 用汇编语言编写程序. Page 1. 4.1 微处理器的内部寄存器结构 —— 典型的 16 位微处理器. Numbering and coding systems. 8-Bit 累加器 A and B. 8-Bit 累加器 A and B. 7. 7. 0. 0. 7. 7. B. B. 0. 0. A. A. or 16-Bit 寄存器 D.

Download Presentation

第四章 微处理器结构和指令集

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第四章 微处理器结构和指令集 • 4.1 微处理器的内部寄存器结构 • 4.2 S12汇编指令集 • 4.3 指令按功能分类 • 4.4 指令按寻址方式分类 • 4.5 用汇编语言编写程序 Page1

  2. 4.1 微处理器的内部寄存器结构——典型的16位微处理器 Numbering and coding systems 8-Bit 累加器 A and B 8-Bit 累加器 A and B 7 7 0 0 7 7 B B 0 0 A A or 16-Bit 寄存器 D or 16-Bit 寄存器 D 15 15 D D 0 0 间址寄存器 X 间址寄存器 X 6 6 GPAGE * GPAGE * 0 0 15 15 X X 0 0 间址寄存器 Y 间址寄存器 Y 15 15 Y Y 0 0 7 7 PPAGE * PPAGE * 0 0 Stack Pointer Stack Pointer 7 7 RPAGE * RPAGE * 0 0 15 15 SP SP 0 0 Program Counter Program Counter 15 15 PC PC 0 0 7 7 EPAGE * EPAGE * 0 0 7 7 0 0 0 0 0 0 0 I P L 0 0 0 0 0 I P L Condition Codes Register CCR Condition Codes Register CCR S S X X H H I I N N Z Z V V C C Page2

  3. 4.1 微处理器的内部寄存器结构——典型的16位微处理器 Numbering and coding systems 0 S 0 X H 0 0 I 0 N Z I V P C L CCR 7 0 条件码计数器 CCR 进位/借位标志C 溢出标志V 为零标志Z 为负标志N 中断屏蔽位I Half Carry (For BCD) 非屏蔽中断允许X STOP 运行模式禁止位 Interrupt priority level IPL(0~7)0:关中断 Page3

  4. 4.1 微处理器的内部寄存器结构——基本内存空间分配 $0000 $0000 2KB I/O空间 2KB I/O空间 $0800 外设寄存器 $0800 1KB EEPROM 2KB EEPROM $0C00 1KB EEPROM $1000 $1000 12KB RAM 4KB RAM $2000 8KB RAM 变量、堆栈 $4000 $4000 16KB FLASH 48KB FLASH 程序代码 $8000 16KB FLASH $C000 16KB FLASH 复位、中断 向量区 $FF00 复位、中断 向量区 $FFFF $FFFF 典型的64KB存储空间分配 MC9S12XS128 Page4

  5. 4.2 S12X 汇编指令集 Numbering and coding systems • 汇编语言是机器码语言,与CPU的硬件结构紧密相关,不同的CPU其汇编语言是不同的,程序不能移植,使用不便。 • 高级语言:与计算机的硬件结构没多大关系。程序通用性好,便于移植。如:C语言、BASIC语言。 • 虽然应用程序可以主要用C语言来开发,但与时序相关的硬件操作必须用汇编语言编写,因为汇编语言程序可以准确地计算出某段程序的执行时间。 • 汇编语言使用助记符、符号和数字等来表示的程序语言。容易理解和记忆,它与机器语言一一对应。 Page5

  6. 汇编语言指令格式 Numbering and coding systems [标号:]操作码 [第一操作数][,第二操作数] [,第三操 作数][,第四操作数][;注释] 操作码:指令代码,以符号形式给出该指令执行什么操 作。 由2~5个英文字母表示。 操作数:参与操作的数据或数据存放的地址。 [ ]表示可选。 要养成直接读操作助记符、直接记英语含义的习惯。 如 CLR 读作 clear LDAA 读作 load accumulator A Page6

  7. 4.3指令按寻址方式分类 Numbering and coding systems 17 1.隐含寻址(inherent) 隐含寻址指令中只有操作码,没有操作数。 如 PSHA ;(SP)-1→SP,(A)→(SP) 执行前执行后 A 17 17 A 4000 SP 3FFF SP Data memory FF 3FFF 4000 Page7

  8. 4.3指令按寻址方式分类 2.立即数寻址(immediate) 操作码后有一个或两个字节的操作数,该操作数表示一个8或16位的数值。立即数由#后面跟数据表示。如: LDY #$3000 ;$表示后面是十六进制数字 0x LDAA #10 ;缺省为十进制 ORAA #%0001011 ; %表示后面是二进制数字 0b Page8

  9. 4.3指令按寻址方式分类 3.直接寻址(direct) 操作数为单字节地址,高位默认为$00,只能对$00~$FF存储单元进行寻址。 $00~$FF是I/O口寄存器地址。 如: LDAA $40 ; STAA <$40 ; (A)→ (0040) 在单字节地址前加<就表示的是直接寻址。 Page9

  10. 4.3指令按寻址方式分类 4.扩展寻址(Extended) 扩展寻址中操作数占2个字节,表示的是存储单元的地址,故寻址范围是64KB。如: STAA $2040 ; (A)→ (2040) STAA $40 ; (A)→ (0040) STAA $0040 ; (A)→ (0040) 因开发环境不同,汇编生成的机器代码会不同,codewarrior中上述两条指令相当于直接寻址。 Page10

  11. 4.3指令按寻址方式分类 5.变址寻址(Indexed),寄存器间接寻址 操作数表示一个地址偏移量。有效地址由变址寄存器X(或Y,SP,PC)的值加上这个偏移量得到的。偏移量细分为无偏移量、5位(±16)、9位(±255)或16位偏移量。如: STAA ,X ;无偏移量 STAA 10 ,X ;<=5位 STAA -200 ,X ;<=9位 LDAA 2000 ,X ;16位 LDAA [2000 ,X] ;X+2000,X+2001 Page11

  12. 4.3指令按寻址方式分类 6.带自动加、减5位偏移量的间接变址寻址,如: MOVW 2,X+,4,+Y 如X=$2000, Y=$3000, 指令含义是将$2000和$2001两单元的内容传给$3004和$3005两单元。 与C语言相同,X+为先用后加,+Y为先加后用。 Page12

  13. 4.3指令按寻址方式分类 7.相对寻址 如: BNE LABLE ;CCR寄存器中Z不为 零,就转到LABLE处。 JMP [D,PC] ;转到PC+D所指向的存 储器中的值所指处。 偏移量是转移的目的值与当前地址值之差,这是编译器自动计算出来的。根据偏移量的大小分为相对短转移(-128~127)和相对长转移(-32768~32767)。 Page13

  14. 4.4指令按功能分类 4.3.1 数据传送指令 数据空间分为寄存器和存储器。寄存器:,B,CCR,D,X,Y,SP,存储器:对MC9S12XS128为$2000~$3FFF空间。 位数相等条件下完成数据传送 Transfer Move Store Register Memory Load Exchange Page14

  15. Load指令,读到寄存器中来。 如 LDAA #$41 ;#立即数, $16进制 LDAA 读作 Load Accumulator A LDAB Load B (M) →B LDD Load D (M:M+1)→(A:B) LDS Load SP (M:M+1)→(SPH:SPL) LDX Load index register X 间址寄存器 LDY Load index register Y LEAS Load Effective Address into SP(P320) LEAX Load Effective Address into X LEAY Load Effective Address into Y 有效地址 Page15

  16. Store指令,写到寄存器中去。 如 STAA $2000 ;(A) →($2000) STAA Store A (A)→M STAB Store B STD Store D STS Store SP STX Store X STY Store Y Page16

  17. Move指令 Move指令,不经过寄存器的、直接存储器数据传送指令。 如 MOVB $2000, $2008 ; ($2000) →($2008) MOVB Move Byte MOVW Move Word Page17

  18. Transfer指令寄存器到寄存器的数据传送指令。 TAB Transfer A to B (A)→B TBA Transfer B to A TAP Transfer A to CCR TPA Transfer CCR to A TFR Transfer register to register TSX Transfer SP to X TSY Transfer SP to Y TXS Transfer X to SP TYS Transfer Y to SP Page18

  19. Exchange指令 寄存器间数据交换 EXG Exchange register to register XGDX Exchange D with Y XGDY Exchange D with Y Page19

  20. 堆栈操作指令 PSHA Push A (SP)-1→SP,(A)→(SP) PSHB Push B PSHD Push D PSHC Push CCR PSHCW Push CCRH:CCR PSHX Push X PSHY Push Y Page20

  21. 堆栈操作指令 PULA Pull A (M(SP))→A,(SP)+1→SP PULB Pull B PULD Pull D PULC Pull CCR PULCW Pull CCRH:CCR PULX Pull X PULY Pull Y Page21

  22. 4.4.2 算术与逻辑运算指令 SEX Sign Extend Byte to Word 把8位数转成16位数的符号扩展指令 D7=0,THEN D8-D15=0X00 D7=1,THEN D8-D15=0XFF LDAA #$84 SEX A,D LDAA #$04 SEX A,D 指令执行后,(A)=——;(B)=——

  23. 加、减法指令(无进位) ADDA ADD without carry to A (A)+(M)→A ADDB ADD without carry to B (B)+(M)→B ADDD ADD without carry to D (A:B)+(M:M+1)→A:B ADDX ADD without carry to X (X)+(M:M+1)→X ADDY ADD without carry to Y (Y)+(M:M+1)→Y ABA Add A to B (B)+(A)→A ABX Add B to X (B)+(X)→X ABY Add B to Y (B)+(Y)→Y

  24. 加、减法指令(有进位) ADCA ADD with carry to A (A)+(M)+C→A ADCB ADD with carry to B (B)+(M)+C →B ADED ADD with carry to D (A:B)+(M:M+1)+C →A:B ADEX ADD with carry to X (X)+(M:M+1)+C →X ADEY ADD with carry to Y (Y)+(M:M+1)+C →Y

  25. 加、减法指令(有进位) SUCA Subtract with borrow fromA(A)-(M)-C→A SUCB Subtract with borrow fromB(B)-(M)-C→B SUED Subtract with borrow fromD(A:B)-(M:M+1)+C →A:B SUEX Subtract with borrow from X(X)-(M:M+1)+C →X SUEY Subtract with borrow from Y(Y)-(M:M+1)+C →Y

  26. 加、减法指令(无借位减法) SUBA Subtract memory from A (A)-(M)→A SUBBSubtract memory from B (B)-(M)→B SUBDSubtract memory from D (A:B)-(M:M+1)→A:B SUBXSubtract memory from X (X)-(M:M+1)→X SUBYSubtract memory from Y (Y)-(M:M+1)→Y SBA Subtract B from A (A)-(B)→A

  27. 乘除法指令 EMUL Multiply(unsigned) 16 by 16 (D)×(Y)→Y:D EMULS Multiply(signed) 16 by 16 (D)×(Y)→Y:D MUL Multiply(unsigned) 8 by 8 (A)×(B)→A:B

  28. 乘除法指令 EDIV Divide(unsigned) 32 by 16 (Y:D)÷(X)→Y,Remained→D EDIVS Divide(signed) 32 by 16 (Y:D)÷(X)→Y,Remained→D FDIV Fractional Divide(unsigned) 16 by 16 (D)÷(X)→X,Remained→D IDIV Integer Divide(unsigned) 16 by 16 (D)÷(X)→X,Remained→D IDIVS Integer Divide(signed) 16 by 16 (D)÷(X)→X,Remained→D

  29. 乘加除法指令 EMACS Multiply and Accumulate(signed) ((M(X): M(X+1))×(M(Y):M(Y+1)))+(M~M+3) → M~M+3 查表、插值指令 TBL Table Lookup and interpolate 8-bit (M)+[(B)×((M+1)-(M))]→A ETBL Table Lookup and interpolate 16-bit (M:M+1)+[(B)×((M+2:M+3)-(M:M+1))]→D

  30. 十进制调整的BCD指令 DAA Decimal Adjust (A)10 调整规则: 加法结果大于9,或产生H进位,结果+6 减法结果有借位,结果-6 • (A)=37H, (B)=46H, 即十进数37和46的BCD码 执行 ADDA B 后: 3 7 H | 0011 | 0111 4 6 H + | 0100 | 0110 进位 0| 0000| 1100 ------------------------- | 0111 | 1101 结果:低4位已非BCD码。 DA A 调整 | 0111 | 1101 + | 0000 | 0110 ------------------------- 83 H| 1000 | 0011

  31. 加一减一指令 INC Increment memory (M)+$01 →M INCA Increment A (A)+$01 →M INCB Increment B (B)+$01 →M INCW Increment memory (M:M+1)+$0001→M:M+1 INS Increment SP (SP)+$0001→SP INX Increment X (X)+$01 →X INY Increment Y (Y)+$01 →Y

  32. 加一减一指令 DEC Decrement memory (M)-$01 →M DECA Decrement A (A)-$01 →M DECB Decrement B (B)-$01 →M DECW Decrement memory (M:M+1)-$0001→M:M+1 DES Decrement SP (SP)-$0001→SP DEX Decrement X (X)-$01 →X DEY Decrement Y (Y)-$01 →Y

  33. 清零指令 CLC Clear C bit in CCR 0 →C CLI Clear I bit in CCR 0 →I CLV Clear V bit in CCR 0 →V CLR Clear memory $0 →M CLRA Clear A $0 →M CLRB Clear B $0 →M CLRW Clear memory 2bytes $00 →M:M+1 CLRX Clear X 2bytes $00 →X CLRY Clear Y 2bytes $00 →Y

  34. 求反指令 COM Complement memory , 1byte $FF-(M)→M or (/M) →M COMA Complement A , 1byte $FF-(A)→A or (/A) →A COMB Complement B , 1byte $FF-(B)→B or (/B) →B COMW Complement memory , 2bytes $FFFF-(M:M+1)→ M:M+1 COMX Complement X , 2bytes $FFFF-(X)→X COMY Complement Y , 2bytes $FFFF-(Y)→Y

  35. 取负数指令 NEG Complement memory , 1byte $00-(M)→M or (/M)+1 →M NEGA Complement A $00-(A)→A or (/A)+1→A NEGB Complement B $00-(B)→B or (/B)+1→B NEGW Complement memory , 2bytes $0000-(M:M+1)→ M:M+1 NEGX Complement X , 2bytes $0000-(X)→X NEGY Complement Y , 2bytes $0000-(Y)→Y

  36. 比较指令 CBA Compare A to B (A)-(B) 影响CCR寄存器 CMPA Compare A to memory (A)-(M) CMPB Compare B to memory (A)-(M) CPD Compare D to memory (A:B)-(M:M+1) CPS Compare SP to memory (SP)-(M:M+1) CPX Compare X to memory (X)-(M:M+1) CPY Compare Y to memory (Y)-(M:M+1)

  37. 比较指令 CPED Compare D to memory with borrow (A:B)-(M:M+1)-C CPES Compare SP to memory with borrow (SP)-(M:M+1)-C CPEX Compare X to memory with borrow (X)-(M:M+1)-C CPEY Compare Y to memory with borrow (Y)-(M:M+1)-C

  38. 测试字节是否为零指令 TST Test memory for zero or minus (M)-$00 TSTA Test A for zero or minus (A)-$00 TSTB Test B for zero or minus (B)-$00 TSTW Test memory for zero or minus (M:M+1)-$00 TSTX Test X for zero or minus (X)-$00 TSTY Test Y for zero or minus (Y)-$00

  39. 测试位与位操作指令 BCLR Clear bits in memory (M) ·(mm) → M BITA Bit test A (A) ·(M) BITB Bit test B (B) ·(M) BITX Bit test X (X) ·(M:M+1) BITY Bit test Y (Y) ·(M:M+1) BSET Set bits in memory (M) +(mm) → M

  40. 位测试与置位指令(用于信号量置位): BTAS Bit test And Set If (M) ·(Mast)=0,then set Z,else clear Z

  41. 逻辑运算操作指令 ANDA AND A with memory (A)·(M) →A ANDB AND B with memory (B)·(M) →A ANDCC AND CCR with memory (CCR)·(M)→CCR ANDX AND X with memory (X)·(M:M+1)→X ANDY AND Y with memory (Y)·(M:M+1)→Y EORA Exlusive OR A with memory (A)⊕(M)→A EORB Exlusive OR B with memory (B)⊕(M)→B EORX Exlusive OR X with memory (X)⊕(M:M+1)→X EORY Exlusive OR Y with memory (Y)⊕(M:M+1)→Y

  42. 逻辑运算操作指令 ORAA OR A with memory (A)|(M) →A ORAB OR B with memory (B)|(M) →A ORCC OR CCR with memory (CCR)|(M)→CCR ORX OR X with memory (X)|(M:M+1)→X ORY OR Y with memory (Y)|(M:M+1)→Y

  43. 逻辑移位与循环移位指令 LSL Logic Shift Left memory, High bit to C, Low bit fill with 0 LSLW Logic Shift Left M:M+1,2 bytes High bit to C, Low bit fill with 0 LSLA Logic Shift Left A, High bit to C, Low bit fill with 0 LSLB Logic Shift Left B, High bit to C, Low bit fill with 0 同样有D、X和Y

  44. 逻辑移位与循环移位指令 LSR Logic Shift Right memory, Low bit to C, High bit fill with 0 LSRW Logic Shift Right M:M+1,2 bytes Low bit to C, High bit fill with 0 LSRA Logic Shift Right A, Low bit to C, High bit fill with 0 LSRB Logic Shift Right B, Low bit to C, High bit fill with 0 同样有D、X和Y

  45. 逻辑移位与循环移位指令 ROL ROtate Left memory through carry ROLW ROtate Left memory 2 bytes through carry ROLA ROtate Left A through carry ROLB ROtate Left B through carry ROLX ROtate Left X through carry ROLY ROtate Left Y through carry ROR ROtate Right memory through carry RORW ROtate Right memory 2 bytes through carry RORA ROtate Right A through carry RORB ROtate Right B through carry RORX ROtate Right X through carry RORY ROtate Right Y through carry

  46. 算术移位指令 ASL Arithmetic Shift Left memory, Same as LSL ASLA Arithmetic Shift Left A, Same as LSLA ASLB Arithmetic Shift Left B, Same as LSLB ASLD Arithmetic Shift Left D, Same as LSLD ASLX Arithmetic Shift Left X, Same as LSLX ASLY Arithmetic Shift Left Y, Same as LSLY

  47. 算术移位指令(右移:符号位保持不变) ASR Arithmetic Shift Right memory, High bit dose not change, Low bit to C ASRA Arithmetic Shift Right A, High bit dose not change, Low bit to C ASRB Arithmetic Shift Right B, High bit dose not change, Low bit to C ASRW Logic Shift Right M:M+1, High bit dose not change, Low bit to C ASRX Arithmetic Shift Right X, High bit dose not change, Low bit to C ASRY Arithmetic Shift Right Y, High bit dose not change, Low bit to C

  48. 取极小值指令 EMIND MIN of 2 unsigned 16-bit value to D MIN((D),(M:M+1)) →D EMINM MIN of 2 unsigned 16-bit value to mem MIN((D),(M:M+1)) → M:M+1 MINA MIN of 2 unsigned 8-bit value to A MIN((A),(M)) →A MINM MIN of 2 unsigned 8-bit value to memory MIN((A),(M)) → M

  49. 取极大值指令 EMAXD MAX of 2 unsigned 16-bit value to D MAX((D),(M:M+1)) →D EMAXM MAX of 2 unsigned 16-bit value to memory MAX((D),(M:M+1)) → M:M+1 MAXA MAX of 2 unsigned 8-bit value to A MAX((A),(M)) →A MAXM MAX of 2 unsigned 8-bit value to memory MAX((A),(M)) → M

  50. 4.4.3 程序控制指令 1. 转移指令 无条件转移指令 BRA Branch Always BRN Branch Never LBRA LongBranch Always LBRN LongBranch Never JMP Jamp to absolute address

More Related