~yerinalexey/scalc-os

5a8bb045c22637172397d3a6c7dc9d2299f27c36 — Alexey Yerin 4 months ago a6fc662
Implement a clone command
2 files changed, 19 insertions(+), 3 deletions(-)

M README.md
M src/main.s
M README.md => README.md +2 -1
@@ 10,7 10,8 @@ implements only the surface functionality though - decimal integers and

* `.` - print last value in the stack
* `d` - drop last value from the stack
* `s` - swap two last values
* `s` - swap last two values
* `c` - push a copy of the last value

Interactions are done through the default input device, in case of most systems,
that would be serial. Entering a number to push it onto the stack works as

M src/main.s => src/main.s +17 -2
@@ 31,6 31,8 @@ kmain:
	li t0, 8
	beq a0, t0, exec_swap
	li t0, 9
	beq a0, t0, exec_clone
	li t0, 10
	beq a0, t0, exec_invalid
exec_number:
	add sp, sp, -8


@@ 117,6 119,13 @@ exec_swap:
	li a0, 's'
	call printcln
	j 2f
exec_clone:
	ld t0, (sp)
	add sp, sp, -8
	sd t0, (sp)
	li a0, 'c'
	call printcln
	j 2f
exec_invalid:
	li a0, '?'
	call printcln


@@ 139,7 148,8 @@ exec_invalid:
        | 6 (print)
        | 7 (drop)
        | 8 (swap)
        | 9 (invalid)
        | 9 (clone)
        | 10 (invalid)
*/
readatom:
	sd fp, -16(sp)


@@ 175,6 185,8 @@ retry:
	beq a0, t0, drop
	li t0, 's'
	beq a0, t0, swap
	li t0, 'c'
	beq a0, t0, clone

	/* 0 < (a0 - '0') < 9 */
	add a0, a0, -'0'


@@ 231,8 243,11 @@ drop:
swap:
	li a0, 8
	j 2f
invalid:
clone:
	li a0, 9
	j 2f
invalid:
	li a0, 10
2:
	add sp, fp, 16
	ld ra, 8(fp)