more projects
This commit is contained in:
@@ -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