more projects
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,158 @@
|
||||
|
||||
|
||||
.data
|
||||
start: .asciiz "---> Start of Bank Program <---\nAuthor information: CS 220 | #324855 | Austin Bennett\n---> Welcome to the Interest Calculator! <--- \n2%: saving years < 7 years\n5%: saving years >= 7 years\n"
|
||||
promptMsg1: .asciiz "==> Enter the principal:$ \n"
|
||||
promptMsg2: .asciiz "==> Enter the years of savings: \n"
|
||||
resultLine: .asciiz "----------------> Result <----------------\n---> Your principal is: "
|
||||
resultLine2: .asciiz "\n---> Your interest rate is: "
|
||||
yrLbl: .asciiz "\nYear "
|
||||
balanceRet: .asciiz ": your balance is $"
|
||||
balLbl: .asciiz "\n---> Your balance after "
|
||||
yearsRet: .asciiz " years: $ "
|
||||
finalLine: .asciiz "\n----------------> End of Interest Calculator <---------------- "
|
||||
newLine: .asciiz "\n"
|
||||
principal: .float 0.0
|
||||
years: .word 0
|
||||
yearsDiv: .word 7
|
||||
rate1: .float 0.02
|
||||
rate2: .float 0.05
|
||||
interestRate: .float 0.0
|
||||
balance: .float 0.0
|
||||
|
||||
.text
|
||||
.globl main #entrance of program
|
||||
.ent main
|
||||
|
||||
main:
|
||||
la $a0, start
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
la $a0, promptMsg1
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
li $v0, 6
|
||||
syscall
|
||||
|
||||
s.s $f0, principal
|
||||
la $a0, promptMsg2
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
li $v0, 5
|
||||
syscall
|
||||
|
||||
sw $v0, years
|
||||
la $a0, resultLine
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
l.s $f12, principal
|
||||
li $v0, 2
|
||||
syscall
|
||||
|
||||
la $a0, resultLine2
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
lw $t1, years
|
||||
lw $t2, yearsDiv
|
||||
blt $t1, $t2, lessThan
|
||||
l.s $f1, rate2
|
||||
s.s $f1, interestRate
|
||||
l.s $f12, interestRate
|
||||
li $v0, 2
|
||||
syscall
|
||||
|
||||
li $t3, 1
|
||||
|
||||
while:
|
||||
bgt $t3, $t1, exit
|
||||
la $a0, yrLbl
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
move $a0, $t3
|
||||
li $v0, 1
|
||||
syscall
|
||||
|
||||
la $a0, balanceRet
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
l.s $f3, principal
|
||||
l.s $f4, interestRate
|
||||
mul.s $f2, $f3, $f4
|
||||
add.s $f5, $f3, $f2
|
||||
s.s $f5, principal
|
||||
s.s $f5, balance
|
||||
l.s $f12, balance
|
||||
li $v0, 2
|
||||
syscall
|
||||
|
||||
addi $t3, $t3, 1
|
||||
j while
|
||||
|
||||
exit:
|
||||
la $a0, balLbl
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
lw $a0, years
|
||||
li $v0, 1
|
||||
syscall
|
||||
|
||||
la $a0, yearsRet
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
l.s $f12, balance
|
||||
li $v0, 2
|
||||
syscall
|
||||
|
||||
la $a0, finalLine
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
li $v0, 10
|
||||
syscall
|
||||
|
||||
lessThan:
|
||||
l.s $f1, rate1
|
||||
s.s $f1, interestRate
|
||||
|
||||
|
||||
l.s $f12, interestRate
|
||||
li $v0, 2
|
||||
syscall
|
||||
|
||||
li $t3, 1
|
||||
|
||||
logic:
|
||||
bgt $t3, $t1, exit
|
||||
la $a0, yrLbl
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
move $a0, $t3
|
||||
li $v0, 1
|
||||
syscall
|
||||
|
||||
la $a0, balanceRet
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
l.s $f3, principal
|
||||
l.s $f4, interestRate
|
||||
mul.s $f2, $f3, $f4
|
||||
add.s $f5, $f3, $f2
|
||||
s.s $f5, principal
|
||||
s.s $f5, balance
|
||||
l.s $f12, balance
|
||||
li $v0, 2
|
||||
syscall
|
||||
|
||||
addi $t3, $t3, 1
|
||||
j logic
|
||||
@@ -0,0 +1,167 @@
|
||||
|
||||
|
||||
.data
|
||||
startMsg: .ascii "---> Start of Bank Program <---\n" #System.out.println(""---> Start of Bank Program <---\n")
|
||||
.ascii "Author information: CS 220 | #02 | Corinne Bond\n" #System.out.println("Author information: CS 220 | #02 | Corinne Bond\n")
|
||||
.ascii "---> Welcome to the Interest Calculator! <--- \n" #System.out.println(">>> Welcome to Interest Calculator! <<<<\n
|
||||
.ascii " 1%: saving years < 5 years\n" # cont.. 1%: saving years < 5 years\n
|
||||
.asciiz " 5%: saving years >= 5 years\n" # cont.. 5%: saving years >= 5 years\n
|
||||
promptMsg1: .asciiz "==> Enter the principal:$ \n" #System.out.println(""==> Enter the principal:$ \n")
|
||||
promptMsg2: .asciiz "==> Enter the years of savings: \n" #System.out.println("==> Enter the years of savings: \n")
|
||||
resultLine: .ascii "----------------> Result <----------------" #System.out.println("----------------> Result <----------------")
|
||||
.asciiz "\n---> Your principal is: " #System.out.println("\n---> Your principal is: ")
|
||||
resultLine2: .asciiz "\n---> Your interest rate is: " #System.out.println("\n *** Interest rate is:"
|
||||
hdr: .asciiz "\nYear " #System.out.println("\nYear")
|
||||
hdr1: .asciiz ": your balance is $" #System.out.println(": your balance is $")
|
||||
hdr2: .asciiz "\n---> Your balance after " #System.outprintln("\n---> Your balance after ")
|
||||
hdr3: .asciiz " years: $ " #System.out.println(" years: $ ")
|
||||
finalLine: .asciiz "\n----------------> End of Interest Calculator <---------------- " #System.out.println("\n----------------> End of Interest Calculator <---------------- ")
|
||||
newLine: .asciiz "\n" #System.out.println("\n")
|
||||
principal: .float 0.0 #32bits, intial val of 0 #float principal = 0.0
|
||||
years: .word 0 #32bits, intial val of 0 #int years = 0
|
||||
testVal: .word 5 #int testVal = 0
|
||||
rate1: .float 0.01 #float rate1 = .01
|
||||
rate2: .float 0.05 #float rate2 = .05
|
||||
interestRate: .float 0.0 #float interestRate = 0.0
|
||||
balance: .float 0.0 #float balance = 0.0
|
||||
#------------------------------------
|
||||
#text/code section
|
||||
.text
|
||||
.globl main #entrance of program
|
||||
.ent main
|
||||
|
||||
main:
|
||||
la $a0, startMsg #load address of start msg
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
la $a0, promptMsg1 #load memory address of promptMsg1
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall
|
||||
|
||||
li $v0, 6 #syscall 6 -> read floating point from kb -> float principal = sc.nextFloat();
|
||||
syscall #do it
|
||||
s.s $f0, principal #save input into principal variable
|
||||
|
||||
la $a0, promptMsg2 #load memory address of promptMsg2
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
li $v0, 5 #syscall 5 -> read int from kb -> int years = sc.nextInt();
|
||||
syscall #do it
|
||||
sw $v0, years #save input into years variable
|
||||
|
||||
la $a0, resultLine #load memory address of resultLine
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
l.s $f12, principal #load principal val into float register to be printed
|
||||
li $v0, 2 #syscall 2 -> print float from register
|
||||
syscall
|
||||
|
||||
la $a0, resultLine2 #load memory address of resultLine2
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
#choose interest rate based on given variables
|
||||
lw $t1, years #load word from years into register
|
||||
lw $t2, testVal #load word from testVal into register
|
||||
blt $t1, $t2, lessThan #if t1 < t2 -> if (yearsOfSaving < 5) {return 0.01F;}
|
||||
l.s $f1, rate2 #load 5% interest rate into register -> else {return 0.05F;}
|
||||
s.s $f1, interestRate #save floating point to interest rate variable
|
||||
|
||||
#print interest rate
|
||||
l.s $f12, interestRate #load floating point to register to be printed
|
||||
li $v0, 2 #syscall 2 -> print float from register
|
||||
syscall #do it
|
||||
|
||||
li $t3, 1 #syscall 1 -> print int
|
||||
|
||||
while: #start of 1st while loop (x>=5)
|
||||
bgt $t3, $t1, exit #exit if t3 > t1 -> for (int i = 1; i <= yearsOfSaving; i++)
|
||||
la $a0,hdr #load memory address of hdr0
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
move $a0, $t3 #move from t3 to a0
|
||||
li $v0, 1 #syscall 1 -> print int
|
||||
syscall #do it
|
||||
|
||||
la $a0, hdr1 #load memory address of hdr1
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
l.s $f3, principal #load floating point to register f3
|
||||
l.s $f4, interestRate #load floating point to register f4
|
||||
mul.s $f2,$f3,$f4 #calculate interest, save into f2
|
||||
add.s $f5,$f3,$f2 #add interest to principa;. save into f5 -> -> balance *= (1 + interest);
|
||||
s.s $f5, principal #update principal with value in f5
|
||||
s.s $f5, balance #update balance with value in f5 -> float balance = principal;
|
||||
l.s $f12, balance #load floating point to register to be printed
|
||||
li $v0, 2 #syscall 2 -> print float from register
|
||||
syscall #do it
|
||||
|
||||
addi $t3, $t3, 1 #add 1 to value in register t3, update register value -> year++;
|
||||
j while #repeat while
|
||||
|
||||
exit:
|
||||
la $a0, hdr2 #load memory address of hdr2
|
||||
li $v0, 4 #syscall 4 -> print char from string ->
|
||||
syscall #do it
|
||||
|
||||
lw $a0, years #load years variable into register a0
|
||||
li $v0, 1 #syscall 1 -> print int
|
||||
syscall #do it
|
||||
|
||||
la $a0, hdr3 #load memory address of hdr3
|
||||
li $v0, 4 #syscall 1 -> print int
|
||||
syscall #do it
|
||||
|
||||
l.s $f12, balance #load floating point to be printed
|
||||
li $v0, 2 #syscall 2 -> print floating point
|
||||
syscall #do it
|
||||
|
||||
la $a0, finalLine #load memory address of finalLine
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
li $v0, 10 #syscall 10 -> exit -> System.exit(0);
|
||||
syscall #do it
|
||||
|
||||
lessThan: #less than branch
|
||||
l.s $f1, rate1 #load storage
|
||||
s.s $f1, interestRate #save variable to interest rate
|
||||
|
||||
#print interest rate
|
||||
l.s $f12, interestRate #load floating point to register to be printed
|
||||
li $v0, 2 #syscall 2 -> print float from register
|
||||
syscall #do it
|
||||
|
||||
li $t3, 1 #syscall 1 -> print int
|
||||
|
||||
while2: #start of 2nd loop (x < 5)
|
||||
bgt $t3, $t1, exit # if t3 > t4 exit -> -> for (int i = 1; i <= yearsOfSaving; i++)
|
||||
la $a0, hdr #load memory address of hdr
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
move $a0, $t3 #move from t3 to a0
|
||||
li $v0, 1 #syscall 1 -> print int
|
||||
syscall #do it
|
||||
|
||||
la $a0, hdr1 #load memory address of hdr1
|
||||
li $v0, 4 #syscall 4 -> print char from string
|
||||
syscall #do it
|
||||
|
||||
l.s $f3, principal #load principal to f3
|
||||
l.s $f4, interestRate #load interestRate to f4
|
||||
mul.s $f2, $f3,$f4 #calculate interest and save to f2
|
||||
add.s $f5, $f3,$f2 #add interest back to principal and store in f5 -> balance *= (1 + interest);
|
||||
s.s $f5, principal #update principal value
|
||||
s.s $f5, balance #update balance
|
||||
l.s $f12, balance #load value of balance to be printed
|
||||
li $v0, 2 #syscall 2 -> print floating point
|
||||
syscall #do it
|
||||
|
||||
addi $t3, $t3, 1 #add 1 to t3, update value in same register
|
||||
j while2
|
||||
@@ -0,0 +1,39 @@
|
||||
# Example program to display a string and an integer.
|
||||
# Demonstrates use of QtSpim system service calls.
|
||||
# -----------------------------------------------------
|
||||
# Data Declarations
|
||||
.data
|
||||
start: .asciiz "------ START Program Example 9.2.1 ------\n"
|
||||
end: .asciiz "\n------ END Program Example 9.2.1 ------\n"
|
||||
id: .ascii "Student: Austin Bennett (CS 220, id: 324855)\n"
|
||||
hdr: .ascii "Example\n"
|
||||
.asciiz "The meaning of life is: "
|
||||
number: .word 42
|
||||
# -----------------------------------------------------
|
||||
# text/code section
|
||||
.text
|
||||
.globl main
|
||||
.ent main
|
||||
main:
|
||||
la $a0, start
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
la $a0, id
|
||||
li $v0, 4 # call code, print string
|
||||
syscall # system call
|
||||
|
||||
la $a0, hdr
|
||||
li $v0, 4
|
||||
|
||||
li $v0, 1 # call code, print int
|
||||
lw $a0, number # value for int to print
|
||||
syscall # system call
|
||||
# ----
|
||||
la $a0, end
|
||||
li $v0, 4
|
||||
syscall
|
||||
# Done, terminate program.
|
||||
li $v0, 10 # terminate
|
||||
syscall # system call
|
||||
.end main
|
||||
@@ -0,0 +1,52 @@
|
||||
# Example program to display an array.
|
||||
# Demonstrates use of QtSpim system service calls.
|
||||
# -----------------------------------------------------
|
||||
# Data Declarations
|
||||
.data
|
||||
id: .asciiz "Student: Austin Bennett (CS 220, id: 324855)\n"
|
||||
hdr: .ascii "Squaring Example\n"
|
||||
.asciiz "Enter Value: "
|
||||
ansMsg: .asciiz "Value Squared: "
|
||||
value: .word 0
|
||||
start: .asciiz "------ START Program Example 9.2.3 ------\n"
|
||||
end: .asciiz "\n------ END Program Example 9.2.3 ------\n"
|
||||
|
||||
# -----------------------------------------------------
|
||||
# text/code section
|
||||
.text
|
||||
.globl main
|
||||
.ent main
|
||||
main:
|
||||
li $v0, 4
|
||||
la $a0, start
|
||||
syscall
|
||||
|
||||
li $v0, 4
|
||||
la $a0, id
|
||||
syscall
|
||||
|
||||
li $v0, 4 # call code for print string
|
||||
la $a0, hdr # addr of NULL terminated str
|
||||
syscall # system call
|
||||
|
||||
li $v0, 5 # call code for read integer
|
||||
syscall # system call (result in $v0)
|
||||
|
||||
mul $t0, $v0, $v0 # square answer
|
||||
sw $t0, value # save to variable
|
||||
li $v0, 4 # call code for print string
|
||||
la $a0, ansMsg # addr of NULL terminated str
|
||||
syscall # system call
|
||||
|
||||
li $v0, 1 # call code for print integer
|
||||
lw $a0, value # value for integer to print
|
||||
syscall # system call
|
||||
|
||||
li $v0, 4
|
||||
la $a0, end
|
||||
syscall
|
||||
# -----
|
||||
# Done, terminate program.
|
||||
li $v0, 10 # terminate
|
||||
syscall # system call
|
||||
.end main
|
||||
@@ -0,0 +1,42 @@
|
||||
# Write A MIPS Assembly Program to ADD the Numbers: 4, 6, 8
|
||||
|
||||
.data
|
||||
start: .asciiz "------ START Program Question 2 ------\n"
|
||||
end: .asciiz "\n------ END Program Question 2 ------\n"
|
||||
id: .asciiz "Student: Austin Bennett (CS 220, id: 324855)\n"
|
||||
tag: .ascii "4 + 6 + 8 = "
|
||||
|
||||
.text
|
||||
.globl main
|
||||
.ent main
|
||||
main:
|
||||
li $v0, 4
|
||||
la $a0, start
|
||||
syscall
|
||||
|
||||
li $v0, 4
|
||||
la $a0, id
|
||||
syscall
|
||||
|
||||
li $v0, 4
|
||||
la $a0, tag
|
||||
syscall
|
||||
|
||||
li $t0,4
|
||||
add $t1,$t1,$t0
|
||||
li $t0,6
|
||||
add $t1,$t1,$t0
|
||||
li $t0,8
|
||||
add $t1,$t1,$t0
|
||||
|
||||
li $v0, 1
|
||||
add $a0,$0,$t1
|
||||
syscall
|
||||
|
||||
li $v0, 4
|
||||
la $a0, end
|
||||
syscall
|
||||
|
||||
li $v0, 10
|
||||
syscall
|
||||
.end main
|
||||
@@ -0,0 +1,62 @@
|
||||
# Write a program in MIPS that takes two values from the user and perform
|
||||
# subtraction between them and then print the subtraction result.
|
||||
|
||||
.data
|
||||
start: .asciiz "------ START Program Question 3 ------\n"
|
||||
end: .asciiz "\n------ END Program Question 3 ------\n"
|
||||
id: .asciiz "Student: Austin Bennett (CS 220, id: 324855)\n"
|
||||
val1: .asciiz "First Value: "
|
||||
val2: .asciiz "Second Value: "
|
||||
tag: .asciiz "Result: "
|
||||
value: .word 0
|
||||
|
||||
.text
|
||||
.globl main
|
||||
.ent main
|
||||
main:
|
||||
li $v0, 4
|
||||
la $a0, start
|
||||
syscall
|
||||
|
||||
li $v0, 4
|
||||
la $a0, id
|
||||
syscall
|
||||
|
||||
# Print 1
|
||||
li $v0,4
|
||||
la $a0,val1
|
||||
syscall
|
||||
|
||||
# Read 1
|
||||
li $v0, 5
|
||||
syscall
|
||||
move $t0,$v0
|
||||
|
||||
# Print 2
|
||||
li $v0,4
|
||||
la $a0,val2
|
||||
syscall
|
||||
|
||||
# Read 2
|
||||
li $v0,5
|
||||
syscall
|
||||
move $t1,$v0
|
||||
|
||||
sub $t0,$t0,$t1
|
||||
sw $t0, value
|
||||
|
||||
li $v0,4
|
||||
la $a0,tag
|
||||
syscall
|
||||
|
||||
li $v0,1
|
||||
lw $a0, value
|
||||
syscall
|
||||
|
||||
li $v0, 4
|
||||
la $a0, end
|
||||
syscall
|
||||
|
||||
li $v0,10
|
||||
syscall
|
||||
.end main
|
||||
@@ -0,0 +1,31 @@
|
||||
.data
|
||||
start: .asciiz "------ START Program Question 3 ------\n"
|
||||
end: .asciiz "\n------ END Program Question 3 ------\n"
|
||||
id: .asciiz "Student: Austin Bennett (CS 220, id: 324855)\n"
|
||||
val: .word 65
|
||||
|
||||
.text
|
||||
.globl main
|
||||
.ent main
|
||||
main:
|
||||
li $v0, 4
|
||||
la $a0, start
|
||||
syscall
|
||||
|
||||
li $v0, 4
|
||||
la $a0, id
|
||||
syscall
|
||||
|
||||
lw $t0, val
|
||||
|
||||
|
||||
move $t1, $t0
|
||||
|
||||
|
||||
li $v0, 4
|
||||
la $a0, end
|
||||
syscall
|
||||
|
||||
li $v0, 10
|
||||
syscall
|
||||
.end main
|
||||
@@ -0,0 +1,71 @@
|
||||
.data
|
||||
x: .word 30
|
||||
y: .word 24
|
||||
|
||||
sum: .word 0
|
||||
subt: .word 0
|
||||
|
||||
promptAdd: .asciiz "The sum of X and Y is : "
|
||||
promptSub: .asciiz "\nThe difference of X and Y is : "
|
||||
|
||||
.text
|
||||
.globl main
|
||||
.ent main
|
||||
|
||||
main:
|
||||
|
||||
lw $a0, x
|
||||
lw $a1, y
|
||||
|
||||
jal Addition
|
||||
sw $v0, sum
|
||||
|
||||
jal Subtraction
|
||||
sw $v0, subt
|
||||
|
||||
la $a0, promptAdd
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
lw $a0, sum
|
||||
li $v0, 1
|
||||
syscall
|
||||
|
||||
la $a0, promptSub
|
||||
li $v0, 4
|
||||
syscall
|
||||
|
||||
lw $a0, subt
|
||||
li $v0, 1
|
||||
syscall
|
||||
|
||||
li $v0, 10
|
||||
syscall
|
||||
|
||||
.end main
|
||||
|
||||
.globl Addition
|
||||
.ent Addition
|
||||
|
||||
Addition:
|
||||
|
||||
li $v0, 0
|
||||
|
||||
add $v0, $a0, $a1
|
||||
|
||||
jr $ra
|
||||
|
||||
.end Addition
|
||||
|
||||
.globl Subtraction
|
||||
.ent Subtraction
|
||||
|
||||
Subtraction:
|
||||
|
||||
li $v0, 0
|
||||
|
||||
sub $v0, $a0, $a1
|
||||
|
||||
jr $ra
|
||||
|
||||
.end Subtraction
|
||||
Reference in New Issue
Block a user