Skip to content

Instantly share code, notes, and snippets.

@tremblerz
Forked from Nicotico/prime_numbers.asm
Created February 11, 2016 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tremblerz/a449780e78bfb77682b5 to your computer and use it in GitHub Desktop.
Save tremblerz/a449780e78bfb77682b5 to your computer and use it in GitHub Desktop.
verifica numeri primi in MIPS
.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