From eac867607d2363de6a68b9d51cb6abd496cce51d Mon Sep 17 00:00:00 2001 From: xolatile Date: Mon, 1 Jul 2024 22:54:37 -0400 Subject: [PATCH] Formatting of regular insstructions... --- source/assembler.c | 41 ++++++++++++++++++++++++++++++++++++----- source/assembler.h | 11 +++++++---- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/source/assembler.c b/source/assembler.c index 7e65a74..5659564 100644 --- a/source/assembler.c +++ b/source/assembler.c @@ -1,12 +1,43 @@ #include "assembler.h" +static void byte_push (byte data) { + byte_array [byte_count] = data; + + byte_count += 1; +} + static void assemble_xor (size_index size, type_index type, - size_t destination, - size_t source) { - // ERROR CHECKING + form destination, + form source) { + byte set = 0; + byte mod = 0; - // byte_array [byte_count] = ...; + if (size == size_256b) exit (EXIT_FAILURE); + if (size == size_128b) exit (EXIT_FAILURE); - // byte_count += ...; + if (size == size_64b) byte_push (0X48); + + switch (type) { + case type_register_register: set += 0X30; break; + case type_register_variable: set += 0X32; break; + case type_register_constant: set += 0X80; break; + case type_variable_register: set += 0X30; break; + case type_variable_constant: set += 0X80; break; + default: exit (EXIT_FAILURE); + } + + if (size != size_8b) set += 1; + + if ((type == type_register_constant) && (destination == 0)) set += 4; + + byte_push (set); + + // FORMAT MOD/SIB BYTE IF NEEDED... + + byte_push (mod); + + // FORMAT MEMORY OR IMMEDIATE IF NEEDED... + + // ... } diff --git a/source/assembler.h b/source/assembler.h index 0244d23..a54aa87 100644 --- a/source/assembler.h +++ b/source/assembler.h @@ -66,15 +66,18 @@ typedef enum { command_length } command_index; -typedef unsigned int data; +typedef signed int form; +typedef unsigned int next; typedef unsigned char byte; -static data byte_count = 0; +static next byte_count = 0; static byte * byte_array = NULL; +static void byte_push (byte data); + static void assemble_xor (size_index size, type_index type, - size_t destination, - size_t source); + form destination, + form source); #endif