Advertisement
Guest User

Assembly MIPS - Clederson

a guest
Oct 20th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Clederson Cruz; 2017
  2. # Realiza conversão de decimal para octal
  3. #$t0 = valor lido
  4. #$t1 = expoente
  5. #$t2 = potencia de 8 acumulada
  6. #$t3 = b * 8^n
  7. #$t4 = resultado
  8. #$s0 = cópia do valor lido
  9. #$s1 = último dígito de $s0
  10. .data
  11.     msg1: .asciiz "Informe um valor decimal: "
  12.     msg2: .asciiz "Em octal: "
  13. .text
  14. main:
  15.     #Escrevendo a msg na tela
  16.     li $v0, 4
  17.     la $a0, msg1
  18.     syscall
  19.    
  20.     #Lendo o valor em decimal (inteiro)
  21.     li $v0, 5
  22.     syscall
  23.     add $t0, $v0, $zero #adicionando o valor lido ao registrador $t0
  24.    
  25.     #***conversão***
  26.     add $s0, $t0, $zero
  27.     mul $t1, $zero, $zero
  28.     add $t2, $zero, 1
  29. while1: #enquanto a cópia for diferente de zero
  30.     beq $s0, $zero, fimWhile1
  31.     rem $s1, $s0, 10
  32.     div $s0, $s0, 10
  33.    
  34.     beq $t1, $zero, else
  35.     mul $t2, $t2, 8 #caso nao seja 8^0
  36. else:
  37.     mul $t3, $t2, $s1
  38.     add $t4, $t4, $t3
  39.     add $t1, $t1, 1
  40.    
  41.     j while1
  42. fimWhile1:
  43.    
  44.     #Exibindo o resultado
  45.     li $v0, 4
  46.     la $a0,msg2
  47.     syscall
  48.    
  49.     li $v0, 1
  50.     add $a0, $t4, $zero
  51.     syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement