flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > small Bug : "code can't be generated"

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 19 Jun 2010, 11:13
Code:
A)
jecxz glop ; <-------------- i like "glop" Smile
db 127 dup 0
glop:

B)
jecxz glop
db 128 dup 0
glop:

C)
jecxz glop
db 129 dup 0
glop:

D)
jecxz glop
db 130 dup 0 ;130,131,132 ....
glop:

;------------------------------------
ASSEMBLE.INC
.....
next_pass:
  inc     [current_pass]
      mov     ax,[current_pass]
   cmp     ax,[passes_limit]   ;<--------------- (*)
        je      code_cannot_be_generated
    jmp     assembler_loop
assemble_ok:
  ret
.....
    


A)
compiler works fine.
"jecxz" = from -128 to +127
compilation ok, no problem.
[passes_limit] = 1 (*)

D)
compiler works fine.
message : relative jump out of range (3 bytes)
no problem.
[passes_limit] = 2 (*)

B) and C)
problem !
message :
not "relative jump out of range"
but "code cannot be generated" !
[passes_limit]= 64 ! (*)

Only with positive values "+128" and "+129", the compiler doesn't seem to find the right solution.

Of course, the correct output with "+128" and "+129" is :
"relative jump out of range" ... like +130 ... and like the following values. (+131,+132 ...)
With values greater than or equal to "+130" there is no problem.
But (only)with +128 and +129, Fasm uses 64 passes and didn't find the exit.


_________________
I am not young enough to know everything (Oscar Wilde)- Image


Last edited by ouadji on 19 Jun 2010, 18:57; edited 2 times in total
Post 19 Jun 2010, 11:13
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 19 Jun 2010, 15:50
ouadji,

This is a small logical glitch in jcxz / loop handling code. It appears in case of forward reference (obviously).

On pass 0 forward-referenced glop symbol has no predicted value, thus FASM let it go.
On pass 1 glop symbol is predicted to be 128 or 129 (while it should be predicted as 130 / 131: instruction takes 2 bytes), reachable by jecxz from 0+2; later on this pass glop is defined as 130 / 131 due to compiled jecxz instruction… and the story begins again (on the next pass destination is unreachable, glop is defined as 128 / 129 and so on). Wink

The patch is simple:
Code:
      make_loop_jump:
    call    check_for_short_jump
        jc      conditional_jump_short
;+++ X86_64.INC [3292]: correct occasional "code cannot be generated" on marginal forward jcxz/loop
 stos    word [edi]
;===
  jmp     jump_out_of_range
      loop_counter_size:    
Post 19 Jun 2010, 15:50
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 19 Jun 2010, 18:35

ok Razz
Code:
X86_64.INC [3292]
stos    word [edi]  ; +++
    
I clearly understood from where this problem comes.
Thank you very much for your explanations.
Thank you also for the "patch". It works very well.
With this additional line of code, there is no problem.
This makes fasm's operations more logical.
It also simplifies my code to display the number of bytes exceeded.

It's amazing ...
your knowledge of how FASM works,
and your knowledge of its internal code.
Have you taken part in the development of FASM ??

again, thank you baldr. Wink

it would be nice to include this fix in the next version

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 19 Jun 2010, 18:35
View user's profile Send private message Send e-mail Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Jun 2010, 18:50
Quote:


it would be nice to include this fix in the next version

For that reason don't mark your thread as "(solved)" because you will make Tomasz unstick it without looking at it. Smile
Post 19 Jun 2010, 18:50
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.