17.04.2015 Views

2.6 Formato de instrucciones.pdf

2.6 Formato de instrucciones.pdf

2.6 Formato de instrucciones.pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.5. <strong>Formato</strong> <strong>de</strong> las <strong>instrucciones</strong><br />

Representación binaria <strong>de</strong> las <strong>instrucciones</strong> en el computador.<br />

La secuencia <strong>de</strong> bits se divi<strong>de</strong> en campos que especifican la operación<br />

y los operandos.<br />

Representación sencilla:<br />

Representación más compleja:<br />

1<br />

Tamaño <strong>de</strong> las <strong>instrucciones</strong>: aspecto básico <strong>de</strong>l diseño <strong>de</strong>l formato.<br />

Compromiso entre:<br />

- Repertorio <strong>de</strong> <strong>instrucciones</strong> potente (más operaciones, más<br />

operandos, más modos <strong>de</strong> direccionamiento y mayor rango <strong>de</strong><br />

direcciones (más registros)): más bits para codificar.<br />

- Programas cortos: <strong>instrucciones</strong> cortas y <strong>de</strong> longitud fija.<br />

- Sencillez <strong>de</strong>l hardware <strong>de</strong> captación y <strong>de</strong>codificación <strong>de</strong> las<br />

<strong>instrucciones</strong>: tamaño <strong>de</strong> las <strong>instrucciones</strong> fijo e igual al tamaño <strong>de</strong> la<br />

palabra <strong>de</strong> la máquina.<br />

Los direccionamientos implícito e indirecto, permiten acortar el tamaño<br />

<strong>de</strong> la instrucción.<br />

2


Codificación <strong>de</strong> los modos <strong>de</strong> direccionamiento<br />

Según el número <strong>de</strong> modos <strong>de</strong> direccionamiento que tenga una<br />

arquitectura:<br />

3<br />

Características <strong>de</strong> los formatos <strong>de</strong> instrucción que <strong>de</strong>ben tener las<br />

arquitecturas:<br />

- Cada computador tiene unos pocos formatos: cada instrucción se<br />

ajusta a uno <strong>de</strong> ellos. Cuantos menos más sencilla la unidad <strong>de</strong><br />

control.<br />

- Son sistemáticos: campos <strong>de</strong>l mismo tipo tienen la misma longitud y<br />

ocupan el mismo sitio <strong>de</strong>ntro <strong>de</strong> la instrucción (código <strong>de</strong> operación<br />

el primero). Simplifica la <strong>de</strong>codificación <strong>de</strong> la instrucción.<br />

4


Ejemplos <strong>de</strong> formatos <strong>de</strong> <strong>instrucciones</strong><br />

IBM 360<br />

16 registros <strong>de</strong> tipo general: 0 – 15<br />

Palabra <strong>de</strong> 32 bits<br />

Modos <strong>de</strong> direccionamiento <strong>de</strong>l computador:<br />

- inmediato (8 bits)<br />

- registro: Ri (4 bits)<br />

- almacenamiento (base + <strong>de</strong>splazamiento): Bi (registro base), Di<br />

(<strong>de</strong>splazamiento <strong>de</strong> 12 bits)<br />

- in<strong>de</strong>xado: Xi (registro índice), Bi (registro base), Di (<strong>de</strong>splazamiento)<br />

Tiene 5 formatos <strong>de</strong> instrucción, según los modos <strong>de</strong> direccionamiento.<br />

2 o 3 operandos explícitos, cada uno mediante un modo <strong>de</strong><br />

direccionamiento <strong>de</strong>terminado.<br />

5<br />

6


Veamos ejemplos <strong>de</strong> <strong>instrucciones</strong> (RR, RS y SI) <strong>de</strong>l IBM 360:<br />

Especificación <strong>de</strong> las <strong>instrucciones</strong>:<br />

Descripción Código Código <strong>Formato</strong> Especificación <strong>de</strong><br />

mnemónico operación instrucc. los operandos<br />

Suma ADR 2A RR R1, R2<br />

normalizada<br />

larga<br />

Salta si BXH 86 RS R1, R3, D2(B2)<br />

índice alto<br />

Movimiento<br />

inmediato<br />

MVI 92 SI D1(B1), inmediato<br />

ADR 3, 4<br />

equivale a 0x2A34<br />

BXH 5, 8, X’6B8’(7) equivale a 0x865876B8<br />

MVI X’A49’(6), X’3F’ equivale a 0x923F6A49<br />

7<br />

El VAX<br />

<strong>Formato</strong> <strong>de</strong> instrucción muy flexible: código <strong>de</strong> operación <strong>de</strong> 8 bits,<br />

seguido <strong>de</strong> un máximo <strong>de</strong> cinco especificadores <strong>de</strong> operando:<br />

8


Cada especificador <strong>de</strong> operando se compone <strong>de</strong> dos o tres partes:<br />

1. Código <strong>de</strong>l modo <strong>de</strong> direccionamiento (4 bits):<br />

- 5: registro<br />

- 0xC: base + <strong>de</strong>splazamiento (<strong>de</strong> 16 bits)<br />

- 0xA: base + <strong>de</strong>splazamiento (<strong>de</strong> 8 bits)<br />

- Para especificar un operando inmediato los 2 bits más significativos<br />

son 00 y los 6 bits restantes (2 + 4 <strong>de</strong>l campo registro) se utilizan<br />

para codificar el valor <strong>de</strong>l operando.<br />

2. Especificación <strong>de</strong> registro (4 bits).<br />

3. Especifica opcionalmente un <strong>de</strong>splazamiento en el<br />

direccionamiento base + <strong>de</strong>splazamiento (8, 16 ó 32 bits).<br />

Veamos algunos ejemplos <strong>de</strong> <strong>instrucciones</strong> <strong>de</strong>l VAX:<br />

9<br />

10


Ejemplos:<br />

Dar la instrucción máquina equivalente a:<br />

CLRL R13<br />

MOVW 362(R3), 67(R12)<br />

ADDL3 #58, R1, 55(R11)<br />

equivale a 0xD45D<br />

equivale a 0xB0C36A01AC43<br />

equivale a 0xC13A51AC37<br />

11<br />

<strong>Formato</strong>s <strong>de</strong> instrucción <strong>de</strong> la MIPS (3 <strong>de</strong> 32 bits)<br />

12


13<br />

1. Tipo R (Registro)<br />

- opco<strong>de</strong>: código <strong>de</strong> operación primario, cuyo valor es cero.<br />

- rs: especificador <strong>de</strong> registro fuente.<br />

- rt: especificador <strong>de</strong> registro objetivo (fuente/<strong>de</strong>stino).<br />

- rd: especificador <strong>de</strong> registro <strong>de</strong>stino.<br />

- sa: cantidad <strong>de</strong> <strong>de</strong>splazamiento.<br />

- function: campo función, especifica la operación.<br />

Utilizado para <strong>instrucciones</strong> aritméticas y lógicas:<br />

14


(1.1) Tres operandos en registros<br />

ADD rd, rs, rt<br />

(rd ← rs + rt)<br />

SUB rd, rs, rt<br />

(rd ← rs - rt)<br />

15<br />

Ejemplos<br />

Modo <strong>de</strong> direccionamiento registro:<br />

16


(1.2) Dos operandos en registros<br />

SLL rd, rt, sa<br />

(rd ← rt


2. Tipo I (Inmediato)<br />

- opco<strong>de</strong>: especifica la operación.<br />

Para <strong>instrucciones</strong>:<br />

(2.1) <strong>de</strong> transferencia <strong>de</strong> datos (carga/almacenamiento):<br />

- rs: registro base.<br />

- rt: registro fuente/<strong>de</strong>stino.<br />

- offset: <strong>de</strong>splazamiento.<br />

(2.2) <strong>de</strong> salto condicional:<br />

- rs y rt: para establecer la condición.<br />

- offset: <strong>de</strong>splazamiento.<br />

(2.3) <strong>instrucciones</strong> con operandos inmediatos:<br />

- rs: operando fuente.<br />

- rt: operando <strong>de</strong>stino.<br />

- offset (inmediate): operando fuente.<br />

19<br />

(2.1) Instrucciones <strong>de</strong> carga/almacenamiento<br />

LW rt, offset(base)<br />

(rt ← memory[base+offset])<br />

SW rt, offset(base)<br />

(memory[base+offset] ← rt)<br />

20


Ejemplos<br />

21<br />

Existen <strong>instrucciones</strong> distintas para los diferentes tamaños <strong>de</strong> dato<br />

(i) Load Byte<br />

(ii) Load Half Word<br />

(iii) Load Word<br />

En todos los casos, el direccionamiento para el segundo operando es<br />

base (registro rt) + <strong>de</strong>splazamiento (offset)<br />

22


(2.2) Instrucciones <strong>de</strong> salto condicional (bifurcación)<br />

BEQ rs, rt, offset<br />

(if (rs = rt) then branch)<br />

Operación: tgt_offset ← sign_extend(offset || 0 2 )<br />

condition ← (GPR[rs] = GPR[rt])<br />

if (condition) then PC ← PC + tgt_offset endif<br />

An 18-bit signed offset (the 16-bit offset field shifted left 2 bits) is ad<strong>de</strong>d<br />

to the address of the instruction following the branch (not the branch<br />

itself), to form a PC-relative effective target address.<br />

23<br />

Ejemplos<br />

beq $19, $20, 6205<br />

bne $19, $20, 6205<br />

Estas <strong>instrucciones</strong> saltarían a la instrucción que está 6206<br />

<strong>instrucciones</strong> más a<strong>de</strong>lante en memoria.<br />

24


El modo <strong>de</strong> direccionamiento es relativo al contador <strong>de</strong> programa.<br />

En este modo, se especifica el <strong>de</strong>splazamiento (en número <strong>de</strong><br />

<strong>instrucciones</strong>), con respecto al PC, don<strong>de</strong> está la instrucción <strong>de</strong>stino <strong>de</strong>l<br />

salto: dirección <strong>de</strong>stino = PC + <strong>de</strong>splazamiento * 4.<br />

Las <strong>instrucciones</strong> <strong>de</strong> bifurcación pue<strong>de</strong>n saltar 2 15 -1 <strong>instrucciones</strong> hacia<br />

<strong>de</strong>lante y 2 15 hacia atrás.<br />

En el ejemplo, si la instrucción “beq $19, $20, 6205” está en la dirección<br />

5300, la dirección <strong>de</strong> la instrucción <strong>de</strong>stino <strong>de</strong>l salto sería:<br />

PC + (6205 * 4) = 5304 + 24820 = 30124<br />

25<br />

(2.3) Instrucciones con un operando inmediato<br />

Para operaciones con constantes<br />

ADDI rt, rs, immediate (rt ← rs + immediate)<br />

Ejemplo<br />

Modo <strong>de</strong> direccionamiento inmediato.<br />

26


3. Tipo J (Salto)<br />

Operación: PC ← PC 32..28 || instr_in<strong>de</strong>x || 0 2<br />

Modo <strong>de</strong> direccionamiento pseudodirecto: la dirección <strong>de</strong> salto son los<br />

26 bits menos significativos <strong>de</strong> la instrucción, <strong>de</strong>splazados 2 posiciones<br />

a la izquierda y concatenados con los 4 bits más significativos <strong>de</strong>l PC.<br />

27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!