New assembler stuff...
This commit is contained in:
@ -9,69 +9,114 @@ static void byte_push (byte data) {
|
|||||||
byte_count += 1;
|
byte_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static form lower (form data) { return ((data >= 0) && (data <= 7)); }
|
static inline form valid (form data) { return ((data => 0) && (data <= 15)); }
|
||||||
static form upper (form data) { return ((data >= 8) && (data <= 15)); }
|
static inline form lower (form data) { return ((data => 0) && (data <= 7)); }
|
||||||
|
static inline form upper (form data) { return ((data => 8) && (data <= 15)); }
|
||||||
|
|
||||||
static void format_prefix (size_index size,
|
//~static inline void format_prefix (size_index size,
|
||||||
type_index type,
|
//~type_index destination,
|
||||||
form destination,
|
//~type_index source) {
|
||||||
form source) {
|
//~if (size == SIZE_16B) {
|
||||||
byte format = 0X00;
|
//~byte_push (0X66);
|
||||||
|
//~} else if (size == SIZE_64B) {
|
||||||
|
//~byte format = 0X48;
|
||||||
|
//~if (destination == TYPE_REGISTER) {
|
||||||
|
//~format += upper (destination) * 0X01;
|
||||||
|
//~}
|
||||||
|
//~if (source == TYPE_REGISTER) {
|
||||||
|
//~format += upper (source) * 0X04;
|
||||||
|
//~}
|
||||||
|
//~byte_push (format);
|
||||||
|
//~} else {
|
||||||
|
//~return;
|
||||||
|
//~}
|
||||||
|
//~}
|
||||||
|
|
||||||
if (size == size_16b) byte_push (0X66);
|
//~static inline void format_rex_prefix (size_index size,
|
||||||
|
//~type_index destination,
|
||||||
|
//~type_index source) {
|
||||||
|
//~byte format = 0X40;
|
||||||
|
|
||||||
if (size == size_64b) format += 0X48;
|
//~byte_push (format);
|
||||||
if (size == size_32b) format += 0X48;
|
//~}
|
||||||
if (size == size_64b) format += 0X48;
|
|
||||||
if (size == size_64b) format += 0X48;
|
|
||||||
|
|
||||||
if (upper (destination)) format += 0X01;
|
static inline void format_register_direction (size_index size,
|
||||||
if (upper (source)) format += 0X04;
|
form to,
|
||||||
|
form from) {
|
||||||
|
byte format = 0XC0;
|
||||||
|
|
||||||
|
error (valid (to), "Invalid destination register index.");
|
||||||
|
error (valid (from), "Invalid source register index.");
|
||||||
|
|
||||||
|
format += 1 * (to % 8);
|
||||||
|
format += 8 * (from % 8);
|
||||||
|
|
||||||
byte_push (format);
|
byte_push (format);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void format_operation (size_index size,
|
static inline void format_register_indirection (size_index size,
|
||||||
type_index type,
|
form to) {
|
||||||
form destination,
|
byte format = 0XF0;
|
||||||
form source) {
|
|
||||||
byte format = 0X00;
|
|
||||||
|
|
||||||
switch (type) {
|
error (valid (to), "Invalid destination register index.");
|
||||||
case type_register_register: format += 0X30; break;
|
|
||||||
case type_register_variable: format += 0X32; break;
|
|
||||||
case type_register_constant: format += 0X80; break;
|
|
||||||
case type_variable_register: format += 0X30; break;
|
|
||||||
case type_variable_constant: format += 0X80; break;
|
|
||||||
default: exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size != size_8b) format += 0X01;
|
format += to % 8;
|
||||||
|
|
||||||
if (type == type_register_constant) format -= (destination == 0) * 0X3A;
|
|
||||||
|
|
||||||
byte_push (format);
|
byte_push (format);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void format_modifier (size_index size,
|
static inline void format_register_redirection (size_index size,
|
||||||
type_index type,
|
form direction) {
|
||||||
form destination,
|
byte format = 0X05;
|
||||||
form source) {
|
|
||||||
byte format = 0X00;
|
error (valid (direction), "Invalid direction register index.");
|
||||||
|
|
||||||
|
format += 8 * (direction % 8);
|
||||||
|
|
||||||
byte_push (format);
|
byte_push (format);
|
||||||
}
|
}
|
||||||
|
|
||||||
void assemble_xor (size_index size,
|
//~static inline void format_operation (size_index size,
|
||||||
type_index type,
|
//~type_index type,
|
||||||
form destination,
|
//~form destination,
|
||||||
form source) {
|
//~form source) {
|
||||||
if (size == size_256b) exit (EXIT_FAILURE);
|
//~byte format = 0X00;
|
||||||
if (size == size_128b) exit (EXIT_FAILURE);
|
|
||||||
|
|
||||||
format_prefix (size, type, destination, source);
|
//~switch (type) {
|
||||||
format_operation (size, type, destination, source);
|
//~case type_register_register: format += 0X30; break;
|
||||||
format_modifier (size, type, destination, source);
|
//~case type_register_variable: format += 0X32; break;
|
||||||
|
//~case type_register_constant: format += 0X80; break;
|
||||||
|
//~case type_variable_register: format += 0X30; break;
|
||||||
|
//~case type_variable_constant: format += 0X80; break;
|
||||||
|
//~default: exit (EXIT_FAILURE);
|
||||||
|
//~}
|
||||||
|
|
||||||
// ...
|
//~if (size != size_8b) format += 0X01;
|
||||||
}
|
|
||||||
|
//~if (type == type_register_constant) format -= (destination == 0) * 0X3A;
|
||||||
|
|
||||||
|
//~byte_push (format);
|
||||||
|
//~}
|
||||||
|
|
||||||
|
//~static inline void format_modifier (size_index size,
|
||||||
|
//~type_index type,
|
||||||
|
//~form destination,
|
||||||
|
//~form source) {
|
||||||
|
//~byte format = 0X00;
|
||||||
|
|
||||||
|
//~byte_push (format);
|
||||||
|
//~}
|
||||||
|
|
||||||
|
//~static void assemble_xor (size_index size,
|
||||||
|
//~type_index type,
|
||||||
|
//~form destination,
|
||||||
|
//~form source) {
|
||||||
|
//~if (size == size_256b) exit (EXIT_FAILURE);
|
||||||
|
//~if (size == size_128b) exit (EXIT_FAILURE);
|
||||||
|
|
||||||
|
//~format_prefix (size, type, destination, source);
|
||||||
|
//~format_operation (size, type, destination, source);
|
||||||
|
//~format_modifier (size, type, destination, source);
|
||||||
|
|
||||||
|
//~// ...
|
||||||
|
//~}
|
||||||
|
@ -4,73 +4,38 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
size_256b, size_128b, size_64b,
|
SIZE_256B, SIZE_128B, SIZE_64B,
|
||||||
size_32b, size_16b, size_8b,
|
SIZE_32B, SIZE_16B, SIZE_8B,
|
||||||
} size_index;
|
} size_index;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
type_register_register, type_register_variable, type_register_constant,
|
TYPE_REGISTER, TYPE_VARIABLE, TYPE_CONSTANT,
|
||||||
type_variable_register, type_variable_constant,
|
|
||||||
} type_index;
|
} type_index;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
operation_move, operation_add, operation_subtract,
|
OPERATION_MOVE, OPERATION_ADD, OPERATION_SUBTRACT,
|
||||||
operation_multiply, operation_divide, operation_modulus,
|
OPERATION_MULTIPLY, OPERATION_DIVIDE, OPERATION_MODULUS,
|
||||||
operation_compare, operation_jump, operation_xor,
|
OPERATION_COMPARE, OPERATION_JUMP, OPERATION_XOR,
|
||||||
operation_and, operation_or, operation_not,
|
OPERATION_AND, OPERATION_OR, OPERATION_NOT,
|
||||||
operation_is, operation_above, operation_below,
|
OPERATION_IS, OPERATION_ABOVE, OPERATION_BELOW,
|
||||||
operation_if, operation_increment, operation_decrement,
|
OPERATION_IF, OPERATION_INCREMENT, OPERATION_DECREMENT,
|
||||||
operation_system, operation_call, operation_return,
|
OPERATION_SYSTEM, OPERATION_CALL, OPERATION_RETURN,
|
||||||
operation_enter, operation_leave, operation_exit,
|
OPERATION_ENTER, OPERATION_LEAVE, OPERATION_EXIT,
|
||||||
} operation_index;
|
} operation_index;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
operand_rax, operand_rcx, operand_rdx,
|
OPERAND_REGISTER_0, OPERAND_REGISTER_1, OPERAND_REGISTER_2,
|
||||||
operand_rbx, operand_rsi, operand_rdi,
|
OPERAND_REGISTER_3, OPERAND_REGISTER_4, OPERAND_REGISTER_5,
|
||||||
operand_rsp, operand_rbp, operand_r8,
|
OPERAND_REGISTER_6, OPERAND_REGISTER_7, OPERAND_REGISTER_8,
|
||||||
operand_r9, operand_r10, operand_r11,
|
OPERAND_REGISTER_9, OPERAND_REGISTER_A, OPERAND_REGISTER_B,
|
||||||
operand_r12, operand_r13, operand_r14,
|
OPERAND_REGISTER_C, OPERAND_REGISTER_D, OPERAND_REGISTER_E,
|
||||||
operand_r15,
|
OPERAND_REGISTER_F, OPERAND_REFERENCE, OPERAND_DEREFERENCE,
|
||||||
} operand_64b_index;
|
} operand_index;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
operand_eax, operand_ecx, operand_edx,
|
|
||||||
operand_ebx, operand_esi, operand_edi,
|
|
||||||
operand_esp, operand_ebp, operand_r8d,
|
|
||||||
operand_r9d, operand_r10d, operand_r11d,
|
|
||||||
operand_r12d, operand_r13d, operand_r14d,
|
|
||||||
operand_r15d,
|
|
||||||
} operand_32b_index;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
operand_ax, operand_cx, operand_dx,
|
|
||||||
operand_bx, operand_si, operand_di,
|
|
||||||
operand_sp, operand_bp, operand_r8w,
|
|
||||||
operand_r9w, operand_r10w, operand_r11w,
|
|
||||||
operand_r12w, operand_r13w, operand_r14w,
|
|
||||||
operand_r15w,
|
|
||||||
} operand_16b_index;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
operand_al, operand_cl, operand_dl,
|
|
||||||
operand_bl, operand_sil, operand_dil,
|
|
||||||
operand_spl, operand_bpl, operand_r8b,
|
|
||||||
operand_r9b, operand_r10b, operand_r11b,
|
|
||||||
operand_r12b, operand_r13b, operand_r14b,
|
|
||||||
operand_r15b,
|
|
||||||
} operand_8b_index;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
command_operation, command_size, command_operand_d,
|
|
||||||
command_operand_s,
|
|
||||||
command_length,
|
|
||||||
} command_index;
|
|
||||||
|
|
||||||
typedef signed int form;
|
typedef signed int form;
|
||||||
typedef unsigned int next;
|
typedef unsigned int next;
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
|
|
||||||
|
// size, operation, type, operand/form, type, operand/form
|
||||||
void assemble_xor (size_index size, type_index type, form destination, form source);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user