Advertisement
Code_Dispensarat0r

Sp13COA_Hwk2Ex2_1_1ab_MARSMIPS_FinProd

Oct 21st, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. .data
  2. g: .word #10
  3. h: .word #3
  4. f: .word
  5. k: .word -5
  6. i: .word #temp holder
  7. int_value1: .word
  8. int_value2: .word
  9. new_line: .asciiz "\n" #new line for legibility
  10. string1: .asciiz "\nThe constant value (f) is : "
  11. string2: .asciiz "\nThe first input value (g) is : "
  12. string3: .asciiz "The second input value (h) is : "
  13.  
  14. .text
  15. #part b of 2.1.1
  16. #f = g + (h -5);
  17.  
  18. _start:
  19. lw $t0, g
  20. lw $t1, h
  21. lw $t3, i
  22. lw $s0, f #result holder
  23. lw $s1, k #since this constant is used as a decrement, it is instantiated as a
  24. #negative signed number
  25.  
  26. main:
  27. #print the constant just for verification
  28. li $v0, 4 #register address 4 prints strings
  29. la $a0, string1
  30. syscall
  31.  
  32. li $v0, 1
  33. move $a0, $s1
  34. syscall
  35.  
  36. li $v0, 4
  37. la $a0, new_line
  38. syscall
  39.  
  40. #_____________________________________________________________________________
  41.  
  42. #print an identifying string to the screen for input 1 i.e. "g"
  43. li $v0, 4 #same as above for string printing
  44. la $a0, string2
  45. syscall
  46.  
  47. #keyboard input 1
  48. li $v0, 5 #loading system call 5 reads the 1st keyboard int input
  49. syscall
  50. sw $v0, int_value1 #use int_value just to differentiate that this is actual input
  51.  
  52. la $t0,($v0) #stores values of input (g) into temp variable $t0 using load address
  53.  
  54. #new line
  55. li $v0, 4
  56. la $a0, new_line
  57. syscall
  58.  
  59. #____________________________________________________________________
  60.  
  61. #print an identifying string to the screen for input 2 i.e. "h"
  62.  
  63. li $v0, 4
  64. la $a0, string3
  65. syscall
  66.  
  67. #keyboard input 2
  68. li $v0, 5 #loading system call 5 reads the 2nd keyboard int input
  69. syscall
  70. sw $v0, int_value2 #use int_value just to differentiate that this is actual input
  71.  
  72. la $t1,($v0) #stores values of input into temp variable $t1 using load address
  73.  
  74. li $v0, 4
  75. la $a0, new_line
  76. syscall
  77. #____________________________________________________________________
  78. #____________________________________________________________________
  79.  
  80. #arithmetic
  81. # h-5 ---> $t0 - $s1 , store in temp variable
  82.  
  83. add $t3,$t1,$s1
  84.  
  85. li $v0,1
  86. move $a0,$t3
  87. syscall
  88.  
  89. li $v0, 4
  90. la $a0, new_line
  91. syscall
  92.  
  93. # g ($t0) + temp variable $t3 and store in f ($s0)
  94. add $s0,$t0,$t3
  95.  
  96. li $v0,1
  97. move $a0,$s0
  98. syscall
  99.  
  100. ######################################################################
  101. #exit gracefully
  102. li $v0, 10 #system call code for exit is "10"
  103. syscall #bye bye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement