From 53956bd3f874993083c8ea2f8574864ebd8f802e Mon Sep 17 00:00:00 2001 From: ALittlePatate Date: Sat, 5 Aug 2023 20:58:26 +0200 Subject: [PATCH] add: end instruction --- docs/documentation.md | 1 + src/instructions.c | 4 ++++ src/instructions.h | 2 ++ src/main.c | 5 +---- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/documentation.md b/docs/documentation.md index 4fce0fc..b4ff8fd 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -82,6 +82,7 @@ The syntax is very close to x86 Intel Assembly. Here is a list of the operands a | **jna** foo | Jumps to `foo` if `cmp` didn't return `CMP_ABOVE` | no | | **jmp** foo | Jumps to `foo` | no | | **ret** | Returns from the callee to the caller | no | +| **end** | Ends the program | no | | **pop** a1 | Pops the first element of the stack into a1 | no | | **push** 69 | Pushes the value 69 to the top of the stack | no | | **call** put | Calls the `put` API | yes/no | diff --git a/src/instructions.c b/src/instructions.c index fa76c8c..2270f26 100644 --- a/src/instructions.c +++ b/src/instructions.c @@ -276,3 +276,7 @@ void xor () { eax = get_value(args->arg1) ^ get_value(args->arg2); } + +void end() { + exit_code = 1; +} diff --git a/src/instructions.h b/src/instructions.h index 60e843c..3b502a6 100644 --- a/src/instructions.h +++ b/src/instructions.h @@ -54,6 +54,7 @@ void push(); void call(); void and(); void xor(); +void end(); static const command_t command_map[] = { {.command = "add", .fptr = add}, @@ -75,6 +76,7 @@ static const command_t command_map[] = { {.command = "call", .fptr = call}, {.command = "and", .fptr = and}, {.command = "xor", .fptr = xor}, + {.command = "end", .fptr = end}, {.command = NULL, .fptr = NULL} }; diff --git a/src/main.c b/src/main.c index 47c1eaf..9e6bfa9 100644 --- a/src/main.c +++ b/src/main.c @@ -152,10 +152,7 @@ int main(int argc, char** argv) { } if (exit_code) { - free(args->arg1); - free(args->arg2); - free(args); - return 0; + break; } ++line_number;