Introduction to Arduino Programming: Features of Arduino
Final assignment sem2.docx
1. COMPUTER ORGANISATION
ASSIGNMENT
.data
a : .word 1 # the first term of the GP
r : .word 2 # the common ratio of the GP
n : .word 4 # the number of terms in the GP
# Function to compute the sum of a geometric progression
.text
.globl main
main:
lw $t5, a # load the address of the first term into $a0
lw $t6, r # load the address of the common ratio into $a1
lw $t7, n # load the number of terms into $a2
li $t2 , 1
pow:
beqz $t7, print # branch to print if y = 0
mult $t2, $t6 # multiply result by x
mflo $t2
addi $t7, $t7, -1 # decrement y
j pow # jump to loop
2. print:
sub $t2 , $t2 , 1
mult $t2, $t5 # multiply result by x
mflo $t2
sub $t6 , $t6 , 1
mtc1 $t2, $f6 # move to flt reg
cvt.s.w $f6, $f6 # cvt to flt format
mtc1 $t6, $f8 # move to float reg
cvt.s.w $f8, $f8 # cvt to float format
div.s $f12, $f6, $f8
li $v0 , 2
syscall
li $v0, 10 # load system call for exit
syscall
.end main