Está en la página 1de 15

Lenguaje ensamblador del DLX

• El procesador DLX
• Modos de direccionamiento
• Formato de instrucciones
• Instrucciones DLX
– Transferencia de datos
– Aritméticas y lógicas
– Saltos y bifurcaciones
– Operaciones en punto flotante
• Sintaxis del ensamblador
• Directivas del ensamblador
• Ejemplo de programa en ensamblador

Estructura de Computadores (FI: 2º II) Ensamblador DLX 1


El procesador DLX
• Diseñado con filosofía RISC
– Arquitectura de carga/almacenamiento
– Repertorio de instrucciones sencillo
– Diseño de la segmentación eficiente
– Instrucciones fáciles de implementar en hardware: Instrucciones de
longitud fija y pocos modos de direccionamiento
– Eficiencia como objeto del compilador
– Incluir en el hardware todo aquello que no sea rentable hacerlo en
software
• Registros
– 32 registros de propósito general (GPRs) de 32 bits
• R0, R1, ... R31; el valor de R0 siempre es cero
– 32 registros de punto flotante (FPR)
• F0,F1,.... F31: 32 registros de 32 bits en simple precisión
• F0, F2,... F30: 16 registros de 64 bits en doble precisión (parejas par-impar)
– Registros especiales para acceder a información sobre el estado
• Flags (indicadores) de cero: FPSR (flag de cero
• Pueden transferirse a y desde registros enteros

Estructura de Computadores (FI: 2º II) Ensamblador DLX 2


El procesador DLX
• Direcciones de memoria de 32 bits
– Modelo de memoria “BIG-ENDIAN”
• Tamaño de las transferencias de datos
– Entre GPRs y memoria
• 8, 16 y 32 bits
– Entre FPRs y memoria
• 32 y 64 bits
• Datos e instrucciones alineados en memoria
– La dirección de memoria donde se ubica un dato ha de ser múltiplo
de su tamaño.

Objeto Bien alineado Mal alineado


Byte 0,1,2,3,4,5,6,.. (nunca)
Media palabra 0,2,4,6,8, ... 1,3,5,7, ...
Palabra (4 bytes) 0,4,8,... 1,2,3,5,6,7,9,10,11,...
Doble palabra 0,8, .. 1,2,3,4,5,6,7,9,10,11,12,13,14,15,....

Estructura de Computadores (FI: 2º II) Ensamblador DLX 3


El procesador DLX
• Estructura segmentada
– Etapa IF
• Búsqueda de instrucción
– Etapa ID
• Decodificación de la instrucción y lectura de registros
– Etapa EX
• Ejecución: Operación o cálculo de dirección efectiva
• Unidades funcionales:
– intEX: Unidad principal entera
» Carga-almacenamiento, operaciones enteras (excepto multiplicación y división) y saltos
– faddEX: Sumador FP
– fmulEX: Multiplicador FP y entero
– fdivEX: Divisor FP y entero
– Etapa MEM
• Carga o almacenamiento de datos en memoria
– Etapa WB
• Almacenamiento de resultados en registros. Se realizan en la primera mitad
del ciclo de reloj. La instrucción que está en la etapa de ID puede leer estos
datos en la segunda mitad del ciclo.

Estructura de Computadores (FI: 2º II) Ensamblador DLX 4


Modos de direccionamiento
• Para DATOS:
– Registro-registro (R-R)
• add r1,r2,r3
– Inmediato (R-I)
• addi r1,r3,#5
– Registro base + desplazamiento (R-I)
• lw r1, inm16(reg)
• Para CÓDIGO:
– Relativo al contador de programa (PC)
• beq r1,r2,loop ; desplazamiento en 16 bits (especifica bytes)
• j dirección ; desplazamientos de 26 bits (especifica bytes)
– Indirecto por registro
• jr r2
• jalr r5

Estructura de Computadores (FI: 2º II) Ensamblador DLX 5


Formato de las instrucciones
Sólo tres tipos de formatos:
• Formato R: add rd,rs1,rs2
op rs1 rs2 rd func Instrucciones tipo R
6 bits 5 bits 5 bits 5 bits 11 bits Todas las instrucciones DLX de 32 bits
000000 01010 11111 00011 00000 100000 0x015f1820 add R3,R10,R31
Codifica: Operaciones de ALU registro-registro: rd <- rs1 op rs2; el campo de “func” codifica la operación a realizar por el
camino de datos: add, sub, ....

• Formato I: lw rd,inmediato(rs1)
op rs1 rd Inmediato Instruciones de carga e inmediatas
6 bits 5 bits 5 bits 16 bits Todas las instrucciones DLX de 32 bits
100011 00011 00101 0000000000100000 0x8c650020 lw $5,32($3)
Codifica: carga y almacenamiento de bytes, palabras y medias palabras; todos los inmediatos ( rd <- rs1 op inmediato); saltos
condicionales (rs1 es el registro, rd no usado); saltos indirectos por registro “jr” y salta y enlaza por registro “jalr” (rd=0; rs1
=destino; inmediato=0)

• Formato J: j dirección
op Dirección objetivo Instrucciones de bifurcación
6 bits 26 bits Todas las instrucciones DLX de 32 bits
000010 11111111111111111111110100 0x0bfffff4 0x10c: j 0x100
Bifurcación “j” y bifurcación y enlace “jal”; trap y retorno de excepción

Estructura de Computadores (FI: 2º II) Ensamblador DLX 6


Instrucciones DLX:
Transferencias de datos
• LB Rd,Adr Load byte (sign extension)
• LBU Rd,Adr Load byte (unsigned)
• LH Rd,Adr Load halfword (sign extension)
• LHU Rd,Adr Load halfword (unsigned)
• LW Rd,Adr Load word
• LF Fd,Adr Load single-precision Floating point
• LD Dd,Adr Load double-precision Floating point
• SB Adr,Rs Store byte
• SH Adr,Rs tore halfword
• SW Adr,Rs Store word
• SF Adr,Fs Store single-precision Floating point
• SD Adr,Fs Store double-precision Floating point
• MOVI2FP Fd,Rs Move 32 bits from integer registers to FP registers
• MOVI2FP Rd,Fs Move 32 bits from FP registers to integer registers
• MOVF Fd,Fs Copy one Floating point register to another register
• MOVD Dd,Ds Copy a double-precision pair to another pair
• MOVI2S SR,Rs Copy a register to a special register (not implemented!)
• MOVS2I Rs,SR Copy a special register to a GPR ( not implemented!)

Estructura de Computadores (FI: 2º II) Ensamblador DLX 7


Instrucciones DLX:
Carga-almacenamiento

Estructura de Computadores (FI: 2º II) Ensamblador DLX 8


Instrucciones DLX:
Aritméticas
• ADD Rd,Ra,Rb Add
• ADDI Rd,Ra,Imm Add immediate (all immediates are 16 bits)
• ADDU Rd,Ra,Rb Add unsigned
• ADDUI Rd,Ra,Imm Add unsigned immediate
• SUB Rd,Ra,Rb Subtract
• SUBI Rd,Ra,Imm Subtract immediate
• SUBU Rd,Ra,Rb Subtract unsigned
• SUBUI Rd,Ra,Imm Subtract unsigned immediate
• MULT Rd,Ra,Rb Multiply signed
• MULTU Rd,Ra,Rb Multiply unsigned
• DIV Rd,Ra,Rb Divide signed
• DIVU Rd,Ra,Rb Divide unsigned

Estructura de Computadores (FI: 2º II) Ensamblador DLX 9


Instrucciones DLX:
Lógicas
• AND Rd,Ra,Rb And
• ANDI Rd,Ra,Imm And immediate
• OR Rd,Ra,Rb Or
• ORI Rd,Ra,Imm Or immediate
• XOR Rd,Ra,Rb Xor
• XORI Rd,Ra,Imm Xor immediate
• LHI Rd,Imm LOad high immediate
• SLL Rd,Rs,Rc Shift left logical
• SRL Rd,Rs,Rc Shift right logical
• SRA Rd,Rs,Rc Shift right arithmetic
• SLLI Rd,Rs,Imm Shift left logical 'immediate' bits
• SRLI Rd,Rs,Imm Shift right logical 'immediate' bits
• SRAI Rd,Rs,Imm Shift right arithmetic 'immediate' bits
• S__ Rd,Ra,Rb Set conditional : "__" may be EQ, NE, LT, GT, LE or GE
• S__I Rd,Ra,Imm Set conditional immediate: "__" ídem de ídem
• S__U Rd,Ra,Rb Set conditional unsigned: "__" ídem de ídem
• S__UI Rd,Ra,Imm Set conditional unsig. immediate: "__" ídem de ídem
• NOP No operation

Estructura de Computadores (FI: 2º II) Ensamblador DLX 10


Instrucciones DLX:
Control
• BEQZ Rt,Dest Branch if GPR equal to zero; 16-bit offset from PC
• BNEZ Rt,Dest Branch if GPR not equal to zero; 16-bit offset from PC
• BFPT Dest Test comparison bit in the FP status register (true) and branch;
16-bit offset from PC
• BFPF Dest Test comparison bit in the FP status register (false) and branch;
16-bit offset from PC
• J Dest Jump: 26-bit offset from PC
• JR Rx Jump: target in register
• JAL Dest Jump and link: save PC+4 to R31; target is PC-relative
• JALR Rx Jump and link: save PC+4 to R31; target is a register
• TRAP Imm Transfer to operating system at a vectored address ; see Traps.
• RFE Dest Return to user code from an execption; restore user mode (not
mplemented!)

Estructura de Computadores (FI: 2º II) Ensamblador DLX 11


Instrucciones DLX:
Punto flotante
• ADDD Dd,Da,Db Add double-precision numbers
• ADDF Fd,Fa,Fb Add single-precision numbers
• SUBD Dd,Da,Db Subtract double-precision numbers
• SUBF Fd,Fa,Fb Subtract single -precision numbers.
• MULTD Dd,Da,Db Multiply double-precision Floating point numbers
• MULTF Fd,Fa,Fb Multiply single-precision Floating point numbers
• DIVD Dd,Da,Db Divide double-precision Floating point numbers
• DIVF Fd,Fa,Fb Divide single-precision Floating point numbers
• CVTF2D Dd,Fs Converts from type single-precision to type double-precision
• CVTD2F Fd,Ds Converts from type double-precision to type single-precision
• CVTF2I Fd,Fs Converts from type single-precision to type integer
• CVTI2F Fd,Fs Converts from type integer to type single-precision
• CVTD2I Fd,Ds Converts from type double-precision to type integer
• CVTI2D Dd,Fs Converts from type integer to type double-precision
• __D Da,Db Double-precision compares: "__" may be EQ, NE, LT, GT,
LE or GE; sets comparison bit in FP status register
• __F Fa,Fb Single-precision compares: "__" may be EQ, NE, LT, GT,
LE or GE; sets comparison bit in FP status register

Estructura de Computadores (FI: 2º II) Ensamblador DLX 12


Sintaxis del ensamblador
• Líneas de comentarios
– Todo lo que haya a partir del simbolo “;” hasta el final de línea se
ignora.
• Directivas
– Secuencia de caracteres, (_) y (.) que no empiezan por un número.
• Etiquetas
– Se declaran colocándolas al principio de línea y terminadas en (:).
• Número decimales y hexadecimales
– Números en base 10 por defecto.
– Hexadecimales o en base 16 precedidos por 0x.
• Cadenas o strings
– Las cadenas están encerradas entre dos comillas (“).
– Caracteres especiales:
• \n Nueva línea
• \t Tab
• \” Comillas

Estructura de Computadores (FI: 2º II) Ensamblador DLX 13


Directivas del ensamblador
• .align n
• .ascii "string1","..."
• .asciiz "string1","..."
• .byte byte1,byte2,...
• .data [address]
• .double number1,...
• .global label
• .space size
• .text [address]
• .word word1,word2,...

Estructura de Computadores (FI: 2º II) Ensamblador DLX 14


Ejemplo
.data
Prompt: .asciiz "An integer value >1 : "
PrintfFormat: .asciiz "Factorial = %g\n\n"
.align 2
PrintfPar: .word PrintfFormat
PrintfValue: .space 8

.text
.global main
main: ;*** Read value from stdin into R1
addi r1,r0,Prompt
jal InputUnsigned
; ;;;;;
Finish: ;*** write result to stdout
sd PrintfValue,f2
addi r14,r0,PrintfPar
trap 5

;*** end
trap 0
Estructura de Computadores (FI: 2º II) Ensamblador DLX 15

También podría gustarte