MIPS

Hello. I am working on a tiny interpreter for MIPS language. It works well as expected. I have implemented some classical OPs with a clever parser. I think that I did not forget anything according to this paper :

https://en.wikibooks.org/wiki/MIPS_Assembly/Instruction_Formats

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# primes.txt
# Written by Geckoo1337
# Computes the primes numbers until it reaches 1000

.data
.text

ori $t0, $t0, 1		# start with 2
ori $t3, $t3, 1000	# go up to 1000
ori $v0, $v0, 1		# integer print syscall

.main: 
ori $t1, $zero, 0	# reset the divisor to start at 2
ori $t1, $t1, 2 
addi $t0, $t0, 1        # ++

sub $t2, $t3, $t0	# check limit
blez $t2, .done		# jump to the end

.loop: 
sub $t2, $t0, $t1	# check if denominator >= divisor
blez $t2, .prime	# this integer is a prime number

div $t0, $t1		# compute current integer by its denominator
mfhi $t2		# get the remainder
blez $t2, .main		# if the remainder equals 0, not a prime
addi $t1, $t1, 1	# try the next divisor
j .loop

.prime: 		# this is a prime number
add $a0, $zero, $t0
syscall
j .main                 # run baby run
			
.done:			# done - bye bye! 


I made some codes as simple examples like a Hello World and a primes numbers computation. However I have no idea how I can implement floating numbers in ASM. What is the best way to get something efficient with precision? I would appreciate an output for a simple 2/3. I notice that mfhi gives me the remainder. Any ideas or tips? Thank you for your help ++
Last edited on
Topic archived. No new replies allowed.