-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#Name: Bradley Gunawan | ||
#11/6/2024 | ||
#Task 1: User input and output | ||
#get two int valeus from the user | ||
#two user values should be held in $s0 and $s1 | ||
#output the use inputs in "Run I/O section back to the user | ||
#Task 2: Arithmetic Operation Practice | ||
#add two values | ||
#subtract two values | ||
#multiply two values | ||
#divide two values | ||
#Task 3: Conditions | ||
#check if two user inputs are equal to each other and output if they're the same | ||
#check if two user inputs are different and output if they're different | ||
.data | ||
#task 1 | ||
msg1: .asciiz "Enter the first integer: " | ||
msg2: .asciiz "Enter the second integer: " | ||
output1: .asciiz "\nThe first integer is: " | ||
output2: .asciiz "\nThe second integer is: " | ||
#task 2 | ||
add_int: .asciiz "\nThe sum of your two inputs: " | ||
sub_int: .asciiz "\nThe difference of your two inputs: " | ||
mult_int: .asciiz "\nThe product of your two inputs: " | ||
div_int: .asciiz "\nThe quotient of your two inputs: " | ||
#task 3 | ||
equal_output: .asciiz "\nUser inputs are the same." | ||
difference_output: .asciiz "\nUser inputs are not the same." | ||
.text | ||
task1: | ||
#input msg for first integer | ||
li $v0, 4 | ||
la $a0, msg1 | ||
syscall | ||
li $v0, 5 | ||
syscall | ||
move $s0, $v0 | ||
#input msg for second integer | ||
li $v0, 4 | ||
la $a0, msg2 | ||
syscall | ||
li $v0, 5 | ||
syscall | ||
move $s1, $v0 | ||
#output first integer | ||
li $v0, 4 | ||
la $a0, output1 | ||
syscall | ||
move $a0, $s0 | ||
li $v0, 1 | ||
syscall | ||
#output second integer | ||
li $v0, 4 | ||
la $a0, output2 | ||
syscall | ||
move $a0, $s1 | ||
li $v0, 1 | ||
syscall | ||
task2: | ||
#addition | ||
add $t0, $s0, $s1 | ||
li $v0, 4 | ||
la $a0, add_int | ||
syscall | ||
move $a0, $t0 | ||
li $v0, 1 | ||
syscall | ||
#subtraction | ||
sub $t1, $s0, $s1 | ||
li $v0, 4 | ||
la $a0, sub_int | ||
syscall | ||
move $a0, $t1 | ||
li $v0, 1 | ||
syscall | ||
#multiplication | ||
mul $t2, $s0, $s1 | ||
li $v0, 4 | ||
la $a0, mult_int | ||
syscall | ||
move $a0, $t2 | ||
li $v0, 1 | ||
syscall | ||
#division | ||
div $t3, $s0, $s1 | ||
li $v0, 4 | ||
la $a0, div_int | ||
syscall | ||
move $a0, $t3 | ||
li $v0, 1 | ||
syscall | ||
task3: | ||
#compare the inputs | ||
beq $s0, $s1, equal_input | ||
#if not equal | ||
li $v0, 4 | ||
la $a0, difference_output | ||
syscall | ||
b exit | ||
equal_input: | ||
#if the inputs equal | ||
li $v0, 4 | ||
la $a0, equal_output | ||
syscall | ||
exit: | ||
#Exit the program | ||
li $v0, 10 | ||
syscall | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#Bradley Gunawan 11/4/2024 | ||
#CS2640 12PM | ||
#November 1, 2024 | ||
# array = [1, 2, 3, 4, 5] (y) | ||
#print out array elements to user | ||
# include: display message, main label (y), loop label, exit label, element loop counter | ||
# use registers: $s0 for base address, $t0 for current array element | ||
|
||
.data | ||
array: .word 1, 2, 3, 4, 5 | ||
curEl: .asciiz "\nCurrent Element: " | ||
displayMessage: .asciiz "Here are your array elements: \n" | ||
arraySize: .word 5 #size of array | ||
|
||
.text | ||
main: | ||
#print displayMessage to user | ||
li $v0, 4 | ||
la $a0, displayMessage | ||
syscall | ||
la $s0, array #loads base address of 'array' into $s0 | ||
li $t1, 0 #initialize loop counter to 0 | ||
lw $t2, arraySize #load arraySize | ||
|
||
loop: | ||
|
||
bge $t1, $t2, exit #check if we reached end of array | ||
#print out message for element | ||
li $v0, 4 | ||
la $a0, curEl | ||
syscall | ||
#load current element from array to $t0 | ||
lw $t0, 0($s0) | ||
#print out element | ||
li $v0, 1 | ||
move $a0, $t0 | ||
syscall | ||
add $s0, $s0, 4 #incrememnt offset 4 bytes | ||
add $t1, $t1, 1 #increment loop counter | ||
#repeat loop | ||
j loop | ||
exit: | ||
#exit the program | ||
li $v0, 10 | ||
syscall | ||