diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2020-03-29 19:41:18 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2020-03-29 19:41:18 +0200 |
commit | 1544c04dfeda290f59e3585b9e5bba526618da32 (patch) | |
tree | da0d9f56929e98a65ec2d8209c9953c7da12ea65 /ecomp-c/asm-i386.c | |
parent | 42e28d593ee56994e41e0f93b4e6c12ddf93ccb9 (diff) | |
download | compilertests-1544c04dfeda290f59e3585b9e5bba526618da32.tar.gz compilertests-1544c04dfeda290f59e3585b9e5bba526618da32.tar.bz2 |
filled out the rest of compare operations
Diffstat (limited to 'ecomp-c/asm-i386.c')
-rw-r--r-- | ecomp-c/asm-i386.c | 110 |
1 files changed, 98 insertions, 12 deletions
diff --git a/ecomp-c/asm-i386.c b/ecomp-c/asm-i386.c index b840e08..b455b17 100644 --- a/ecomp-c/asm-i386.c +++ b/ecomp-c/asm-i386.c @@ -17,6 +17,11 @@ * F7 F3 div ebx * 39 XX cmp r32, r32 * 74 XX je rel8 + * 75 XX jne rel8 + * 72 XX jb rel8 + * 76 XX jbe rel8 + * 77 XX ja rel8 + * 73 XX jae rel8 * EB XX jmp rel8 * F4 hlt * @@ -615,6 +620,11 @@ typedef enum { OPCODE_CMP, OPCODE_JMP, OPCODE_JE, + OPCODE_JNE, + OPCODE_JB, + OPCODE_JBE, + OPCODE_JA, + OPCODE_JAE, OPCODE_HLT, OPCODE_UNKNOWN } Opcode; @@ -631,6 +641,11 @@ static char *opcodename[OPCODE_UNKNOWN+1] = { "cmp", "jmp", "je", + "jne", + "jb", + "jbe", + "ja", + "jae", "hlt", "<unknown>" }; @@ -722,15 +737,51 @@ static OpcodeInfo *parseOpcode( void ) } break; case 'j': - if( strcmp( ident, "jmp" ) == 0 ) { - opcode_info->opcode = OPCODE_JMP; - opcode_info->nof_operands = 1; - /* TODO: how to handle variable size patchup of jumps? */ - opcode_info->incr = 2; - } else if( strcmp( ident, "je" ) == 0 ) { - opcode_info->opcode = OPCODE_JE; - opcode_info->nof_operands = 1; - opcode_info->incr = 2; + switch( ident[1] ) { + case 'm': + if( strcmp( ident, "jmp" ) == 0 ) { + opcode_info->opcode = OPCODE_JMP; + opcode_info->nof_operands = 1; + /* TODO: how to handle variable size patchup of jumps? */ + opcode_info->incr = 2; + } + break; + case 'e': + if( strcmp( ident, "je" ) == 0 ) { + opcode_info->opcode = OPCODE_JE; + opcode_info->nof_operands = 1; + opcode_info->incr = 2; + } + break; + case 'n': + if( strcmp( ident, "jne" ) == 0 ) { + opcode_info->opcode = OPCODE_JNE; + opcode_info->nof_operands = 1; + opcode_info->incr = 2; + } + break; + case 'b': + if( strcmp( ident, "jb" ) == 0 ) { + opcode_info->opcode = OPCODE_JB; + opcode_info->nof_operands = 1; + opcode_info->incr = 2; + } else if( strcmp( ident, "jbe" ) == 0 ) { + opcode_info->opcode = OPCODE_JBE; + opcode_info->nof_operands = 1; + opcode_info->incr = 2; + } + break; + case 'a': + if( strcmp( ident, "ja" ) == 0 ) { + opcode_info->opcode = OPCODE_JA; + opcode_info->nof_operands = 1; + opcode_info->incr = 2; + } else if( strcmp( ident, "jae" ) == 0 ) { + opcode_info->opcode = OPCODE_JAE; + opcode_info->nof_operands = 1; + opcode_info->incr = 2; + } + break; } break; case 'm': @@ -1152,6 +1203,13 @@ static void emit_opcode( OpcodeInfo *opcode_info ) Abort( "Unsupported sub addressing mode" ); } break; + case OPCODE_JMP: + if( opcode_info->operand->type == OPERAND_MEMORY_DIRECT ) { + Emit( "%c%c", 0xEB, relative_distance( opcode_info, opcode_info->addr, opcode_info->operand->addr ) ); + } else { + Abort( "jmp expects a jump label" ); + } + break; case OPCODE_JE: if( opcode_info->operand->type == OPERAND_MEMORY_DIRECT ) { Emit( "%c%c", 0x74, relative_distance( opcode_info, opcode_info->addr, opcode_info->operand->addr ) ); @@ -1159,11 +1217,39 @@ static void emit_opcode( OpcodeInfo *opcode_info ) Abort( "je expects a jump label" ); } break; - case OPCODE_JMP: + case OPCODE_JNE: if( opcode_info->operand->type == OPERAND_MEMORY_DIRECT ) { - Emit( "%c%c", 0xEB, relative_distance( opcode_info, opcode_info->addr, opcode_info->operand->addr ) ); + Emit( "%c%c", 0x75, relative_distance( opcode_info, opcode_info->addr, opcode_info->operand->addr ) ); } else { - Abort( "jmp expects a jump label" ); + Abort( "jne expects a jump label" ); + } + break; + case OPCODE_JB: + if( opcode_info->operand->type == OPERAND_MEMORY_DIRECT ) { + Emit( "%c%c", 0x72, relative_distance( opcode_info, opcode_info->addr, opcode_info->operand->addr ) ); + } else { + Abort( "jne expects a jump label" ); + } + break; + case OPCODE_JBE: + if( opcode_info->operand->type == OPERAND_MEMORY_DIRECT ) { + Emit( "%c%c", 0x76, relative_distance( opcode_info, opcode_info->addr, opcode_info->operand->addr ) ); + } else { + Abort( "jne expects a jump label" ); + } + break; + case OPCODE_JA: + if( opcode_info->operand->type == OPERAND_MEMORY_DIRECT ) { + Emit( "%c%c", 0x77, relative_distance( opcode_info, opcode_info->addr, opcode_info->operand->addr ) ); + } else { + Abort( "ja expects a jump label" ); + } + break; + case OPCODE_JAE: + if( opcode_info->operand->type == OPERAND_MEMORY_DIRECT ) { + Emit( "%c%c", 0x73, relative_distance( opcode_info, opcode_info->addr, opcode_info->operand->addr ) ); + } else { + Abort( "jae expects a jump label" ); } break; default: |