From f0d11f5dfad5dc19d5a274024933bb4c998d38a9 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 13 Jun 2020 15:02:43 -0400 Subject: Made the source code cleaner. --- asmmon.h | 1 + assemble.c | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/asmmon.h b/asmmon.h index 213c9b5..39e2d19 100644 --- a/asmmon.h +++ b/asmmon.h @@ -3,6 +3,7 @@ #include #define MAX_TOK 0x1000 +#define TXS_MNE_ID 78 /* Used for a special case in the assembler. */ typedef struct tok token ; typedef struct ln line ; diff --git a/assemble.c b/assemble.c index 6397173..990ca96 100644 --- a/assemble.c +++ b/assemble.c @@ -75,18 +75,17 @@ uint64_t get_val(token *t, uint64_t addr, uint8_t size, uint8_t dbg) { return value; } -uint8_t get_dirsize(uint8_t type, uint8_t dbg) { - uint8_t size = 0; +uint8_t get_directivesize(uint8_t type, uint8_t dbg) { switch (type) { - case DIR_QWORD: size = 3; break; - case DIR_DWORD: size = 2; break; - case DIR_WORD : size = 1; break; - case DIR_BYTE : size = 0; break; + case DIR_QWORD: return 3; + case DIR_DWORD: return 2; + case DIR_WORD : return 1; + case DIR_BYTE : return 0; } - return size; + return 0; } -uint64_t handle_dir(token *t, bytecount *bc, uint8_t isasm, uint64_t address, uint8_t dbg) { +uint64_t handle_directive(token *t, bytecount *bc, uint8_t isasm, uint64_t address, uint8_t dbg) { union reg val; uint8_t c = 0; uint8_t tmp = 0; @@ -102,9 +101,9 @@ uint64_t handle_dir(token *t, bytecount *bc, uint8_t isasm, uint64_t address, ui case TOK_CHAR: case TOK_SYM: case TOK_LABEL: - val.u64 = get_val(t, tmpaddr, get_dirsize(type, dbg), dbg); + val.u64 = get_val(t, tmpaddr, get_directivesize(type, dbg), dbg); switch (type) { - case DIR_QWORD: + case DIR_QWORD: /* Falls through. */ if (isasm) { addr[tmpaddr+7] = val.u8[7]; addr[tmpaddr+6] = val.u8[6]; @@ -112,13 +111,13 @@ uint64_t handle_dir(token *t, bytecount *bc, uint8_t isasm, uint64_t address, ui addr[tmpaddr+4] = val.u8[4]; } tmp += 4; - case DIR_DWORD: + case DIR_DWORD: /* Falls through. */ if (isasm) { addr[tmpaddr+3] = val.u8[3]; addr[tmpaddr+2] = val.u8[2]; } tmp += 2; - case DIR_WORD: + case DIR_WORD: /* Falls through. */ if (isasm) { addr[tmpaddr+1] = val.u8[1]; } @@ -203,7 +202,8 @@ uint64_t handle_opcode(token *t, bytecount *bc, uint8_t isasm, uint64_t address, val.u64 = get_val(t, address, (rs != 0xFF) ? rs : 0, dbg); } opcode = opcodes[inst][type]; - if (inst == 78) { + /* Special case for TXS. */ + if (inst == TXS_MNE_ID) { if (type == IMM) { rs = 1; } else { @@ -325,7 +325,7 @@ uint64_t parse_tokens(token *t, bytecount *bc, uint8_t isasm, uint64_t address, case DIR_BYTE: case DIR_WORD: case DIR_DWORD: - case DIR_QWORD: address = handle_dir(t, bc, isasm, address, dbg); break; + case DIR_QWORD: address = handle_directive(t, bc, isasm, address, dbg); break; } break; case TOK_OPCODE: address = handle_opcode(t, bc, isasm, address, dbg); break; -- cgit v1.2.3-13-gbd6f