Escolar Documentos
Profissional Documentos
Cultura Documentos
MIPS
ISA MIPS
3 formatos de instrues
instrues de 3 operandos
Programa em C Assembly MIPS
a = b + c; add a,b,c
d = a c; sub d,a,c
f = ( g + h ) ( i + j ); add t0,g,h
add t1,i,j
sub f,t0,t1
o compilador cria t0 e t1 .
? 1998 Morgan Kaufmann Publishers
Paulo C. Centoducatte Ch3-2
Operandos
Load e Store
Exemplo:
g = h + A[8];
: :
12 100
PROCESSADOR
8 10
4 101
0 1
ENDEREOS DADOS
MEMRIA
Soluo:
g = h + A[i];
Soluo
add $t1,$s4,$s4
add $t1,$t1,$t1 # $t1 recebe 4*i ( porque ??? )
6 5 5 5 5 6
bits bits bits bits bits bits
op rs rt rd shamt funct
op rs rt endereo
Op rs rt rd end/shamt funct
35 9 8 1200
0 18 8 8 0 32
43 9 8 1200
if ( i == j ) go to L1;
f = g + h;
L1: f = f - i;
Soluo
J L1
quando executado faz com que o programa seja desviado para
L1
Exemplo Compilando um comando if-then-else
if ( i == j) f = g + h; else f = g h;
Soluo
Usando IF
Exemplo
Loop: g = g + A[i];
i = i + j;
if ( i != h ) go to Loop
Soluo
Exemplo
while (save[i] == k)
i = i + j;
Soluo
Soluo:
switch (k) {
case 0: f = f + j; break;
case 1: f = g + h; break;
}
Exit:
? 1998 Morgan Kaufmann Publishers
Paulo C. Centoducatte Ch3-21
? 1998 Morgan Kaufmann Publishers
Paulo C. Centoducatte Ch3-22
? 1998 Morgan Kaufmann Publishers
Paulo C. Centoducatte Ch3-23
Suporte a Procedimentos
SP
stack
Exemplo
f = (g + h) (i + j);
return f;
}
No procedimento
add $t0,$a0,$a1
add $t1,$a2,$a3
sub $s0,$t0,$t1
add $v0,$s0,$zero
lw $s0, 0($sp)
lw $t0, 4($sp)
lw $s1, 8($sp)
add $sp,$sp,12
Retornar
jr $ra
? 1998 Morgan Kaufmann Publishers
Paulo C. Centoducatte Ch3-28
High address
$sp $sp
Contents of register $t1
Lowaddress a. b. c.
Figura 3.10 Valores de sp antes, durante e depois da chamada
do procedimento
fact:
sub $sp,$sp,8 # ajuste da pilha
sw $ra,4($sp) # salva o endereo de retorno
sw $a0,0(sp) #salva o argumento n
jr $ra
$sp $sp
$fp Saved argument
registers (if any)
Saved saved
registers (if any)
$sp
Low address
a. b. c.
addi $sp,$sp,4
8 29 29 4
opcode rs rt imediato
Em comparaes
slti $t0,$s2,10 # $t0 =1 se $s2 < 10
Soluo
Instrues J-type
op endereo
6 bits 26 bits
Exemplo
2 1000
Branch (I-type)
Exemplo
bne $s0,$s1,Exit
5 16 17 Exit
PC ? PC + Exit
Loop:
add $t1,$s3,$s3 # $t1 = 2 * i
add $t1,$t1,$t1 # $t1 = 4 * i
add $t1,$t1,$s6 # $t1 = endereo de save[i]
lw $t0,0($t1) # $t0 recebe save[i]
bne $t0,$s5,Exit #v para Exit se save[i] != k
add $s3,$s3,$s4 #i = i+j
j Loop
Exit:
80000 0 19 19 9 0 32
80004 0 9 9 9 0 32
80008 0 9 21 9 0 32
80012 35 9 8 0
80016 5 8 21 8
80020 0 19 20 19 0 32
80024 2 80000
80028 ..............................
beq $s0,$s1,L1
Soluo
bne $s0,$s1,L2
j L1
L2:
2. Register addressing
op rs rt rd ... funct Registers
Register
3. Base addressing
op rs rt Address Memory
4. PC-relative addressing
op rs rt Address Memory
PC + Word
5. Pseudodirect addressing
op Address Memory
PC Word
C program
Compiler
Assembler
Linker
Loader
Memory
Dynamic data
Text
pc 0040 0000 hex
Reserved
0
Update addressing
update a register as part of load (for marching through
arrays)
example: lwu $t0,4($s3)
#$t0=Memory[$s3+4];$s3=$s3+4
What do we have to do in MIPS?
Others:
load multiple/store multiple
a special counter register bc Loop
decrement counter, if not 0 goto loop
? 1998 Morgan Kaufmann Publishers
Paulo C. Centoducatte Ch3-53
80x86
Qual o melhor?
tamanho do cdigo fonte
tamanho do cdigo objeto
tempo de execuo
simplicidade e desempenho do hardware para suportar
arquitetura