Semi-working output, still no exall
This commit is contained in:
parent
6e1839892a
commit
7c0e113593
2 changed files with 44 additions and 29 deletions
19
end.s
Normal file
19
end.s
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Just print the word 'exit' to the address 0x10000000
|
||||||
|
.globl end
|
||||||
|
end:
|
||||||
|
addi a0, x0, 0x65 # 'e'
|
||||||
|
li a1, 0x10000000
|
||||||
|
sb a0, (a1)
|
||||||
|
|
||||||
|
addi a0, x0, 0x78 # 'x'
|
||||||
|
sb a0, (a1)
|
||||||
|
|
||||||
|
addi a0, x0, 0x69 # 'i'
|
||||||
|
sb a0, (a1)
|
||||||
|
|
||||||
|
addi a0, x0, 0x74 # 't'
|
||||||
|
sb a0, (a1)
|
||||||
|
|
||||||
|
addi a0, x0, 0x0A
|
||||||
|
sb a0, (a1) # '\n'
|
||||||
|
ret
|
54
main.s
54
main.s
|
@ -5,11 +5,19 @@
|
||||||
num2: .word 7 # Second number
|
num2: .word 7 # Second number
|
||||||
result: .word 0 # Variable to store the result
|
result: .word 0 # Variable to store the result
|
||||||
msg: .ascii "Hello, World!\n"
|
msg: .ascii "Hello, World!\n"
|
||||||
|
array: .space 100 # 100 bytes of space
|
||||||
|
|
||||||
# Main program entry point
|
# Main program entry point
|
||||||
|
.globl start
|
||||||
.text
|
.text
|
||||||
.global _start
|
start:
|
||||||
.align 4
|
call test_routine
|
||||||
|
call hello_manual
|
||||||
|
# call hello # This doesn't work
|
||||||
|
call end
|
||||||
|
ebreak
|
||||||
|
|
||||||
|
# Arbitrary test routine
|
||||||
test_routine:
|
test_routine:
|
||||||
la a0, num1 # Load the address of num1 into register a6
|
la a0, num1 # Load the address of num1 into register a6
|
||||||
li a1, 10 # Load the value 10 into register a5
|
li a1, 10 # Load the value 10 into register a5
|
||||||
|
@ -17,31 +25,8 @@ test_routine:
|
||||||
sw a1, 0(a0) # Store the value in memory
|
sw a1, 0(a0) # Store the value in memory
|
||||||
ret
|
ret
|
||||||
|
|
||||||
_start:
|
# Prints "hello" manually
|
||||||
call h2
|
hello_manual:
|
||||||
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
|
addi a0, x0, 0x68
|
||||||
li a1, 0x10000000
|
li a1, 0x10000000
|
||||||
sb a0, (a1) # 'h'
|
sb a0, (a1) # 'h'
|
||||||
|
@ -57,8 +42,12 @@ h2:
|
||||||
|
|
||||||
addi a0, x0, 0x6F
|
addi a0, x0, 0x6F
|
||||||
sb a0, (a1) # 'o'
|
sb a0, (a1) # 'o'
|
||||||
|
|
||||||
|
addi a0, x0, 0x0A
|
||||||
|
sb a0, (a1) # '\n'
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
# Is supposed to print "Hello, World!\n" to stdout via ecall, but doesn't work
|
||||||
hello:
|
hello:
|
||||||
# Write the string "Hello, World!\n" to stdout
|
# Write the string "Hello, World!\n" to stdout
|
||||||
la a0, msg # Load the address of the string into a0
|
la a0, msg # Load the address of the string into a0
|
||||||
|
@ -68,6 +57,13 @@ hello:
|
||||||
ecall # Make the system call to write
|
ecall # Make the system call to write
|
||||||
ret # Return from the function
|
ret # Return from the function
|
||||||
|
|
||||||
# To avoid the program from exiting
|
# Another routine, presumably written for the rars emulator?
|
||||||
loop: j loop
|
hello2:
|
||||||
|
li a0, 0x1
|
||||||
|
la a1, msg
|
||||||
|
li a2, 13
|
||||||
|
li a7, 64
|
||||||
|
ecall
|
||||||
|
|
||||||
|
# To avoid the program from exiting
|
||||||
|
loop: j loop
|
Loading…
Reference in a new issue