75 lines
2.5 KiB
NASM
75 lines
2.5 KiB
NASM
.data
|
|
firstNumPrompt: .asciiz "Enter g = "
|
|
secondNumPrompt: .asciiz "Enter h = "
|
|
thirdNumPrompt: .asciiz "Enter i = "
|
|
fourthNumPrompt: .asciiz "Enter j = "
|
|
|
|
function: .asciiz "leaf_example(int g, int h, int i, int j) returns f \n"
|
|
formula: .asciiz "f = (g + h) - (i + j) \n"
|
|
end: .asciiz "f = "
|
|
|
|
.text
|
|
|
|
main:
|
|
|
|
# First prompt
|
|
li $v0, 4 # Load immediate syscall value 4
|
|
la $a0, firstNumPrompt # Load address into argument 0 (register $a0)
|
|
syscall
|
|
|
|
# Read the first
|
|
li $v0, 5 # system call 5 is for reading an integer
|
|
syscall # integer value read is in $v0
|
|
add $t0, $0, $v0 # copy the first num into $to
|
|
|
|
# Print the prompt for second num
|
|
li $v0, 4 # Load immediate syscall value 4
|
|
la $a0, secondNumPrompt # Load address into argument 0 (register $a0)
|
|
syscall
|
|
|
|
# Read the second and add to total
|
|
li $v0, 5 # system call 5 is for reading an integer
|
|
syscall # integer value read is in $v0
|
|
add $t0, $t0, $v0 # copy the first num into $to
|
|
|
|
# Print the prompt for third num
|
|
li $v0, 4 # Load immediate syscall value 4
|
|
la $a0, thirdNumPrompt # Load address into argument 0 (register $a0)
|
|
syscall
|
|
|
|
# Read the third and subtract from total
|
|
li $v0, 5 # system call 5 is for reading an integer
|
|
syscall # integer value read is in $v0
|
|
sub $t0, $t0, $v0 # copy the first num into $to
|
|
|
|
# Print the prompt for fourth num
|
|
li $v0, 4 # Load immediate syscall value 4
|
|
la $a0, fourthNumPrompt # Load address into argument 0 (register $a0)
|
|
syscall
|
|
|
|
# Read the fourth and subtract from total
|
|
li $v0, 5 # system call 5 is for reading an integer
|
|
syscall # integer value read is in $v0
|
|
sub $t0, $t0, $v0 # copy the first num into $to
|
|
|
|
# Print function header
|
|
li $v0, 4 # Load immediate syscall value 4
|
|
la $a0, function # Load address into argument 0 (register $a0)
|
|
syscall
|
|
|
|
# Print formula header
|
|
li $v0, 4 # Load immediate syscall value 4
|
|
la $a0, formula # Load address into argument 0 (register $a0)
|
|
syscall
|
|
|
|
# Print total
|
|
li $v0, 4 # Load immediate syscall value 4
|
|
la $a0, end # Load address into argument 0 (register $a0)
|
|
syscall
|
|
|
|
# Print the total
|
|
li $v0, 1
|
|
la $a0, ($t0)
|
|
syscall
|
|
|
|
nor |