Last active
February 11, 2016 19:14
-
-
Save Nicotico/9854304 to your computer and use it in GitHub Desktop.
verifica numeri primi in MIPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.data | |
.text | |
.globl main | |
main: | |
#li $v0, 5 | |
#syscall | |
move $a0, $v0 #sposto l'intero in a0 | |
jal PRIMI | |
li $v0, 1 | |
syscall | |
li $v0, 10 | |
syscall | |
PRIMI: | |
addi $t0, $a0, -1 # i=numero-1 | |
LOOP: | |
beq $t0, 1, TEST | |
div $a0, $t0 #divisione tra numero e i | |
mfhi $t1 #resto della divisione | |
beq $t1, $zero, NO_PRIMO | |
addi $t0, $t0, -1 #i=i-1 | |
j LOOP | |
TEST: | |
addi $a0 , $zero, 1 | |
j $ra | |
NO_PRIMO: | |
add $a0 , $zero, $zero | |
j $ra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment