Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Département d’informatique et Technologies de l’information Architecture des Ordinateurs

TD6 : Le FPU

Calculer la surface et le volume d’une sphère.


Solution
.data mov.s $f12,$f8
pi: .float 3.14 la $a0,msg1
fourPtZero: .float 4.0 li $v0,4
threePtZero: .float 3.0 syscall
rayon: .float 17.25 li $v0,2
surfaceArea: .float 0.0 syscall
volume: .float 0.0 la $a0,ret
msg0: .asciiz "Entrez le rayon: " li $v0,4
msg1: .asciiz "Surface = " syscall
msg2: .asciiz "Volume = " # Calculate volume of a sphere. #
ret: .asciiz "\n" volume = (4.0 * pi / 3.0) * rayon^3
.text l.s $f8,threePtZero
main: div.s $f5,$f4,$f8
l.s $f2,fourPtZero # (4.0 * pi / 3.0)
l.s $f4,pi mul.s $f10,$f6,$f6
mul.s $f4,$f2,$f4 # 4.0 * pi mul.s $f10,$f10,$f6 # rayon^3
la $a0,msg0 mul.s $f12,$f5,$f10
li $v0,4 # 4.0*pi/3.0*rayon^3
syscall s.s $f12,volume
li $v0,6 # Number to $f0 # store final answer
syscall la $a0,msg2
mov.s $f6,$f0 li $v0,4
#Calculate surface area of a sphere. syscall
# surfaceArea = 4.0 * pi * radius^2 li $v0,2
mul.s $f8,$f6,$f6 # rayon^2 syscall
mul.s $f8,$f4,$f8 li $v0,10
# 4.0 * pi * rayon^2 syscall
s.s $f8,surfaceArea .end main
# store final answer

You might also like