Work on inc line count function
This commit is contained in:
@@ -52,6 +52,8 @@ _start:
|
||||
li s1, 1
|
||||
li s2, 0 # processed files
|
||||
|
||||
call zero_line_count
|
||||
bnez a0, .LMainReturnErr
|
||||
call _check_flags
|
||||
|
||||
li t0, 1
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
.data
|
||||
line_count: .space 8
|
||||
line_count: .space 6
|
||||
|
||||
.section .text
|
||||
.globl add_endings, add_line_numbers
|
||||
.globl add_endings, add_line_numbers, zero_line_count
|
||||
|
||||
# Print to stdout while adding "$" characters.
|
||||
# @param[in] a0: ptr to null-terminated str.
|
||||
@@ -132,3 +132,57 @@ add_line_numbers:
|
||||
addi sp, sp, 72
|
||||
ret
|
||||
|
||||
|
||||
# Increment the line count string
|
||||
# @param[in] a0: not used
|
||||
# @param[out] a0: result code
|
||||
_inc_line_count:
|
||||
la t0, line_count # load the line count buffer address
|
||||
li t1, 5 # current offset, we move from right to left first
|
||||
|
||||
.LIncLine:
|
||||
bltz t1, .LLineCountDoneInc
|
||||
add t2, t0, t1 # load the correct offset address into t2
|
||||
lb t3, 0(t2) # load the current ascii character into t3
|
||||
|
||||
li t4, 32 # load space character
|
||||
bne t3, t4, .LLineCountNotSpaceChar # if the character is not a space, skip setting to zero
|
||||
li t4, 48 # ascii '0'
|
||||
sb t4, 0(t2) # store this at the current pointer
|
||||
|
||||
.LLineCountNotSpaceChar:
|
||||
add t2, t0, t1 # load the correct offset address into t2
|
||||
lb t3, 0(t2) # load the current ascii character into t3
|
||||
li t4, 58 # ascii ':', right after ascii '9', overflow
|
||||
|
||||
addi t3, t3, 1
|
||||
beq t3, t4, .LLineCountOverflow
|
||||
sb t3, 0(t2)
|
||||
j .LLineCountDoneInc
|
||||
.LLineCountOverflow:
|
||||
li t4, 48 # ascii '0'
|
||||
sb t4, 0(t2) # store that ascii '0'
|
||||
li t4, 1
|
||||
sub t1, t1, t4 # move to the next digit to the left
|
||||
j .LIncLine
|
||||
|
||||
.LLineCountDoneInc:
|
||||
ret
|
||||
|
||||
# Set the line count to all space characters
|
||||
# @param[in] a0: not used
|
||||
# @param[out] a0: result code
|
||||
zero_line_count:
|
||||
la t0, line_count # load the line count buffer address
|
||||
li t1, 0 # char ptr
|
||||
li t2, 5 # max char
|
||||
li t3, 32 # space character
|
||||
|
||||
1:
|
||||
add t4, t0, t1 # load offset addr
|
||||
sb t3, 0(t4) # store the space char in offset addr
|
||||
addi t1, t1, 1
|
||||
blt t1, t2, 1b
|
||||
|
||||
li a0, 0
|
||||
ret
|
||||
|
||||
Reference in New Issue
Block a user