From e1e94814565bfe659e6d879fcd1dcd4fe575d965 Mon Sep 17 00:00:00 2001 From: kdx Date: Thu, 13 Apr 2023 23:28:24 +0200 Subject: INC DEC --- samples/helloworld.orgaasm | 2 +- spec.md | 2 ++ src/ops.h | 4 ++++ src/orgaemu.c | 6 ++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/samples/helloworld.orgaasm b/samples/helloworld.orgaasm index e3f39a7..2c3a0fa 100644 --- a/samples/helloworld.orgaasm +++ b/samples/helloworld.orgaasm @@ -4,7 +4,7 @@ RET @putstr ( str -- ) DUP LDA WRT ( write ) - #0001 ADD ( increment pointer ) + INC ( increment pointer ) DUP LDA ( loop until end of string ) JNZ ,putstr RET diff --git a/spec.md b/spec.md index 2954a31..bac7d39 100644 --- a/spec.md +++ b/spec.md @@ -35,3 +35,5 @@ XOR ( a b -- a^b ) LSF ( a shift -- c ) left shift RSF ( a shift -- c ) right shift SLP ( -- ) give control back to the interpreter +INC ( a -- a+1 ) +DEC ( a -- a-1 ) diff --git a/src/ops.h b/src/ops.h index 2ad2285..de30ea2 100644 --- a/src/ops.h +++ b/src/ops.h @@ -32,6 +32,8 @@ enum { OP_LSF, OP_RSF, OP_SLP, + OP_INC, + OP_DEC, }; static const char ops[][4] = { @@ -66,4 +68,6 @@ static const char ops[][4] = { [OP_LSF] = "LSF", [OP_RSF] = "RSF", [OP_SLP] = "SLP", + [OP_INC] = "INC", + [OP_DEC] = "DEC", }; diff --git a/src/orgaemu.c b/src/orgaemu.c index cdadb69..cb1d6e2 100644 --- a/src/orgaemu.c +++ b/src/orgaemu.c @@ -143,6 +143,12 @@ exec_data(uint16_t *mem) case OP_XOR: push(pop() ^ pop()); break; + case OP_INC: + push(pop() + 1); + break; + case OP_DEC: + push(pop() - 1); + break; default: fprintf(stderr, "unhandled opcode %04x\n", mem[pc]); if (mem[pc] <= OP_SLP) -- cgit v1.2.3