# MIPS Assembly Language Program # # High-level (C++) equivalent: # # int main() # { # int age, weight, rate # # cout << "Enter age: "; # cin >> age; // enter age # cout << "Enter weight: "; # cin >> weight; // enter weight # rate = weight /age; // compute growth rate # cout << "Your growth rate is " << rate << " pounds per year." << endl; # } .data age: .word 0 weight: .word 0 inString1: .asciiz "Enter age: " # storage for strings for input / output prompts inString2: .asciiz "Enter weight: " outString1: .asciiz "Your growth rate is " outString2: .asciiz " pounds per year." .text # __start: # not used in SPIM simulator main: # needed for SPIM simulator! # print out first prompt, inString1 li $v0, 4 # load appropriate system call code into register $v0; # code for printing string is 4 la $a0, inString1 # load address of string to be printed into $a0 syscall # pseudo-code that calls the operating system to perform # desired print operation # read age li $v0, 5 # load system call code into $v0; read integer = 5 syscall # pseudo-code that calls the operating system sw $v0, age # integer read returned in $v0; store into age # print out second prompt, inString2 li $v0, 4 # load system call code into $v0; print string = 4 la $a0, inString2 # load address of string to be printed into $a0 syscall # call operating system to perform operation # read weight li $v0, 5 # load system call code into $v0: read integer = 5 syscall # pseudo-code that calls the operating system sw $v0, weight # integer read returned in $v0; store into age # finally, do some work! lw $t0, age lw $t1, weight div $t1, $t0 mflo $t2 # $t2 = weight / age # print output string outString1 li $v0, 4 # load system call code into $v0; print string = 4 la $a0, outString1 # load address of string to be printed into $a0 syscall # call operating system to perform operation # print out integer value of rate, contained in $t2 li $v0, 1 # load system call code into $v0; print integer = 1 move $a0, $t2 # move integer to be printed into $a0: $a0 = $t2 syscall # call operating system to perform operation # print output string outString2 li $v0, 4 # load system call code into $v0; print string = 4 la $a0, outString2 # load address of string to be printed into $a0 syscall # call operating system to perform operation # done # not used in SPIM simulator!