2024-04-05 17:02:26 +02:00
|
|
|
# Define variables
|
|
|
|
.data
|
|
|
|
.align 4
|
|
|
|
num1: .word 5 # First number
|
|
|
|
num2: .word 7 # Second number
|
|
|
|
result: .word 0 # Variable to store the result
|
|
|
|
msg: .ascii "Hello, World!\n"
|
|
|
|
|
|
|
|
# Main program entry point
|
|
|
|
.text
|
|
|
|
.global _start
|
|
|
|
.align 4
|
|
|
|
test_routine:
|
|
|
|
la a0, num1 # Load the address of num1 into register a6
|
|
|
|
li a1, 10 # Load the value 10 into register a5
|
|
|
|
xori a2, a1, 0x1 # Calculate the value of a2
|
|
|
|
sw a1, 0(a0) # Store the value in memory
|
|
|
|
ret
|
2024-04-01 11:09:45 +02:00
|
|
|
|
|
|
|
_start:
|
2024-04-05 17:02:26 +02:00
|
|
|
call h2
|
|
|
|
call test_routine
|
|
|
|
call hello
|
|
|
|
|
|
|
|
# Load the first number into register t0
|
|
|
|
lw t0, num1
|
|
|
|
|
|
|
|
# Load the second number into register t1
|
|
|
|
lw t1, num2
|
|
|
|
|
|
|
|
# Add the two numbers and store the result in register t2
|
|
|
|
add t2, t0, t1
|
|
|
|
|
|
|
|
# Store the result in memory
|
|
|
|
la t3, result
|
|
|
|
sw t2, 0(t3)
|
|
|
|
|
|
|
|
# Call _hello
|
|
|
|
la a0, result
|
|
|
|
|
|
|
|
# End program
|
|
|
|
ecall
|
|
|
|
|
|
|
|
h2:
|
|
|
|
addi a0, x0, 0x68
|
|
|
|
li a1, 0x10000000
|
|
|
|
sb a0, (a1) # 'h'
|
|
|
|
|
|
|
|
addi a0, x0, 0x65
|
|
|
|
sb a0, (a1) # 'e'
|
|
|
|
|
|
|
|
addi a0, x0, 0x6C
|
|
|
|
sb a0, (a1) # 'l'
|
|
|
|
|
|
|
|
addi a0, x0, 0x6C
|
|
|
|
sb a0, (a1) # 'l'
|
|
|
|
|
|
|
|
addi a0, x0, 0x6F
|
|
|
|
sb a0, (a1) # 'o'
|
|
|
|
ret
|
|
|
|
|
|
|
|
hello:
|
|
|
|
# Write the string "Hello, World!\n" to stdout
|
|
|
|
la a0, msg # Load the address of the string into a0
|
|
|
|
li a7, 4 # syscall number for write
|
|
|
|
li a1, 13 # Length of the string
|
|
|
|
li a2, 1 # File descriptor: stdout
|
|
|
|
ecall # Make the system call to write
|
|
|
|
ret # Return from the function
|
|
|
|
|
|
|
|
# To avoid the program from exiting
|
|
|
|
loop: j loop
|
|
|
|
|