From 7c0e11359348b99c5c05351effb41198a9fd01db Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 5 Apr 2024 18:27:41 +0200 Subject: [PATCH] Semi-working output, still no exall --- end.s | 19 +++++++++++++++++++ main.s | 54 +++++++++++++++++++++++++----------------------------- 2 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 end.s diff --git a/end.s b/end.s new file mode 100644 index 0000000..07b6e36 --- /dev/null +++ b/end.s @@ -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 \ No newline at end of file diff --git a/main.s b/main.s index 70bdd83..cbdd0b4 100644 --- a/main.s +++ b/main.s @@ -5,11 +5,19 @@ num2: .word 7 # Second number result: .word 0 # Variable to store the result msg: .ascii "Hello, World!\n" + array: .space 100 # 100 bytes of space # Main program entry point +.globl start .text -.global _start -.align 4 +start: + call test_routine + call hello_manual + # call hello # This doesn't work + call end + ebreak + +# Arbitrary test routine test_routine: la a0, num1 # Load the address of num1 into register a6 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 ret -_start: - 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: +# Prints "hello" manually +hello_manual: addi a0, x0, 0x68 li a1, 0x10000000 sb a0, (a1) # 'h' @@ -57,8 +42,12 @@ h2: addi a0, x0, 0x6F sb a0, (a1) # 'o' + + addi a0, x0, 0x0A + sb a0, (a1) # '\n' ret +# Is supposed to print "Hello, World!\n" to stdout via ecall, but doesn't work hello: # Write the string "Hello, World!\n" to stdout la a0, msg # Load the address of the string into a0 @@ -68,6 +57,13 @@ hello: ecall # Make the system call to write ret # Return from the function -# To avoid the program from exiting -loop: j loop +# Another routine, presumably written for the rars emulator? +hello2: + li a0, 0x1 + la a1, msg + li a2, 13 + li a7, 64 + ecall +# To avoid the program from exiting +loop: j loop \ No newline at end of file