Guest User

Untitled

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