tipuri de instruc template Țiuni mips · 2016. 10. 20. · tipuri de instrucȚiuni mips structura...
TRANSCRIPT
Template S
em
inaru
l 1
TIPURI DE INSTRUCȚIUNI
MIPS
Sem
inaru
l 5
STRUCTURA ȘI ORGANIZAREA CALCULATOARELOR
TIPURI DE INSTRUCȚIUNI
MIPS
1.INSTRUCȚIUNI SYSCALL
2.INSTRUCȚIUNI DE ÎNCĂRCARE
3.INSTRUCȚIUNI ARITMETICE
4.INSTRUCȚIUNI DE CONTROL
o branch
o jump
INSTRUCȚIUNI DE CONTROL
BRANCH
b label
o label – eticheta
o branch necondiționat
Exemplu: .data
var1: .word 23 var2: .word 3
.text
.globl main, label_addi main: lw $t0, var1
lw $t1, var2 b label_addi add $t2,$t0,$t1 sub $t3,$t0,$t1
label_addi: addi $t4,$t1,5
INSTRUCȚIUNI DE CONTROL
BRANCH
beq $t0, $t1, label
o branch if equal
o branch condiționat
o condiție: $t0 = $t1
beqz $t1, label
o branch if equal to zero
o branch condiționat
o condiție: $t1 = 0
INSTRUCȚIUNI DE CONTROL
BRANCH
bgt $t0, $t1, label
o branch if greater than
o branch condiționat
o condiție: $t0 > $t1
bgtz $t1, label
o branch if greater than zero
o branch condiționat
o condiție: $t1 > 0
INSTRUCȚIUNI DE CONTROL
BRANCH
bge $t0, $t1, label
o branch if greater than or equal to
o branch condiționat
o condiție: $t0 >= $t1
bgez $t1, label
o branch if greater than or equal to zero
o branch condiționat
o condiție: $t1 >= 0
INSTRUCȚIUNI DE CONTROL
BRANCH
ble $t0, $t1, label
o branch if less than or equal to
o branch condiționat
o condiție: $t0 <= $t1
blez $t1, label
o branch if less than or equal to zero
o branch condiționat
o condiție: $t1 <= 0
INSTRUCȚIUNI DE CONTROL
BRANCH
blt $t0, $t1, label
o branch if less than
o branch condiționat
o condiție: $t0 < $t1
bltz $t1, label
o branch if less than zero
o branch condiționat
o condiție: $t1 < 0
INSTRUCȚIUNI DE CONTROL
BRANCH
bne $t0, $t1, label
o branch if not equal to
o branch condiționat
o condiție: $t0 != $t1
bnez $t1, label
o branch if not equal to zero
o branch condiționat
o condiție: $t1 != 0
INSTRUCȚIUNI DE CONTROL
JUMP
j label
o jump necondiționat la etichetă
INSTRUCȚIUNI DE CONTROL
JUMP
jr $t1
o jump necondiționat la registru
INSTRUCȚIUNI DE CONTROL
JUMP
jal label
o jump and link
o salvează adresa de întoarcere în registrul $ra, apoi execută jump la etichetă
o scop: după ce instrucțiunea întâlnită la etichetă este executată, programul revine la următoarea instrucțiune după jump
INSTRUCȚIUNI DE CONTROL
JUMP
jalr $t1
o jump and link register
o salvează adresa de întoarcere în registrul $ra, apoi execută jump la registrul $t1
jalr $t1, $t2
o jump and link register
o salvează adresa de întoarcere în registrul $t1, apoi execută jump la registrul $t2
INSTRUCȚIUNI DE CONTROL
INSTRUCȚIUNE EFECT
INSTRUCȚIUNI DE CONTROL
IF-ELSE
C:
MIPS:
$t0=var1; $t1=var2
INSTRUCȚIUNI DE CONTROL
SET
seq $t1,$t2,$t3
o dacă $t2=$t3, atunci scrie în $t1 valoarea 1, altfel valoarea 0
seq $t1,$t2,valoare
o dacă $t2=valoare, atunci scrie în $t1 valoarea 1, altfel valoarea 0
Similar:
sne, slt, slti, sle, sgt, sgti, sge.
TIPURI DE INSTRUCȚIUNI
MIPS
1.INSTRUCȚIUNI SYSCALL
2.INSTRUCȚIUNI DE ÎNCĂRCARE
3.INSTRUCȚIUNI ARITMETICE
4.INSTRUCȚIUNI DE CONTROL
5.INSTRUCȚIUNI DE DEPLASARE/ROTAȚIE
6.INSTRUCȚIUNI LOGICE
INSTRUCȚIUNI DE DEPLASARE/ROTAȚIE
SHIFT
sll $t1,$t2,valoare
o deplasează la stânga valoarea din $t2 cu numărul de biți specificat de valoare, completează cu zerouri și scrie rezultatul în $t1
sllv $t1,$t2,$t3 o deplasează la stânga valoarea din $t2 cu
numărul de biți specificat în $t3, completează cu zerouri și scrie rezultatul în $t1
Similar: srl, srlv
INSTRUCȚIUNI DE DEPLASARE/ROTAȚIE
SHIFT
sra $t1,$t2,valoare
o deplasează la dreapta valoarea din $t2 cu numărul de biți specificat de valoare, completează cu bitul de semn și scrie rezultatul în $t1
srav $t1,$t2,$t3
o deplasează la dreapta valoarea din $t2 cu numărul de biți specificat în $t3, completează cu bitul de semn și scrie rezultatul în $t1
INSTRUCȚIUNI DE DEPLASARE/ROTAȚIE
ROTATE
ror $t1,$t2,valoare
o rotește la dreapta valoarea din $t2 cu numărul de biți specificat de valoare și scrie rezultatul în $t1
ror $t1,$t2,$t3
o deplasează la dreapta valoarea din $t2 cu numărul de biți specificat în $t3 și scrie rezultatul în $t1
Similar:rol
TIPURI DE INSTRUCȚIUNI
MIPS
1.INSTRUCȚIUNI SYSCALL
2.INSTRUCȚIUNI DE ÎNCĂRCARE
3.INSTRUCȚIUNI ARITMETICE
4.INSTRUCȚIUNI DE CONTROL
5.INSTRUCȚIUNI DE DEPLASARE/ROTAȚIE
6.INSTRUCȚIUNI LOGICE
INSTRUCȚIUNI LOGICE
and
andi
or
ori
xor
xori
nor
not
FORMATUL INSTRUCȚIUNILOR
MIPS
1.FORMAT R
2.FORMAT I
3.FORMAT J
FORMATUL INSTRUCȚIUNILOR
FORMATUL R
opcode rd, rs, rt
o opcode: codul operației
o rs, rt: operanzi
o rd: rezultat
o shift: doar în cazul operațiilor de deplasare sau de rotație (numărul de biți)
o funct: doar în cazul instrucțiunilor care folosesc același opcode
opcode rs rt rd shift (shamt) funct
6 biți 5 biți 5 biți 5 biți 5 biți 6 biți
FORMATUL INSTRUCȚIUNILOR
FORMATUL I
opcode rd, rs, IMM
o opcode: codul operației
o rs: primul operand
o rd: rezultat
o IMM: al doilea operand
opcode rs rd IMM
6 biți 5 biți 5 biți 16 biți
FORMATUL INSTRUCȚIUNILOR
FORMATUL J
opcode label
o opcode: codul operației
o pseudo-adresa: eticheta
opcode pseudo-adresă
6 biți 26 biți
FORMATUL INSTRUCȚIUNILOR
Mnemonică Denumire Format Opcode Funct
add Add R 0x00 0x20
addi Add Immediate I 0x08 NA
sub Subtract R 0x00 0x22
mult Multiply R 0x00 0x18
div Divide R 0x00 0x1A
mfhi Move from HI Register R 0x00 0x10
mflo Move from LO Register R 0x00 0x12
lw Load Word I 0x23 NA
sw Store Word I 0x2B NA
j Jump to Address J 0x02 NA
jal Jump and Link J 0x03 NA
jr Jump to Address in Register R 0x00 0x08
beq Branch if Equal I 0x04 NA
bne Branch if Not Equal I 0x05 NA