Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Author: Madeline Chubb + Jacob Gallucci
- # E-mail: mac6920@psu.edu + jag6248@psu.edu
- # Course: CMPSC 312
- # Assignment: MIPS Programming Project
- # Due Date: 4/11/2018
- # File: TriangleWithLoop.asm
- # Purpose: This program prompts a user to enter 3 positive integers and reports whether or not they form a triangle.
- # Simulator: Mars 4.5
- # Operating
- # System: macOS High Sierra 10.13.2 (Maddie) + Debian 9 Stretch (Jacob) + Windows 8.1 (Jacob)
- # (SO basically this should work on literally any operating system... *BSD untested but we're sure it works
- # References: Class demo programs
- # https://www.youtube.com/watch?v=B0GAXDjfdbQ (How to get user input)
- # http://forums.devshed.com/programming-languages-139/mips-finding-largest-integers-3-inputs-858246.html
- # (How to compare integers)
- .data # Output Variables
- # Prompt user for input
- prompt: .asciiz "Enter 3 positive integers by pressing <enter> after each: "
- # New Line
- newline: .asciiz "\n"
- # Invalid Input Response
- error: .asciiz "Invalid Input!\n"
- # Separator Line
- format: .asciiz "*************************************************************************\n"
- # Prompt user to input another triangle
- continue: .asciiz "Do you want to test more integers? (Type 0 to quit, 1 to run again.): "
- # Lengths do not form a triangle
- nope: .asciiz "These integers do NOT form a triangle.\n"
- # Lengths do form a triangle
- yes: .asciiz "These integere DO form a triangle.\n"
- .text # Section containing code
- .globl main # Execution start point
- main:
- li $v0, 4 # Loads string to print (4)
- la $a0, prompt # Prints String
- syscall # Executes above code
- li $v0, 4 # Loads string to print (4)
- la $a0, newline # Prints string new line
- syscall # Executes above code
- li $v0, 5 # Gets user integer input (5)
- syscall # Executes above code
- move $t0, $v0 # Stores v0 register in t0
- blez $t0, invalid # If t0 is less than or equal to 0 Goes to label invalid for user to input another integer
- li $v0, 5 # Gets user input (5)
- syscall # Executes above code
- move $t1, $v0 # Stores v0 in t1
- blez $t1, invalid # If t1 is less than or equal to 0 Goes to label invalid for user to input another integer
- li $v0, 5 # Gets user input (5)
- syscall # Executes above code
- move $t2, $v0 # Stores v0 in t2
- blez $t2, invalid # If t2 is less than or equal to 0 Goes to label invalid for user to input another integer
- li $v0, 4 # Loads string to print (4)
- la $a0, newline # Prints string new line
- syscall # Executes above code
- add $t3, $t0, $t1 # Adds t0 and t1 and stores in t3
- bge $t2, $t3, notTri # if t3 is bigger than t2, go to label not triangle (notTri)
- add $t4, $t0, $t2 # Adds t0 and t2 and stores in t4
- bge $t1, $t4, notTri # if t4 is bigger than t1, go to label not triangle (notTri)
- add $t5, $t1, $t2 # Adds t1 and t2 and stores in t5
- bge $t0, $t5, notTri # if t0 is bigger than t5, go to label not triangle (notTri)
- b yesTri # if passes all above tests go to yes it is a triangle (yesTri)
- # invalid label
- invalid:
- li $v0, 4 # Loads string to print (4)
- la $a0, error # Prints error string (invalid input)
- syscall # Executes above code
- b main # Goes back to main label
- # notTriangle label
- notTri:
- li $v0, 4 # Loads string to print (4)
- la $a0, nope # Prints not a triangle string
- syscall # Executes above code
- b loop # Goes to loop label (to ask user if they wish to go again)
- # yesTri label (if inputted lengths are a triangle)
- yesTri:
- li $v0, 4 # Loads string to print (4)
- la $a0, yes # Prints string (yes it is a triangle)
- syscall # Executes above code
- b loop # Goes to loop label (to ask user if they wish to go again)
- # Loop label (prompts user to go again)
- loop:
- li $v0, 4 # Loads string to print (4)
- la $a0, format # Prints string (divider line)
- syscall # Executes above cude
- li $v0, 4 # Loads string to print (4)
- la $a0, continue # Prints string (prompts user to choose to go again)
- syscall # Executes above code
- li $v0, 5 # Gets user integer input (5)
- syscall # Executes above code
- move $t7, $v0 # stores v0 in t7
- li $v0, 4 # Loads string to print
- la $a0, format # Prints string (divider line)
- syscall # Executes above code
- blez $t7, end # if input is less than or equal to 0 , goes to end label (to end the program)
- bge $t7, 1, main # if input is greater or equal to 1, goes to main label (loops again - go again)
- # End label (ends program)
- end:
- li $v0, 10 # Loads exit program
- syscall # Executes above code (and ends)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement