diff options
-rw-r--r-- | ecomp-c/asm-i386.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/ecomp-c/asm-i386.c b/ecomp-c/asm-i386.c index 6f599de..e1ecb2e 100644 --- a/ecomp-c/asm-i386.c +++ b/ecomp-c/asm-i386.c @@ -942,6 +942,21 @@ static Register getRegister( char *s ) return REGISTER_UNKNOWN; } +static int is32bitRegister( Register r ) +{ + switch( r ) { + case REGISTER_EAX: + case REGISTER_ECX: + case REGISTER_EDX: + case REGISTER_EBX: + return 1; + + case REGISTER_AL: + default: + return 0; + } +} + static void assign_label( OperandInfo *operand_info, char *label ) { Symbol *symbol; @@ -1609,12 +1624,20 @@ static void emit_opcode( OpcodeInfo *opcode_info ) break; case OPCODE_PUSH: if( opcode_info->operand->type == OPERAND_REGISTER ) { - Emit( "%c", 0x50 | opcode_info->operand->reg ); + if( is32bitRegister( opcode_info->operand->reg ) ) { + Emit( "%c", 0x50 | opcode_info->operand->reg ); + } else { + Abort( "Only 32-bit stack operations are possible" ); + } } break; case OPCODE_POP: if( opcode_info->operand->type == OPERAND_REGISTER ) { - Emit( "%c", 0x58 | opcode_info->operand->reg ); + if( is32bitRegister( opcode_info->operand->reg ) ) { + Emit( "%c", 0x58 | opcode_info->operand->reg ); + } else { + Abort( "Only 32-bit stack operations are possible" ); + } } break; case OPCODE_ADD: |