diff --git a/documentation/main_test.c b/documentation/main_test.c index 92eaf90..7ca8037 100644 --- a/documentation/main_test.c +++ b/documentation/main_test.c @@ -4,18 +4,29 @@ #include "../source/assembler.h" #include "../source/assembler.c" -#define COUNT (29+24) +#define COUNT (6 * 20) static unsigned int array [COUNT] = { - ADC, D64, REG, R1, REG, R2, - ADC, D32, REG, R1, MEM, 12, - ADC, D16, MEM, 12, REG, R10, - ADC, D8, REG, R3, IMM, 0X77, - INC, D16, REG, R0, LOCK, - CMOVG, D64, REG, R1, REG, R1, - CMOVG, D64, REG, R1, REG, R9, - CMOVG, D64, REG, R9, REG, R1, - CMOVG, D64, REG, R9, REG, R9 + ADD, D64, REG, R1, REG, R9, + ADD, D64, REG, R1, MEM, 0, + ADD, D64, REG, R1, IMM, 0X11223344U, + ADD, D64, MEM, 0, REG, R9, + ADD, D64, MEM, 0, IMM, 0X11223344U, + OR, D32, REG, R1, REG, R9, + OR, D32, REG, R1, MEM, 0, + OR, D32, REG, R1, IMM, 0X11223344U, + OR, D32, MEM, 0, REG, R9, + OR, D32, MEM, 0, IMM, 0X11223344U, + ADC, D16, REG, R1, REG, R9, + ADC, D16, REG, R1, MEM, 0, + ADC, D16, REG, R1, IMM, 0X11223344U, + ADC, D16, MEM, 0, REG, R9, + ADC, D16, MEM, 0, IMM, 0X11223344U, + SBB, D8, REG, R1, REG, R9, + SBB, D8, REG, R1, MEM, 0, + SBB, D8, REG, R1, IMM, 0X11223344U, + SBB, D8, MEM, 0, REG, R9, + SBB, D8, MEM, 0, IMM, 0X11223344U }; int main (void) { @@ -27,16 +38,10 @@ int main (void) { printf ("> %u\n", token_count); for (index = 0; index < token_count; ++index) { - printf ("%02X \n", token_array [index]); + printf ("%02X ", token_array [index]); } free (token_array); return (0); } -ADD, OR, ADC, SBB, AND, SUB, XOR, CMP, INC, DEC, NOT, NEG, UMUL, IMUL, UDIV, -IDIV, NOP, RETN, RETF, LEAVE, LOCK, HLT, SYSENTER, SYSEXIT, SYSCALL, SYSRET, -PAUSE, CPUID, ENTER, CALL, IN, OUT, JMP, JO, JNO, JB, JAE, JE, JNE, JBE, JA, -JS, JNS, JPE, JPO, JL, JGE, JLE, JG, MOV, CMOVO, CMOVNO, CMOVB, CMOVAE, CMOVE, -CMOVNE, CMOVBE, CMOVA, CMOVS, CMOVNS, CMOVPE, CMOVPO, CMOVL, CMOVGE, CMOVLE, -CMOVG diff --git a/documentation/test.asm b/documentation/test.asm index 2896a57..de0c3a1 100644 --- a/documentation/test.asm +++ b/documentation/test.asm @@ -7,63 +7,174 @@ entry $ nop nop - nop add rcx, r9 - nop add rcx, [x8] - nop - add rcx, 07fffffffh - nop + add rcx, 11223344h add [x8], rcx - nop - add qword[x8], 07fffffffh + add qword[x8], 11223344h + or ecx, r9d + or ecx, [x4] + or ecx, 11223344h + or [x4], ecx + or dword[x4], 11223344h + adc cx, r9w + adc cx, [x2] + adc cx, 1122h + adc [x2], cx + adc word[x2], 1122h + sbb cl, r9b + sbb cl, [x1] + sbb cl, 11h + sbb [x1], cl + sbb byte[x1], 11h + +; 4C 01 C9 48 03 0D E1 11 00 00 48 81 C1 44 33 22 11 48 01 0D D3 11 00 00 48 81 05 C8 11 00 00 44 33 22 11 44 09 C9 0B 0D BB 11 00 00 81 C9 44 33 22 11 09 0D AF 11 00 00 81 0D A5 11 00 00 44 33 22 11 66 44 11 C9 66 13 0D 98 11 00 00 66 81 D1 22 11 66 11 0D 8C 11 00 00 66 81 15 83 11 00 00 22 11 44 18 C9 1A 0D 79 11 00 00 80 D9 11 18 0D 70 11 00 00 80 1D 69 11 00 00 11 +; 4C 01 C9 48 03 0D FF FF FF FF 48 81 C2 44 33 4C 01 0D FF FF FF FF 48 81 05 FF FF FF FF 44 33 44 09 C9 0B 0D FF FF FF FF 81 CA 44 33 22 11 44 09 0D FF FF FF FF 81 0D FF FF FF FF 44 33 22 11 66 44 11 C9 66 13 0D FF FF FF FF 66 81 D2 44 33 66 44 11 0D FF FF FF FF 66 81 15 FF FF FF FF 44 33 44 18 C9 1A 0D FF FF FF FF 80 D9 44 44 18 0D FF FF FF FF 80 1C FF FF FF FF 44 nop nop nop - nop - add ecx, r9d - nop - add ecx, [x4] - nop - add ecx, 07fffffffh - nop - add [x4], ecx - nop - add dword[x4], 07fffffffh + xor rcx, r9 + xor rcx, [x8] + xor rcx, 11223344h + xor [x8], rcx + xor qword[x8], 11223344h + xor ecx, r9d + xor ecx, [x4] + xor ecx, 11223344h + xor [x4], ecx + xor dword[x4], 11223344h + xor cx, r9w + xor cx, [x2] + xor cx, 1122h + xor [x2], cx + xor word[x2], 1122h + xor cl, r9b + xor cl, [x1] + xor cl, 11h + xor [x1], cl + xor byte[x1], 11h nop nop nop - nop - add cx, r9w - nop - add cx, [x2] - nop - add cx, 07fffh - nop - add [x2], cx - nop - add word[x2], 07fffh + xor rcx, r9 + xor rcx, [x8] + xor rcx, 11223344h + xor [x8], rcx + xor qword[x8], 11223344h + xor ecx, r9d + xor ecx, [x4] + xor ecx, 11223344h + xor [x4], ecx + xor dword[x4], 11223344h + xor cx, r9w + xor cx, [x2] + xor cx, 1122h + xor [x2], cx + xor word[x2], 1122h + xor cl, r9b + xor cl, [x1] + xor cl, 11h + xor [x1], cl + xor byte[x1], 11h nop nop nop - nop - add cl, r9b - nop - add cl, [x1] - nop - add cl, 07fh - nop - add [x1], cl - nop - add byte[x1], 07fh + inc rcx + inc qword[x8] + inc ecx + inc dword[x4] + inc cx + inc word[x2] + inc cl + inc byte[x1] nop + nop + nop + + div r9 + div qword[x8] + div r9d + div dword[x4] + div r9w + div word[x2] + div r9b + div byte[x1] + + nop + nop + nop + + ret + leave + lock + hlt + + nop + nop + nop + + sysenter + sysexit + syscall + sysret + pause + cpuid + + ;~nop + ;~nop + ;~nop + + ;~jo fff + ;~jno fff + ;~jb fff + ;~jae fff + ;~je fff + ;~jne fff + ;~jbe fff + ;~ja fff + ;~js fff + ;~jns fff + ;~jpe fff + ;~jpo fff + ;~jl fff + ;~jge fff + ;~jle fff + ;~jg fff + + ;~nop + ;~nop + ;~nop + + ;~cmovo rax, rcx + ;~cmovno rax, rcx + ;~cmovb rax, rcx + ;~cmovae rax, rcx + ;~cmove rax, rcx + ;~cmovne rax, rcx + ;~cmovbe rax, rcx + ;~cmova rax, rcx + ;~cmovs rax, rcx + ;~cmovns rax, rcx + ;~cmovpe rax, rcx + ;~cmovpo rax, rcx + ;~cmovl rax, rcx + ;~cmovge rax, rcx + ;~cmovle rax, rcx + ;~cmovg rax, rcx + + nop + nop + nop + + ;mov + ;jmp nop nop diff --git a/source/assembler.c b/source/assembler.c index d7fcaa9..43048ce 100644 --- a/source/assembler.c +++ b/source/assembler.c @@ -54,9 +54,9 @@ static void place (form when, token_count += (next) when; } -static void print (form when, - form size, - next data) { +static void print (form when, + size_index size, + next data) { /* */ place ((when != 0) && (size >= D8), (byte) ((data >> 0) & 0XFF)); place ((when != 0) && (size >= D16), (byte) ((data >> 8) & 0XFF)); @@ -83,8 +83,8 @@ static void build_long_prefix (form use_big_registers, /* */ place (use_big_registers || use_new_destination || use_new_source, (byte) (0X40 - + 0X01 * use_new_source - + 0X04 * use_new_destination + + 0X01 * use_new_destination + + 0X04 * use_new_source + 0X08 * use_big_registers)); } @@ -237,7 +237,7 @@ static void build_jump (size_index size, type_index to, next destination) { /* */ - place ((to == REG) && upper (destination), (byte) 0X41); + place ((to == REG) && upper ((form) destination), (byte) 0X41); place (to == REL, (byte) (0XE9 + 0X02 * (size == D8))); place (to == REG, (byte) 0XFF); @@ -275,11 +275,11 @@ static void build_move (size_index size, place ((to == MEM) && (from == IMM), (byte) (0XC6 + (size != D8))); place ((to == MEM) && (from == IMM), (byte) (0X05)); - //~print ((to == REG) && (from == MEM), D32, (next) ~0); - //~print ((to == REG) && (from == IMM), size, source); - //~print ((to == MEM) && (from == REG), D32, (next) ~0); - //~print ((to == MEM) && (from == IMM), D32, (next) ~0); - //~print ((to == MEM) && (from == IMM), size, source); + print ((to == REG) && (from == MEM), D32, (next) ~0); + print ((to == REG) && (from == IMM), size, source); + print ((to == MEM) && (from == REG), D32, (next) ~0); + print ((to == MEM) && (from == IMM), D32, (next) ~0); + print ((to == MEM) && (from == IMM), size, source); } next token_count; @@ -322,13 +322,13 @@ void assemble (next count, array [index + 4], array [index + 5]); index += 5; } else if (array [index] == JMP) { - build_jump_if (array [index + 1], array [index + 2], - array [index + 3]); + build_jump (array [index + 1], array [index + 2], + array [index + 3]); index += 3; } else if (array [index] == MOV) { - build_move_if (array [index + 1], array [index + 2], - array [index + 3], array [index + 4], - array [index + 5]); + build_move (array [index + 1], array [index + 2], + array [index + 3], array [index + 4], + array [index + 5]); index += 5; } else { exit (EXIT_FAILURE); // For debugging only!