Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. .data
  2. fn_2: .word 0
  3. fn_1: .word 1
  4. fn: .word 0
  5. n: .word 0
  6. spaceInsert: .asciiz " "
  7. prompt: .asciiz "Please enter a positive integer: "
  8. test: .asciiz "testing..."
  9.  
  10.  
  11. .text
  12. .globl main
  13. main:
  14. li $v0, 4 # load instructions to output a string
  15. la $a0, prompt # prompt for n
  16. syscall
  17.  
  18. li $v0, 5 # load instructions to read an int
  19. la $a0, n # read in n
  20. syscall
  21.  
  22. lw $t0, n # st0re n into $t0
  23. lw $s0, fn_2 # store fn_2 into register $s0
  24. lw $s1, fn_1 # store fn_1 into register $s1
  25. lw $s2, fn # store fn into $s0
  26. add $t1, $zero, 1 # this is the counter, int i = 1
  27.  
  28. li $v0, 1
  29. move $a0, $t0
  30. syscall
  31.  
  32. li $v0, 1 # load instructions to print out an int
  33. move $a0, $s1 # print out fn_1 as 1 before it starts incrementing
  34. syscall
  35.  
  36. LOOP: add $s2, $s1, $s0 # fn = fn_1 + fn_2
  37.  
  38. li $v0, 4 # load instructions to output a string
  39. la $a0, spaceInsert # output space
  40. syscall
  41.  
  42. li $v0, 1 # load instructions to output an int
  43. move $a0, $s2 # output fn
  44. syscall
  45.  
  46. move $s0, $s1 # fn_2 = fn_1
  47. move $s1, $s2 # fn_1 = fn
  48.  
  49. add $t1, $t1, 1 # i++
  50. bne $t1, $t0, LOOP # loop if i < n
  51.  
  52. Exit:
  53. li $v0, 10
  54. syscall
Add Comment
Please, Sign In to add comment