Implement addition and subtraction

This commit is contained in:
2024-09-29 19:50:55 +02:00
parent ed144309fa
commit c2c923276f
11 changed files with 131 additions and 89 deletions

View File

@ -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