Question
Using the template below, Write a MIPS program that uses a Monte Carlo method to estimate . The program iterates the total number of tosses
Using the template below, Write a MIPS program that uses a Monte Carlo method to estimate . The program iterates the total number of tosses and prints out the result. Run your program while varying the number of tosses, 100, 1,000, 10,000, to obtain reasonable estimate of .
.text
#.align 2
.globl main
main: la $t0, list
move $t1, $0 # init $t1 = 0
start: bge $t1, 4, exit # check loop condition
lw $a0, 0($t0) # load 1st arg
lw $a1, 4($t0) # load 2nd arg
jal gcfr # call gcfr or gcf
add $a0, $0, $v0 # move result to print argument
li $v0, 1 # print integer
syscall # system call for print result
addi $a0, $0, 0xA # ascii code for LF
addi $v0, $0, 0xB # syscall 11
syscall
addi $t1, $t1, 1 # increment $t1
add $t0, $t0, 8 # adjust index
j start # iterate
exit: li $v0, 10 # system call for exit
syscall # we are out of here
########## gcfr (non-leaf procedure) #######################
gcfr: # recursive version here
addi $sp, $sp, -4 # reserve space
sw $ra, 0($sp) # save return address to stack
move $v0, $a1 # v0 = b
remu $a1, $a0, $v0 # rem = a % b
bne $a1, $0, recur
addi $sp, $sp, 4 # restore stack
jr $ra
recur:
move $a0, $v0 # set next a = last $v0 = last b
jal gcfr
lw $ra, 0($sp) # restore return address
addi $sp, $sp, 4 # restore stack
jr $ra # return to caller
########## START of your modification: gcf #######################
#gcf: fill your implementation here
########## END of your modification #######################
.data
.align 0
list:
.word 13, 13, 37, 600, 20, 100, 624129, 2061517
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started