diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2020-06-20 18:53:25 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2020-06-20 18:53:25 +0200 |
commit | e65aa4b6f359327c142d099328c23197857593ac (patch) | |
tree | 658c81b07234df6e5549289a6541cc7ef5cbe49c | |
parent | 54c57c5de0ae74914fa0676728ba49d0ed46ba14 (diff) | |
download | compilertests-e65aa4b6f359327c142d099328c23197857593ac.tar.gz compilertests-e65aa4b6f359327c142d099328c23197857593ac.tar.bz2 |
asm-i386: added checks for 32-bit stack pushes
-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: |