I have written MIPS program to print prime numbers below 1000.
Here is what I wrote:
# Constants
ARRAY_LEN = 1000
main:
# TODO: add your code here
li $t0, 2
li $t1, 0
li $t2, 2
li $t3, 0
li $t4, 0
loop_cond:
bge $t0, ARRAY_LEN, end
loop:
lb $t1, prime($t0)
bnez $t1, counter_add
print:
li $v0, 1
move $a0, $t1
syscall
loop2:
mul $t4, $t0, $t2
bge $t4, ARRAY_LEN, counter_add
sb $zero, prime($t4)
addi $t2, $t2, 1
j loop2
counter_add:
addi $t0, $t0, 1
j loop_cond
end:
li $v0, 0
jr $ra # return 0;
.data
prime:
.byte 1:ARRAY_LEN # uint8_t prime[ARRAY_LEN] = {1, 1, ...};
but when I run this program, it prints nothing and I’m not sure which part I did wrong.
New contributor
ivegal op is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.