Store line length in a variable in calculator.asm

This commit is contained in:
Juhani Krekelä 2022-08-18 14:53:07 +03:00
parent e8102339d7
commit bbb5b4b35f
1 changed files with 48 additions and 6 deletions

View File

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