Skip to content

Instantly share code, notes, and snippets.

@willianrschuck
Created May 10, 2019 18:10
Show Gist options
  • Select an option

  • Save willianrschuck/8c579cfbffe107fc892c183582407526 to your computer and use it in GitHub Desktop.

Select an option

Save willianrschuck/8c579cfbffe107fc892c183582407526 to your computer and use it in GitHub Desktop.
Gerador de número pseudo-aleatórios baseado na fórmula de um gerador congruencial linear
# Programa em Assembly (MIPS) para gerar valores pseudo aleatório
# Base para o projeto o modelo de um gerador congruencial linear
# int rng(int v) {
# return (mul*v + inc) % mod;
# }
.data
divisao: .asciiz", "
.text
main:
li $t0, 0 # valor
li $t1, 256 # modulo
li $t2, 57 # multiplicador
li $t3, 3 # incremento
# Exibe o valor de $t0 na tela
li $v0, 1
add $a0, $t0, $zero
syscall
li $v0, 4
la $a0, divisao
syscall
# Gerar novo valor
mul $t4, $t0, $t2 # t4 = mul * v
add $t5, $t4, $t3 # t5 = t4 + inc
rem $t6, $t5, $t1 # t6 = t5 % modulo
add $t0, $t6, $zero # t0 = t6
# Exibe o novo valor na tela
li $v0, 1
add $a0, $t0, $zero
syscall
li $v0, 10
syscall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment