aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-04-13 23:28:24 +0200
committerkdx <kikoodx@paranoici.org>2023-04-13 23:28:24 +0200
commite1e94814565bfe659e6d879fcd1dcd4fe575d965 (patch)
tree6517692093cfd2a287b467b2ddb79737ca168e69
parenta0615ea6f7496e97a5d9f837e9cf80fd6ec3acd0 (diff)
downloadorga-e1e94814565bfe659e6d879fcd1dcd4fe575d965.tar.gz
INC DEC
-rw-r--r--samples/helloworld.orgaasm2
-rw-r--r--spec.md2
-rw-r--r--src/ops.h4
-rw-r--r--src/orgaemu.c6
4 files changed, 13 insertions, 1 deletions
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)