Académique Documents
Professionnel Documents
Culture Documents
AFDEL
Filière SMI
6 26
000010 00000000000000000000000000 -- champs d’instruction
opcode target -- description des champs
Figure 1
On prend les 26 bits représentons l’adresse cible de l’instruction jump et on les décale de
deux bits pour avoir une adresse sur 28 puis on place les 4 bits (MSB de PC et on les
copie dans les bits b28, b29, b30 et b31 pour avoir l’adresse de branchement.
27
Module : architecture ordinateur (microprocesseur MIPS) k.AFDEL
Filière SMI
BRANCHEMENT CONDITIONNEL
IF…..ELSE….;
28
Module : architecture ordinateur (microprocesseur MIPS) k.AFDEL
Filière SMI
Assembleur Mips
## absVal.asm
##
## Calculate the absolute value of A
##
## Registers:
## $8 --- A, two's comp. integer
## $9 --- sign bit of A
## $10 --- base register for .data section
.text
.globl main
main:
# Get A
lui $10,0x1000 # Init base register
lw $8,0($10) # Load A
sll $0,$0,0
# Is A Negative?
srl $9,$8,31 # Shift sign bit to position 0
beq $0,$9,done # sign bit == zero, done
sll $0,$0,0
# Store -A
sub $8,$0,$8 # negate A
sw $8,0($10) # save it
.data
A: .word -1
## End of File
29
Module : architecture ordinateur (microprocesseur MIPS) k.AFDEL
Filière SMI
En assembleur, on ne dispose certainement pas d'instruction qui réalise directeemnt la boucle while.
On va donc la déconstruire à l'aide de constructions plus élémentaires (goto et if).
While: While:
if t1 <= 0 then goto End ble $t1, $0, End
else
begin
t2 := t2 + t1; add $t2, $t2, $t1
t1 := t1 - 1; sub $t1, $t1, 1
goto While j While
end;
End: End:
begin j Test
goto Test; Loop:
Loop: add $t2, $t2, $t1
t2 := t2 + t1; sub $t1, $t1, 1
t1 := t1 - 1; bgt $t1, $0, Loop
Test:
if t1 > 0 then goto Loop
end
APPELS SYSTEME
SPIM fournit quelques appels système minimalistes: le programme charge dans $v0
le code de l’appel et les arguments dans les registres $a0,$a3 (ou $f12 les valeurs en
virgule flottante). Le résultat se trouve dans $v0 (ou $f0).
Code
Service Arguments Results
in $v0
print_int 1 $a0 = integer to be printed
print_float 2 $f12 = float to be printed
print_double 3 $f12 = double to be printed
print_string 4 $a0 = address of string in memory
read_int 5 integer returned in $v0
read_float 6 float returned in $v0
read_double 7 double returned in $v0
$a0 = memory address of string input buffer
read_string 8
$a1 = length of string buffer (n)
sbrk 9 $a0 = amount address in $v0
exit 10
30
Module : architecture ordinateur (microprocesseur MIPS) k.AFDEL
Filière SMI
Read integer value, store in RAM location with label int_value (presumably declared in data section)
.data
string1 .asciiz "Print this.\n" # declaration for string variable,
# .asciiz directive makes string null terminated
.text
main: li $v0, 4 # load appropriate system call code into register $v0;
# code for printing string is 4
la $a0, string1 # load address of string to be printed into $a0
syscall # call operating system to perform print operation
e.g. To indicate end of program, use exit system call; thus last lines of program should be:
exemple
.data
str: .asciiz "deux plus trois = "
.text
li $v0, 4 # system call code for print_str
la $a0, str # address of string to print
syscall # print the string
li $v0, 1 # system call code for print_int
li $a0, 5 # integer to print
syscall # print it
31