Professional Documents
Culture Documents
MehmetEmre Kantaş 001 PRELIM 01
MehmetEmre Kantaş 001 PRELIM 01
Lab 1
001
Mehmet Emre Kantaş
22003693
10/05/2022
#CS224_Lab1_1.asm --> This program creates an array with the maximum size 20, takes
the actual array length from the user
#as an input, fills the array according to the inputs of the user, displays the
array, reverses the order of the elements,
#displays the array again.
.globl main
.text
main:
#prompting the user to enter the size of the array
la $a0, enterSize
li $v0, 4
syscall
#Starting to create array by taking array elements as inputs from the user
fillingTheArray:
#taking input
li $v0, 5
syscall
# loading the first and the last elements of the array to register t5
and t6, respectively
lw $t5, 0($t0)
lw $t6, 0($t1)
#if the last element is printed, stop branching into comma and branch
into done
bgt $t1, $t4, putComma
ble $t1, $t4, done
#data section
.data
array: .space 80
arraySize: .word 0
enterSize: .asciiz "Enter the size of the array(maximum 20): "
enterElem: .asciiz "Enter element: "
displayMsg: .asciiz "Array: "
comma: .asciiz ", "
endl: .asciiz "\n"
--------------------------------------------END OF SWAP (PRELIMINARY WORK
PART1.1)---------------------------------------------
------------------------------------------ARITHMETIC EXPRESSION(PRELIMINARY WORK
PART1.2)--------------------------------------
#CS224_Lab1_2.asm --> This program takes inputs from the user to be used in an
arithmetic expression. 3 inputs will be taken
#as integers: B, C and D. Using these integers, we will have A = (B / C + D * B -
C) mod B as a result. The program will display
#this result at the end of the execution flow.
.globl main
.text
main:
doneDiv:
#taking mod B of the value in the register t1 to find the final result
doneMod:
#printing results
move $a0, $t5
li $v0, 1
syscall
#exiting
li $v0, 10
syscall
#data section
.data
result: .word 0
B: .word 0
C: .word 0
D: .word 0
userPrompt: .asciiz "You need to enter 3 integer values for the
arithmetic expression (to find A)"
askB: .asciiz "Enter the number B: "
askC: .asciiz "Enter the number C: "
askD: .asciiz "Enter the number D: "
finalMessage: .asciiz "(B / C + D * B - C) mod B = "
endl: .asciiz "\n"