##################################################################### # Program #2: Check Book # Programmer: Bob Britton # Last Modified: Sep 30, 2008 Bob Farnham to format pseudocode as a # while loop. ##################################################################### # Functional Description: # This program can be used to balance your check book. # ##################################################################### # Pseudocode: # 1. Print Header; # 2. balance <- 0; # 3. done <- false; # 4. while( not done ), do the following steps: # 4.1. Prompt user for transaction value; # 4.2. Receive value from user; # 5.4. if( value == 0 ) # 5.4.1 done <- true; # 5.4.2 otherwise do the following steps: # 5.4.2.1. balance <- balance + value; # # print the value of balance on the screen # 5. print "Adios Amigo" on the screen # ###################################################################### # Register Usage: # $v0: Transaction Amount # $s0: Current Bank Balance # ###################################################################### .data # Data declaration section Head: .ascii "\n\tThis program, written by ," .ascii " can be used to balance your check book." .asciiz "\n\n\t\t\t\t\t\t\t\t\t Balance" tabs: .asciiz "\t\t\t\t\t\t\t\t\t" tran: .asciiz "\nTransaction:" bye: .asciiz "\n **** Adios Amigo **** " .text # Executable code follows main: li $v0, 4 # system call code for print_string la $a0, Head # load address of Header message into $a0 syscall # print the Header move $s0, $zero # Set Bank Balance to zero loop: li $v0, 4 # system call code for print_string la $a0, tran # load address of prompt into $a0 syscall # print the prompt message li $v0, 5 # system call code for read_integer syscall # reads the amount of Transaction into $v0 beqz $v0, done # If $v0 equals zero, branch to done addu $s0, $s0, $v0 # add transaction amount to the Balance li $v0, 4 # system call code for print_string la $a0, tabs # load address of tabs into $a0 syscall # used to space over to the Balance column li $v0, 1 # system call code for print_integer move $a0, $s0 # move Bank Balance value to $a0 syscall # print Bank Balance b loop # branch to loop done: li $v0, 4 # system call code for print_string la $a0, bye # load address of msg. into $a0 syscall # print the string li $v0, 10 # terminate program run and syscall # return control to system # END OF PROGRAM