From 71e2a4f4926d36a9595aad58b6fa7ef19c2bbfb9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 30 Aug 2020 17:06:59 +0200 Subject: asm-i386: fixed patchup of forward references (again) --- ecomp-c/asm-i386.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/ecomp-c/asm-i386.c b/ecomp-c/asm-i386.c index 584c631..6daae41 100644 --- a/ecomp-c/asm-i386.c +++ b/ecomp-c/asm-i386.c @@ -1686,12 +1686,29 @@ static int patchup_addresses( OpcodeInfo *opcode_info, int ORG ) int res = 0; while( opcode != NULL ) { + + /* replace illegal address (forward references) with the + * correct address */ + operand = opcode->operand; + while( operand != NULL ) { +/* if( operand->type == OPERAND_MEMORY_DIRECT || operand->type == OPERAND_MEMORY_INDIRECT ) { */ + if( operand->num == ADDRESS_UNDEFINED ) { + if( operand->node != NULL ) { + operand->num = evaluateExpression( operand->node, ORG, opcode->addr ); + } + } +/* } */ + operand = operand->next; + } /* set new increment of an instruction, if we have to * enhance the space occupied by the opcode */ switch( opcode->opcode ) { case OPCODE_JMP: + if( DEBUG_PARSER ) { + fprintf( stderr, "JMP at $%X to $%X\n", opcode->addr, opcode->operand->num ); + } if( opcode->addr != ADDRESS_UNDEFINED && opcode->operand->num != ADDRESS_UNDEFINED ) { int rel = relative_distance( opcode, opcode->addr, opcode->operand->num ); if( DEBUG_PARSER ) { @@ -1702,7 +1719,7 @@ static int patchup_addresses( OpcodeInfo *opcode_info, int ORG ) /* all fine, optimistic case already taken, short rel8 jump */ } else { if( DEBUG_PARSER ) { - fprintf( stderr, "Inreasing opcode of jump to 5 at $%X\n", opcode->addr ); + fprintf( stderr, "Increasing opcode of jump to 5 at $%X\n", opcode->addr ); } opcode->size = 5; res = 1; @@ -1739,19 +1756,6 @@ static int patchup_addresses( OpcodeInfo *opcode_info, int ORG ) break; } - /* replace illegal address (forward references) with the - * correct address */ - operand = opcode->operand; - while( operand != NULL ) { -/* if( operand->type == OPERAND_MEMORY_DIRECT || operand->type == OPERAND_MEMORY_INDIRECT ) { */ - if( operand->num == ADDRESS_UNDEFINED ) { - if( operand->node != NULL ) { - operand->num = evaluateExpression( operand->node, ORG, opcode->addr ); - } - } -/* } */ - operand = operand->next; - } opcode = opcode->next; } -- cgit v1.2.3-54-g00ecf