Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- g: .word #10
- h: .word #3
- f: .word
- k: .word -5
- i: .word #temp holder
- int_value1: .word
- int_value2: .word
- new_line: .asciiz "\n" #new line for legibility
- string1: .asciiz "\nThe constant value (f) is : "
- string2: .asciiz "\nThe first input value (g) is : "
- string3: .asciiz "The second input value (h) is : "
- .text
- #part b of 2.1.1
- #f = g + (h -5);
- _start:
- lw $t0, g
- lw $t1, h
- lw $t3, i
- lw $s0, f #result holder
- lw $s1, k #since this constant is used as a decrement, it is instantiated as a
- #negative signed number
- main:
- #print the constant just for verification
- li $v0, 4 #register address 4 prints strings
- la $a0, string1
- syscall
- li $v0, 1
- move $a0, $s1
- syscall
- li $v0, 4
- la $a0, new_line
- syscall
- #_____________________________________________________________________________
- #print an identifying string to the screen for input 1 i.e. "g"
- li $v0, 4 #same as above for string printing
- la $a0, string2
- syscall
- #keyboard input 1
- li $v0, 5 #loading system call 5 reads the 1st keyboard int input
- syscall
- sw $v0, int_value1 #use int_value just to differentiate that this is actual input
- la $t0,($v0) #stores values of input (g) into temp variable $t0 using load address
- #new line
- li $v0, 4
- la $a0, new_line
- syscall
- #____________________________________________________________________
- #print an identifying string to the screen for input 2 i.e. "h"
- li $v0, 4
- la $a0, string3
- syscall
- #keyboard input 2
- li $v0, 5 #loading system call 5 reads the 2nd keyboard int input
- syscall
- sw $v0, int_value2 #use int_value just to differentiate that this is actual input
- la $t1,($v0) #stores values of input into temp variable $t1 using load address
- li $v0, 4
- la $a0, new_line
- syscall
- #____________________________________________________________________
- #____________________________________________________________________
- #arithmetic
- # h-5 ---> $t0 - $s1 , store in temp variable
- add $t3,$t1,$s1
- li $v0,1
- move $a0,$t3
- syscall
- li $v0, 4
- la $a0, new_line
- syscall
- # g ($t0) + temp variable $t3 and store in f ($s0)
- add $s0,$t0,$t3
- li $v0,1
- move $a0,$s0
- syscall
- ######################################################################
- #exit gracefully
- li $v0, 10 #system call code for exit is "10"
- syscall #bye bye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement