Risc-V-Asm/main.s

70 lines
1.6 KiB
ArmAsm
Raw Permalink Normal View History

2024-04-05 17:02:26 +02:00
# Define variables
.data
num1: .word 5 # First number
num2: .word 7 # Second number
result: .word 0 # Variable to store the result
msg: .ascii "Hello, World!\n"
2024-04-05 18:27:41 +02:00
array: .space 100 # 100 bytes of space
2024-04-05 17:02:26 +02:00
# Main program entry point
2024-04-05 18:27:41 +02:00
.globl start
2024-04-05 17:02:26 +02:00
.text
2024-04-05 18:27:41 +02:00
start:
call test_routine
call hello_manual
# call hello # This doesn't work
call end
ebreak
# Arbitrary test routine
2024-04-05 17:02:26 +02:00
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
2024-04-05 18:27:41 +02:00
# Prints "hello" manually
2024-12-09 12:25:56 +01:00
hello_manual:
2024-04-05 17:02:26 +02:00
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'
2024-04-05 18:27:41 +02:00
addi a0, x0, 0x0A
sb a0, (a1) # '\n'
2024-04-05 17:02:26 +02:00
ret
2024-04-05 18:27:41 +02:00
# Is supposed to print "Hello, World!\n" to stdout via ecall, but doesn't work
2024-04-05 17:02:26 +02:00
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
2024-04-05 18:27:41 +02:00
# Another routine, presumably written for the rars emulator?
hello2:
li a0, 0x1
la a1, msg
li a2, 13
li a7, 64
ecall
2024-04-05 17:02:26 +02:00
2024-04-05 18:27:41 +02:00
# To avoid the program from exiting
2024-04-05 19:53:44 +02:00
loop: j loop