TABELA DE OPCODES
-
Upload
fabio-dos-santos -
Category
Documents
-
view
321 -
download
35
Transcript of TABELA DE OPCODES
20-Aug-07
1
Sistemas de ComputaçãoMontador - continuação
Prof. João Paulo A. Almeida ([email protected])
2007/02 - INF01907
Elementos de um montador
• Tabela de opcodes (depende do alvo)
– Mapeamento do mneumônico para códigos de operação (instrução)
– Parâmetro
– Tamanho da instrução
• Tabela de símbolos
– Uma entrada para cada símbolo
• ILC (Instruction Location Counter – contador de localização de instrução)
– Ajustada para 0 no início da passagem um e incrementada do comprimento da instrução para cada instrução processada
Tabela de OpcodesMneumônico Parâmetro Opcode (hex) Tam. Instrução
LOADA Addr 01h 2
LOADB Addr 02h 2
CONB Con 03h 2
SAVEB Addr 04h 2
SAVEC Addr 05h 2
ADD - 06h 1
SUB - 07h 1
MUL - 08h 1
DIV - 09h 1
COM - 0Ah 1
JUMP Addr 0Bh 2
JEQ Addr 0Ch 2
JNEQ Addr 0Dh 2
JG Addr 0Eh 2
JGE Addr 0Fh 2
JL Addr 10h 2
JLE Addr 11h 2
STOP - 12h 1
1ª Passagem: Construção tabela de símbolos
Símbolo Valor
a 128
f 129
while 8
fim 31
Instruções: linha-a-linhaRótulo Opcode Operandos Tam. Instrução ILC
CONB 1 2 0
SAVEB [a] 2 2
CONB 1 2 4
SAVEB [f] 2 6
while LOADA [a] 2 8
CONB 5 2 10
COM 1 12
JG fim 2 13
LOADA [f] 2 15
LOADB [a] 2 17
MUL 1 19
SAVEC [f] 2 20
LOADA [a] 2 22
CONB 1 2 24
ADD 1 26
SAVEC [a] 2 27
JUMP while 2 29
fim STOP 1 31
Fonte em assemblySEGMENT .DATA128 a DB 0129 f DB 0SEGMENT .TEXT0 CONB 1 // a=1;2 SAVEB [a]4 CONB 1 // f=1;6 SAVEB [f]while:8 LOADA [a] // if a > 5 jump to 1710 CONB 512 COM13 JG fim15 LOADA [f] // f=f*a;17 LOADB [a]19 MUL20 SAVEC [f]22 LOADA [a] // a=a+1;24 CONB 126 ADD27 SAVEC [a]29 JUMP while // loop back to iffim: 31 STOP
20-Aug-07
2
Eliminando rótulos// Assumir a no endereço 128
// Assumir f no endereço 129
0 CONB 1 // a=1;2 SAVEB 1284 CONB 1 // f=1;6 SAVEB 129
8 LOADA 128 // if a > 5 jump to 1710 CONB 512 COM13 JG 3115 LOADA 129 // f=f*a;17 LOADB 12819 MUL20 SAVEC 12922 LOADA 128 // a=a+1;24 CONB 126 ADD27 SAVEC 12829 JUMP 8 // loop back to if
31 STOP
Usando a representação numéricaEnd. CódigoInstrução/operador0 3 1 12 4 3 1284 3 5 16 4 7 1298 1 9 12810 3 11 512 10 13 14
14 3115 1 16 12917 2 18 12819 8 20 5 21 12922 1 23 12824 3 25 126 6 27 5 28 12829 11 30 831 18
Usando a representação numéricaEnd. CódigoInstrução/operador0 3 // CONB 11 12 4 // SAVEB 1283 1284 3 // CONB 15 16 4 // SAVEB 1297 1298 1 // LOADA 1289 12810 3 // CONB 511 512 10 // COM13 14 // JG 31
14 3115 1 // LOADA 12916 12917 2 // LOADB 12818 12819 8 // MUL20 5 // SAVEC 12921 12922 1 // LOADA 12823 12824 3 // CONB 125 126 6 // ADD27 5 // SAVEC 12828 12829 11 // JUMP 830 831 18 // STOP
• Principal característica de um nível ISA: seu conjunto deinstruções de máquina.
• As instruções controlam tudo aquilo que a máquina pode fazer.
• De uma forma geral, podem sempre existir:
– Instruções LOAD e STORE (em diversos formatos): permitir o movimentode dados entre a memória e os registradores.
– Instruções MOVE: copiar valores entre registradores.
– Instruções aritméticas, lógicas, de comparação de valores.
– Instruções de desvio.
Conjunto de instruções
Formato de instrução Intel 32-bits Prefixos
• 4 grupos de prefixos
– opcionais
• Grupo 1 – Prefixos de repetição
– F0h – LOCK
– F2h – REPNE(=REPNZ)
– F3h – REP
• Grupo 2 – Branch hints
– 2Eh – Branch taken
– 3Eh – Branch not taken• Somente usados com desvios condicionais
• Grupo 3
• Grupo 4
20-Aug-07
3
Opcode
• Código primário da instrução
• Define qual a instrução executada
– Define também tamanho de operador, direção da operação, ...
• 1, 2 ou 3 bytes de tamanho
• Pode se expandir para ocupar uma parte de Reg/Opcode
• Smaller fields can be defined within the primary opcode. Such fields define the direction of operation, size of displacements, register encoding, condition codes, or sign extension. Encoding fields used by an opcode vary depending on the class of operation.
ModR/M
• Instruções que se referem a operandos na memória usam esse byte para especificar a forma de endereçamento
• The ModR/M byte contains three fields of information:
– The mod field combines with the r/m field to form 32 possible values: eight registers and 24 addressing modes.
– The reg/opcode field specifies either a register number or three more bits of opcode information. The purpose of the reg/opcode field is specified in the primary opcode.
– The r/m field can specify a register as an operand or it can be combined with the mod field to encode an addressing mode. Sometimes, certain combinations of the mod field and the r/m field is used to express opcodeinformation for some instructions.
Referenciamento indireto de memória
• [ base reg + factor *index reg + constant ]
• base reg é um dos registradores: EAX, EBX, ECX, EDX, EBP, ESP, ESI ou EDI.
• factor é 1, 2, 4 out 8. (Se 1, fator pode ser omitido.)
• index reg é um dos registradores: EAX, EBX, ECX, EDX, EBP, ESI, EDI.
– ESP não está na lista
Operando Imediato
• Valor diretamente inserido no final da instrução
• Caso exista: 1, 2 ou 4 bytes
20-Aug-07
4
20-Aug-07
5
Convenções (manual Intel)
• r8—One of the byte general-purpose registers AL, CL, DL, BL, AH, CH, DH, or BH
• r16—One of the word general-purpose registers AX, CX, DX, BX, SP, BP, SI, or DI
• r32—One of the doubleword general-purpose registers EAX, ECX, EDX, EBX, ESP, EBP, ESI, or EDI
• imm8—An immediate byte value.
• imm16—An immediate word value used for instructions whose operand-size attribute is 16 bits.
• imm32—An immediate doubleword value used for instructions whose operand-size attribute is 32 bits.
Intel Architecture Software Developer’s Manual
Volume 2: Instruction Set Reference
http://developer.intel.com/design/pentiumii/manuals/243191.htm
Convenções (manual Intel)• r/m8—A byte operand that is either the contents of a byte general-purpose
register (AL, BL, CL, DL, AH, BH, CH, and DH), or a byte from memory.
• r/m16—A word general-purpose register or memory operand used for instructions whose operand-size attribute is 16 bits. The word general-purpose registers are: AX, BX, CX, DX, SP, BP, SI, and DI. The contents of memory are found at the address provided by the effective address computation.
• r/m32—A doubleword general-purpose register or memory operand used for instructions whose operand-size attribute is 32 bits. The doubleword general-purpose registers are: EAX, EBX, ECX, EDX, ESP, EBP, ESI, and EDI. The contents of memory are found at the address provided by the effective address computation.
Intel Architecture Software Developer’s Manual
Volume 2: Instruction Set Reference
http://developer.intel.com/design/pentiumii/manuals/243191.htm
Arquivo .com (DOS, 16-bit); hi.asm - simple "hello world" program
; assemble with "nasm -f bin -o hi.com hi.asm"
org 100h ; inform Nasm this is a .com file
; int 21h is going to want...
mov dx,msg ; the address of or message in dx
mov ah,9 ; ah=9 - "print string" sub-function
int 21h ; call dos services
mov ah,4Ch ; "terminate program" sub-function
int 21h ; call dos services
msg db 'Hello, World!',0Dh,0Ah,'$' ; $-terminated message
Gerando a listagem do programa c/ nasm1 ; hi.asm - simple "hello world" program
2 ; assemble with "nasm -f bin -o hi.com hi.asm"
3
4 org 100h ; inform Nasm this is a .com file
5 ; int 21h is going to want...
6 00000000 BA[0B00] mov dx,msg ; the address of or message in dx
7 00000003 B409 mov ah,9 ; ah=9 - "print string" sub-function
8 00000005 CD21 int 21h ; call dos services
9
10 00000007 B44C mov ah,4Ch ; "terminate program" sub-function
11 00000009 CD21 int 21h ; call dos services
12
13 0000000B 48656C6C6F2C20576F- msg db 'Hello, World!',0Dh,0Ah,'$' ; $-terminated message
14 00000014 726C64210D0A24
15
Considerando o “org 100h”, ...1 ; hi.asm - simple "hello world" program
2 ; assemble with "nasm -f bin -o hi.com hi.asm"
3
4 org 100h ; inform Nasm this is a .com file
5 ; int 21h is going to want...
6 00000000 BA[0B01] mov dx,msg ; the address of or message in dx
7 00000003 B409 mov ah,9 ; ah=9 - "print string" sub-function
8 00000005 CD21 int 21h ; call dos services
9
10 00000007 B44C mov ah,4Ch ; "terminate program" sub-function
11 00000009 CD21 int 21h ; call dos services
12
13 0000000B 48656C6C6F2C20576F- msg db 'Hello, World!',0Dh,0Ah,'$' ; $-terminated message
14 00000014 726C64210D0A24
15
Lembre-se que os endereços são representados em “Little Endian”, ou seja, byte mais significativo vem antes.