1 / 25

Chapter four 80x86 Instruction Set ( 1 )

Chapter four 80x86 Instruction Set ( 1 ). Instruction Encodings.

arch
Download Presentation

Chapter four 80x86 Instruction Set ( 1 )

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. Chapter four80x86 Instruction Set(1) 2014年3月11日1

  2. Instruction Encodings The 80x86 uses a binary encoding for each machine operation. While it is important to have a general understanding of how the 80x86 encodes instructions, it is not important that you memorize the encodings for all the instructions in the instruction set. If you were to write an assembler or disassembler (debugger), you would definitely need to know the exact encodings. For general assembly language programming, however, you won’t need to know the exact encodings. However, as you become more experienced with assembly language you will probably want to study the encodings of the 80x86 instruction set. Certainly you should beaware of such terms as opcode, mod-reg-r/m byte, displacement value, and so on. 2014年3月11日2

  3. Machine Language Codes • Each instruction is coded as one or more bytes • The first byte is generally an OpCode • A numeric code representing a particular instruction or class of instructions • Additional bytes may affect the action of the instruction or provide information about the data acted upon by the instruction 2014年3月11日3

  4. Opcode d w mod reg r/m Variable Format Instructions • The meaning of bits in an instruction varies depending on the instruction • The number of bytes in an instruction varies depending on the needs of the instruction • Basic 8086 instruction format low disp/data hi disp/data low data hi data 2014年3月11日4

  5. Opcode d w Opcode • 8086 Opcodes are 6, 7, or 8 bits • d(irection) bit - used for instructions that code a register as one of the operands • 1 = register is destination, 0 = register is source • w(idth) bit - used to distinguish byte(0)/word(1) operands • 7-bit opcodes do not use d, 8-bit opcodes do not use either d or w 2014年3月11日5

  6. mod reg r/m mod/reg/r/m • The second byte of some instructions is divided into three fields • The reg field, together with the w bit (in the opcode), specifies a register operand • If there is only one register operand, d specifies whether it is the source or destination • If there are two registers, reg specifies the destination register 2014年3月11日6

  7. reg w=1 w=0 000 AX AL 001 CX CL 010 DX DL 011 BX BL 100 SP AH 101 BP CH 110 SI DH 111 DI BH The reg field contains a number between 0 and 7. Depending on the w-bit setting, this selects one of 8 registers as an operand used by the instruction reg 2014年3月11日7

  8. register/memory • Interpretation depends on mod field contents • mod = 11 r/m=(same code as reg) • second operand is the specified register • mod = 00 r/m=110 • second argument is the address specified in the the next two bytes of the instruction, direct near addressing - DS:offset (Unless segment override is in effect) 2014年3月11日8

  9. All other combinations specify indirect addressing Target Address = [BX/BP]+[SI/DI]+disp mod specifies the size of the displacement which is coded in the next one or two bytes of the instruction mod r/m mode 00 110 direct 00 --- no disp 01 all byte disp 10 all word disp 11 all register (see next table) More mod/r/m 2014年3月11日9

  10. r/m seg addr 000 DS BX+SI 001 DS BX+DI 010 SS BP+SI 011 SS BP+DI 100 DS SI 101 DS DI 110 SS BP 111 DS BX if mod = 01 or 10 disp is added if mod = 00 no displacement Exception: mod = 00 and r/m = 110 direct addressing using a 16-bit offset and DS register Indirect Address Modes 2014年3月11日10

  11. Immediate Operands • Data is stored in the instruction in the byte or bytes immediately following the address information • If bytes 3 or 4 contain a displacement the data follows the displacement info • data may be a single byte or a word 2014年3月11日11

  12. Disclaimer • Not all instructions conform to the formats described so far! The 8086 instruction set is very complex. Some opcodes are only 4-5 bits in length, and others are 16-bits. We have hit only the highlights here. 2014年3月11日12

  13. MOV mov reg,reg 2 100010dw modregr/m mov reg,mem 3-4 100010dw modregr/m disp(1-2) mov reg,imm 2-3 1011wreg data(1-2) mov acc,mem 3 1010000w disp(2) mov mem,acc 3 1010001w disp(2) mov mem,imm 4-6 1100011w modregr/m disp(1-2) data(1-2) 2014年3月11日13

  14. Sample Machine Codes 0000 000A a dw 10 0002 00 b db ? .code 0000 8B DF mov bx,di 0002 8A F9 mov bh,cl 0004 8B 1E 0000 R mov bx,a 0008 8A 26 0002 R mov ah,b 000C 8B 12 mov dx,[si][bp] 000E A0 0002 R mov al,b 0011 8A 26 0002 R mov ah,b 0015 BB 0003 mov bx,3 0018 B1 03 mov cl,3 001A C7 06 0000 R 0064 mov a,100 0020 C6 06 0002 R FF mov b,255 2014年3月11日14

  15. PC-Relative Addressing • The jump instructions use an addressing mode called PC-relative or self-relative • The machine code contains a displacement that is added to the current IP to cause a jump to occur • The assembler must calculate this displacement 2014年3月11日15

  16. JMP • Direct intrasegment short • 11101011 disp • Direct intrasegment (near) • 11101001 disp-low disp-high • Indirect intrasegment • 11111111 mod 100 r/m • Indirect intersegment • 11111111 mod 101 r/m • Direct intersegment (far) • 11101010 offset-low offset-high seg-low seg-high 2014年3月11日16

  17. 003C LP: ... 0054 JMP LP ... 010C JMP ELP ... 0406 ELP: 0406 JMP XYZ disp=3C-56=E6 11101011 11100110 disp=406-10E=2F8 * disp=406-10F=2F7 11101001 11110111 00000010 Assume XYZ is a far label at 01C5:0094 EA 94 00 C5 01 JMP Example 2014年3月11日17

  18. Conditional Jumps • These are always 2 bytes (8086-80286) • opcode disp • JA: 01110111 disp • JE: 01110100 disp • Jwhatever: 0111xxxx disp • 80386 and later processors allow near jumps • opcode is 1000xxxx disp-lo disp-hi 2014年3月11日18

  19. 100010DW mod reg r/m disp8 100010 0 0 11111010 01 001 001 1000 1000 0100 1001 1111 1010 例:写出下面指令的机器语言编码。 MOV [BX+DI-6],CL =88H、49H、FAH 2014年3月11日19

  20. 000000DW mod reg r/m Disp-L Disp-H 000000 1 1 00100110 00001000 10 000 001 0000 0011 1000 0001 0010 0110 0000 1000 例: 写出下面指令的机器语言编码。 ADD AX,[BX+DI-0826] 03H 81H 26H 08H 2014年3月11日20

  21. Addressing Modes on the x86 This is one of the most important issues for your studying of the assembly language programming “寻址方式”是你学习汇编语言指令及程序设计的基础!!! 2014年3月11日21

  22. Addressing Modes on the x86 • The x86 instructions use THREE different operand types: • Constants(立即数寻址方式) mov al, 30h • registers(寄存器寻址方式) mov ah,al • memory addressing(存储器寻址方式) mov [2000h],al 2014年3月11日22

  23. 8086/8088的寻址方式 所谓寻址方式就是寻找操作数存放地址(位置)的方法。在8086/8088系统中操作数存放的位置用以下3种: ⑴ 操作数包含在指令字节中。即指令格式中操作数部分就是操作数本身。这种操作数叫立即数操作数。 ⑵ 操作数存放在CPU的某个内部寄存器中。这种操作数叫寄存器操作数。 ⑶ 操作数在内存的数据区中。这种操作数叫存储器操作数。 2014年3月11日23

  24. 存储器 AH AL 存储器 AL 80H 12 34 操作码字节 指 令 码 指 令 码 操作码字节 34H 34 80H 80H 12H 12 在8086/8088系统中,操作数又可分为两大类:数据操作数和地址操作数。因此,寻址方式也分为数据寻址方式和地址寻址方式两大类。 1. 数据的寻址方式 1)立即数寻址方式 例如:MOV AL, 80H MOV AX, 1234H 2014年3月11日24

  25. 2)寄存器寻址方式 例如:MOV AX, CX 存储器 AX 89 CX 指令码 (包括操作数) C1 2014年3月11日25

More Related