tipuri de instruc template Țiuni mipsace.catalinamancas.ro/ace/soc-seminar5.pdf · 2016. 10....

27
Template Seminarul 1 TIPURI DE INSTRUCȚIUNI MIPS Seminarul 5 STRUCTURA ȘI ORGANIZAREA CALCULATOARELOR

Upload: others

Post on 04-Dec-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

Template S

em

inaru

l 1

TIPURI DE INSTRUCȚIUNI

MIPS

Sem

inaru

l 5

STRUCTURA ȘI ORGANIZAREA CALCULATOARELOR

Page 2: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 3: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 4: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 5: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 6: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 7: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 8: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 9: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 10: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

INSTRUCȚIUNI DE CONTROL

JUMP

j label

o jump necondiționat la etichetă

Page 11: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

INSTRUCȚIUNI DE CONTROL

JUMP

jr $t1

o jump necondiționat la registru

Page 12: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 13: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 14: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

INSTRUCȚIUNI DE CONTROL

INSTRUCȚIUNE EFECT

Page 15: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

INSTRUCȚIUNI DE CONTROL

IF-ELSE

C:

MIPS:

$t0=var1; $t1=var2

Page 16: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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.

Page 17: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 18: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 19: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 20: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 21: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 22: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

INSTRUCȚIUNI LOGICE

and

andi

or

ori

xor

xori

nor

not

Page 23: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

FORMATUL INSTRUCȚIUNILOR

MIPS

1.FORMAT R

2.FORMAT I

3.FORMAT J

Page 24: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 25: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 26: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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

Page 27: TIPURI DE INSTRUC Template ȚIUNI MIPSace.catalinamancas.ro/ACE/SOC-Seminar5.pdf · 2016. 10. 20. · tipuri de instrucȚiuni mips 1.instrucȚiuni syscall 2.instrucȚiuni de ÎncĂrcare

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