diff options
| author | onelin <oscar@nelin.dk> | 2026-11-19 21:54:02 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2026-11-19 21:54:02 +0000 |
| commit | 692c1521ced0f113e85f0d67cead896893852093 (patch) | |
| tree | e9a07e11f7271188a0c1c9fa325dc68d392c0ffe | |
| parent | c38941afde2b398bf6b6ed040d8248a7570c1450 (diff) | |
Add more elaborate add/mov exit example
| -rw-r--r-- | .clang-format | 7 | ||||
| -rw-r--r-- | main.c | 28 |
2 files changed, 30 insertions, 5 deletions
diff --git a/.clang-format b/.clang-format index 04e3364..a3680a7 100644 --- a/.clang-format +++ b/.clang-format @@ -82,8 +82,11 @@ BraceWrapping: SplitEmptyNamespace: true BreakAdjacentStringLiterals: true BreakAfterAttributes: Leave -BreakAfterJavaFieldAnnotations: false -BreakArrays: true + +BreakArrays: true +BreakAfterOpenBracketBracedList: true +BreakBeforeCloseBracketBracedList: true + BreakBeforeBinaryOperators: None BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach @@ -1,17 +1,39 @@ #include "instructions.h" #include "registers.h" #include "write_elf.c" +#include <sys/syscall.h> + +static const unsigned char exit_2[] = { + // Exit syscall + MOVWI(REG_EAX, SYS_exit), + // Exit code + MOVWI(REG_EDI, 0x02), SYSCALL +}; static const unsigned char some_opcodes[] = { - MOVWI(REG_EAX, (long)0x41), MOVQ(REG_EAX, REG_EDI), - MOVDI(REG_EAX, (long)0x3c), SYSCALL}; + // rbx 00000001 + MOVDI(REG_EBX, 0x1), + // rcx 00000002 + MOVBI(REG_CL, 0x2), + // rcx 00000003 + ADDB(REG_BL, REG_CL), + // rcx 00000004 + ADDW(REG_BX, REG_CX), + // rcx 00000005 + ADDD(REG_EBX, REG_ECX), + // rcx 00000006 + ADDQ(REG_EBX, REG_ECX), + // rdi 00000006 + MOVD(REG_ECX, REG_EDI), + // Exit syscall + MOVWI(REG_EAX, SYS_exit), SYSCALL +}; static const unsigned int some_opcodes_len = sizeof(some_opcodes) / sizeof(some_opcodes[0]); int main(int argc, char* argv[]) { - char opcodes[] = {}; write_elf("test.out", some_opcodes_len, (char*)some_opcodes); return 0; } |
