Professional Documents
Culture Documents
MehmetEmre Kantaş 001 LabWork Lab01
MehmetEmre Kantaş 001 LabWork Lab01
Lab01
001
Mehmet Emre Kantaş
22003693
10/05/2022
-------------------------Lab01 Program1.asm-------------------------
##
## Program1.asm - prints out "hello world"
##
## a0 - points to the string
##
#################################
# #
# text segment #
# #
#################################
.text
.globl __start
#################################
# #
# data segment #
# #
#################################
.data
str: .asciiz "hello Pouya Ghahramanian"
n: .word 10
##
## end of file Program1.asm
-------------------------Lab01 Program2.asm-------------------------
##
## Program2.asm asks user for temperature in Celsius,
## converts to Fahrenheit, prints the result.
##
## v0 - reads in Celsius
## t0 - holds Fahrenheit result
## a0 - points to output strings
##
#################################
# #
# text segment #
# #
#################################
.text
.globl __start
__start:
la $a0,prompt # output prompt message on terminal
li $v0,4 # syscall 4 prints the string
syscall
#################################
# #
# data segment #
# #
#################################
.data
prompt: .asciiz "Enter temperature (Celsius): "
ans1: .asciiz "The temperature in Fahrenheit is "
endl: .asciiz "\n"
##
## end of file Program2.asm
-------------------------Lab01 Program3.asm-------------------------
##
## Program3.asm is a loop implementation
## of the Fibonacci function
##
#################################
# #
# text segment #
# #
#################################
.text
.globl __start
li $v0,10
syscall # bye bye
#------------------------------------------------
#################################
# #
# data segment #
# #
#################################
.data
endl: .asciiz "\n"
##
## end of Program3.asm
-------------------------Lab01 Part2_3-------------------------
#lab1_3.asm
.data
A: .word 0
B: .word 0
entera: .asciiz "Enter a: "
enterb: .asciiz "Enter b: "
.text
main:
sw $v0, A
sw $v0, B
#to multiply by A
addi $t2, $0, 2
#system exit
li $v0, 10
syscall
-------------------------Lab01 Part2_4-------------------------
.data
.text
main:
fillingTheArray:
#taking input
li $v0, 5
syscall
la $a0, select #
li $v0, 4 #
syscall #
#
la $a0, select2 #
li $v0, 4 #Displaying menu
syscall #
#
la $a0, select3 #
li $v0, 4 #
syscall #
selection1:
#prompting the user and taking input to choose greater than number
la $a0, yourInput
li $v0, 4
syscall
li $v0, 5
syscall
move $t0, $v0 #t0 is input
loop1:
bge $t4, $t2, print1 #if(i >= arraysize) -> print1
lw $t5, 0($t1) #t5 is elem at index i
addi $t1, $t1, 4 #next element of the array
addi $t4, $t4, 1 #next index
sgt $t6, $t5, $t0 #copy of the elem at current index because $t5 should
not be corrupted
beq $t6, 0, loop1
add $t3, $t3, $t5
j loop1
print1:
la $a0, select1out
li $v0, 4
syscall
selection2:
print2:
la $a0, select2evenOut
li $v0, 4
syscall
la $a0, select2oddOut
li $v0, 4
syscall
selection3:
la $a0, yourInput
li $v0, 4
syscall
li $v0, 5
syscall
move $t0, $v0 #t0 is input
loop3:
bge $t4, $t2, print3
lw $t5, 0($t1)#elem at index i
addi $t1, $t1, 4
addi $t4, $t4, 1
addi $t6, $t5, 0
mod3:
blt $t6, $t0, doneMod3
sub $t6, $t6, $t0
j mod3
doneMod3:
print3:
la $a0, select3Out
li $v0, 4
syscall
done:
la $a0, goodbye
li $v0, 4
syscall
li $v0, 10
syscall