Compile procedure calls

This commit is contained in:
2025-04-24 23:01:12 +02:00
parent f343296463
commit 2e0c958aa3
4 changed files with 812 additions and 185 deletions

View File

@@ -1,4 +1,4 @@
.global is_alpha, is_digit, is_alnum, is_upper, is_lower, write_out, read_file, exit, memcmp, write_error
.global _is_alpha, _is_digit, _is_alnum, _is_upper, _is_lower, _write_out, _read_file, exit, _memcmp, _write_error
.section .rodata
@@ -16,8 +16,8 @@ new_line: .ascii "\n"
# Write the current token to stderr.
# a0 - String pointer.
# a1 - String length.
.type write_error, @function
write_error:
.type _write_error, @function
_write_error:
mv t0, a0
mv t1, a1
@@ -40,8 +40,8 @@ write_error:
# a2 - The length to compare.
#
# Returns 0 in a0 if memory regions are equal.
.type memcmp, @function
memcmp:
.type _memcmp, @function
_memcmp:
mv t0, a0
li a0, 0
@@ -64,7 +64,8 @@ memcmp:
ret
# Detects if a0 is an uppercase character. Sets a0 to 1 if so, otherwise to 0.
is_upper:
.type _is_upper, @function
_is_upper:
li t0, 'A' - 1
sltu t1, t0, a0 # t1 = a0 >= 'A'
@@ -74,8 +75,8 @@ is_upper:
ret
# Detects if a0 is an lowercase character. Sets a0 to 1 if so, otherwise to 0.
.type is_lower, @function
is_lower:
.type _is_lower, @function
_is_lower:
li t0, 'a' - 1
sltu t2, t0, a0 # t2 = a0 >= 'a'
@@ -87,8 +88,8 @@ is_lower:
# Detects if the passed character is a 7-bit alpha character or an underscore.
# The character is passed in a0.
# Sets a0 to 1 if the character is an alpha character or underscore, sets it to 0 otherwise.
.type is_alpha, @function
is_alpha:
.type _is_alpha, @function
_is_alpha:
# Prologue.
addi sp, sp, -16
sw ra, 12(sp)
@@ -97,11 +98,11 @@ is_alpha:
sw a0, 4(sp)
call is_upper
call _is_upper
sw a0, 0(sp)
lw a0, 4(sp)
call is_lower
call _is_lower
lw t0, 4(sp)
xori t1, t0, '_'
@@ -117,8 +118,8 @@ is_alpha:
addi sp, sp, 16
ret
.type is_digit, @function
is_digit:
.type _is_digit, @function
_is_digit:
li t0, '0' - 1
sltu t1, t0, a0 # t1 = a0 >= '0'
@@ -128,8 +129,8 @@ is_digit:
ret
.type is_alnum, @function
is_alnum:
.type _is_alnum, @function
_is_alnum:
# Prologue.
addi sp, sp, -16
sw ra, 12(sp)
@@ -138,11 +139,11 @@ is_alnum:
sw a0, 4(sp)
call is_alpha
call _is_alpha
sw a0, 0(sp)
lw a0, 4(sp)
call is_digit
call _is_digit
lw a1, 0(sp)
or a0, a0, a1
@@ -153,8 +154,8 @@ is_alnum:
addi sp, sp, 16
ret
.type write, @function
write_out:
.type _write_out, @function
_write_out:
# Prologue.
addi sp, sp, -8
sw ra, 4(sp)
@@ -178,8 +179,8 @@ write_out:
# a1 - Buffer size.
#
# Returns the result in a0.
.type read_file, @function
read_file:
.type _read_file, @function
_read_file:
# Prologue.
addi sp, sp, -8
sw ra, 4(sp)