Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ########################################################################
  2. ### Seja f(x) = 2x + 8. Leia um inteiro n do teclado e calcule f(n). ###
  3. ########################################################################
  4.  
  5.     .text
  6.     .globl main
  7.    
  8. main:   ori $v0, $0, 5 # $v0 = 5. Corresponde à syscall read_int() que guarda o valor devolvido também no $v0.
  9.     syscall        # Executa a syscall.
  10.    
  11.     or $t0, $0, $v0 # $t0 = $v0. Guarda o valor devolvido pelo read_int() no $t0. Representa o x na função f(x) = 2x + 8.
  12.              
  13.     ori $t2, $0, 8 # $t2 = 8. Representa a constante 8 na função f(x) = 2x + 8.
  14.    
  15.     add $t1, $t0, $t0 # $t1 = x + x = 2 * x
  16.     add $t1, $t1, $t2 # $t1 = y = (2 * x) + 8
  17.    
  18.     or $a0, $0, $t1 # $a0 = $t1. Representa o argumento das syscalls print_int10($a0), print_int16($a0), print_int2($a0), print_intu10($a0).
  19.              
  20.     ori $v0, $0, 1 # $v0 = 1. Corresponde à syscall print_int10($a0). Imprime $a0 em base 10.
  21.     syscall         # Executa a syscall
  22.    
  23.     #ori $v0, $0, 34 # $v0 = 34. Corresponde à syscall print_int16($a0). Imprime $a0 em base 16.
  24.     #syscall         # Executa a syscall
  25.    
  26.     #ori $v0, $0, 35 # $v0 = 35. Corresponde à syscall print_int2($a0). Imprime $a0 em base 2.
  27.     #syscall         # Executa a syscall
  28.    
  29.     #ori $v0, $0, 36 # $v0 = 36. Corresponde à syscall print_intu10($a0). Imprime $a0 em base 10 unsigned (sempre positivo).
  30.     #syscall         # Executa a syscall
  31.    
  32.     jr  $ra # Fim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement