From bbb5b4b35f1414aa06426a41cf046584109c254f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Thu, 18 Aug 2022 14:53:07 +0300 Subject: [PATCH] Store line length in a variable in calculator.asm --- calculator.asm | 54 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/calculator.asm b/calculator.asm index 30bdf8a..64d97fe 100644 --- a/calculator.asm +++ b/calculator.asm @@ -1,10 +1,41 @@ org 0 -start: - cleq r0, r0, stReadline - cleq r0, r0, dumpstack +cleq r0, r0, readline - halt +load r0, linelen+0 +load r1, linelen+1 +cleq r0, r0, pushWord + +cleq r0, r0, stDup +cleq r0, r0, stPrinthex + +xor r0, r0 +xor r1, r1 +cleq r0, r0, pushWord + +printloop: + cleq r0, r0, stOver + cleq r0, r0, stOver + cleq r0, r0, stSwap + cleq r0, r0, stGtEq + brneq r0, r1, printend + + cleq r0, r0, stDup + load r0, linebufStart+0 + load r1, linebufStart+1 + cleq r0, r0, pushWord + cleq r0, r0, stAdd + + cleq r0, r0, stLoadByte + cleq r0, r0, stEmit + + cleq r0, r0, stInc + + breq r0, r0, printloop + +printend: +cleq r0, r0, newline +halt debug: store debugr0, r0 @@ -108,7 +139,7 @@ debug: debugr2: data 0 debugr3: data 0 -stReadline: +readline: ; Current index starts at 0 xor r0, r0 xor r1, r1 @@ -151,8 +182,13 @@ stReadline: breq r0, r0, readlineLoop readlineEnter: - ; Remove the CR byte off the stack, as we only want to return the length + ; Remove the CR byte off the stack, as it's not needed cleq r0, r0, popWord + + cleq r0, r0, popWord + store linelen+0, r0 + store linelen+1, r1 + breq r0, r0, newline readlineBackspace: @@ -169,6 +205,7 @@ stReadline: brneq r0, r1, readlineLoop ; Decrease the index and erase the echoed character + ; TODO: utf-8 cleq r0, r0, stDec load r3, litcharSpace store ffff, r3 @@ -179,6 +216,7 @@ stReadline: readlineBufFull: ; Drop the input byte and erase the echoed character + ; TODO: utf-8 cleq r0, r0, popWord load r3, litcharBS store ffff, r3 @@ -1064,6 +1102,10 @@ litff: data ff ; Data ; ================================================================== +linelen: + data 0 + data 0 + linebufStart: addr end linebufSize: data 00