The goal of this was to be able to enter any number and print out the prime factors of that number. Are there any shorter ways of writing this code? I'm not very familiar with low-level syntax and was hoping somebody could give it a look.
.text
.align 2
.globl main
main:
# compute and display the first prime numbers up to n where n is given. Set n to be 19 but the program should work of any value of n.
li $v0, 4
la $a0, prompt
syscall # call operating sys
li $v0, 5 # read keyboard into $v0 (number n is the limit)
syscall # call operating sys
move $t0,$v0 # store n in $t0
li $v0, 4 # display message to user
la $a0, message
syscall
# call operating sys
li $v0, 4
la $a0, space
syscall # call operating sys
# Load variables into registers
lw $t1, i # $t1 = i
lw $t2, k # $t2 = k
lw $t3, p # $t3 = p
lw $t5, c # $t5 = c
lw $t6, d # $t6 = d
blt $t0,$t1 L2
li $v0, 1 # print integer function call 1
move $a0, $t1 # integer to print
syscall
# call operating sys
li $v0, 4 # print new line
la $a0, space
syscall # call operating sys
#Outer loop
L2: move $t3, $zero
# Inner loop
L1: remu $t4, $t1, $t2
bne $t4, $zero, I
move $t3, $t5
I: add $t2, $t2, $t5 # increment k
blt $t2, $t1 L1
bne $t3, $zero, P
li $v0, 1 # print integer function call 1
move $a0, $t1 # integer to print
syscall
li $v0, 4 # print new line
la $a0, space
syscall # call operating sys
P: add $t1, $t1, $t5 # increment i
move $t2, $t6
bgt $t1, $t0, E
j L2
E: li $v0, 10 # system call code for exit = 10
syscall # call operating sys
end: jr $ra
.data
prompt:
.asciiz "Please enter the number you wish to find the prime numbers of : "
message:
.asciiz "The Prime Numbers are : "
space: .asciiz "\n "
#initialization of registers
i:
.word 2
p:
.word 0
k:
.word 2
c:
.word 1
d:
.word 2
remu
- is that a macro, or is it an instruction that was added more recently than I've seen MIPS? \$\endgroup\$