Implement addition and subtraction
This commit is contained in:
@ -18,10 +18,16 @@ printi:
|
||||
# t1 - Constant 10.
|
||||
# a1 - Local buffer.
|
||||
# t2 - Current character.
|
||||
# t3 - Whether the number is negative.
|
||||
lw t0, 0(s0)
|
||||
addi t1, zero, 10
|
||||
addi a1, s0, -2
|
||||
|
||||
addi t3, zero, 0
|
||||
bge t0, zero, .digit10
|
||||
addi t3, zero, 1
|
||||
sub t0, zero, t0
|
||||
|
||||
.digit10:
|
||||
rem t2, t0, t1
|
||||
addi t2, t2, '0'
|
||||
@ -30,8 +36,12 @@ printi:
|
||||
addi a1, a1, -1
|
||||
bne zero, t0, .digit10
|
||||
|
||||
ecall
|
||||
beq zero, t3, .write_call
|
||||
addi t2, zero, '-'
|
||||
sb t2, 0(a1)
|
||||
addi a1, a1, -1
|
||||
|
||||
.write_call:
|
||||
addi a0, zero, 1
|
||||
addi a1, a1, 1
|
||||
sub a2, s0, a1
|
||||
|
Reference in New Issue
Block a user