flat assembler
Message board for the users of flat assembler.

flat assembler > Compiler Internals > jecxz "jump out of range" --> first solution

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium

jecxz : relative jump out of range.

sorry for my english, i will try to do my best.

It would be very interesting to also display the number of bytes exceeded.
This would allow to know if it's worth trying to optimize the code ... or not.
Indeed, if the excess is only a few bytes,
it's maybe possible to optimize the code so that the limits are no longer exceeded.
or ... if the number of bytes beyond the limits is too large,
it indicates that a simple optimization isn't enough to eliminate the problem.


jecxz : relative jump out of range (8bytes)

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


Last edited by ouadji on 19 Jun 2010, 12:03; edited 2 times in total
Post 02 Apr 2010, 22:41
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16733
Location: In your JS exploiting you and your system
This can jump up to +-2GB.
Code:
test ecx,ecx
jz Somewhere    
If you need to jump further than that then you are probably doing something wrong. Wink
Post 03 Apr 2010, 03:25
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 688
Location: Adelaide
If you need to optimize, using jecxz (and loop) are much slower than a test/jump (or a dec/jnz).
Post 03 Apr 2010, 03:34
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
On AMD, JECXZ has a two cycles latency and it is a DirectPath instruction. Maybe JECXZ is not always as fast as TEST/J(N)Z is, but still, there may be situations in which you don't want to destroy the flags to find out ECX's current status.
Post 03 Apr 2010, 04:01
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tomasz uses loop in "convert_line" in preproce.inc
Code:
...
  mov     ebx,characters
        xor     ecx,ecx
      convert_symbol:
        lods    byte [esi]
        stos    byte [edi]
        xlat    byte [ebx]
        or      al,al
        loopnzd convert_symbol
        neg     ecx
        cmp     ecx,255         
...
    
Post 03 Apr 2010, 04:48
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 688
Location: Adelaide
>Tomasz uses loop in "convert_line" in preproce.inc
Also uses xlat...

Just an observation, not a hard-and-fast rule, since it depends on the cpu.
P4 is good with dec and bad with loop and jcxz. P3 is slower with dec.
Post 03 Apr 2010, 04:52
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
revolution wrote:
This can jump up to +-2GB.
Code:
test ecx,ecx
jz Somewhere    
If you need to jump further than that then you are probably doing something wrong. Wink

thank you revolution ... I didn't know that !
sorry, but i'm a beginner in asm. Laughing Laughing
Quote:
there may be situations in which you don't want to destroy the flags
good answer Wink

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


Last edited by ouadji on 03 Apr 2010, 06:43; edited 1 time in total
Post 03 Apr 2010, 06:35
View user's profile Send private message Send e-mail Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
sinsi wrote:
>Tomasz uses loop in "convert_line" in preproce.inc
Also uses xlat...


Also the slow string instructions (lodsb, stosb). Wasn't he writing on a real 386 at one time back in the day?? I'm sure it's smarter to target slow processors that need the extra speed than fast processors that already have it. Wink
Post 03 Apr 2010, 06:40
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 688
Location: Adelaide
rugxulo, no argument here, although I haven't programmed recently on less then a P3.
I just latched onto the 'optimize' in the OP. Go to the MASM32 forum and look at all the optimization that goes on there... Rolling Eyes
Post 03 Apr 2010, 07:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16733
Location: In your JS exploiting you and your system
The word "optimise" is so ambiguous. It can mean many things. Optimising for what? Speed? Size? Ease of coding? Ease of reading? Which platform? Which CPU? Under what usage conditions? Hehe, optimise is a dirty word!
Post 03 Apr 2010, 08:47
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium

no, "optimise" isn't a dirty word.
No matter why we search a optimization,
speed, size, ease of coding, ease of reading ...
it depends on the coding spirit of each developper
everyone has his own choice
but "car" is a dirty word .. bus, truck, van ? Wink

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 03 Apr 2010, 10:38
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16733
Location: In your JS exploiting you and your system
Please help me to optimise my code:
Code:
;pretend there is some code here    
Okay, so what did I ask for there? No one can possibly know without further information.
Post 03 Apr 2010, 11:18
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 754
Location: Massachusetts, USA
I help you optimize it for size and readability and speed and everything else...
Code:
    

Hehe Smile
Post 03 Apr 2010, 11:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16733
Location: In your JS exploiting you and your system
Wow, it compiled nicely. Thanks bitshifter.
Quote:
flat assembler version 1.69.12 (152449 kilobytes memory)
1 passes, 0 bytes.
Post 03 Apr 2010, 11:29
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
sinsi wrote:
P4 is good with dec

P4 is bad in pretty much everything including DEC, you must use "SUB reg/mem, 1" instead.

Agner Fog wrote:
16.2 INC and DEC (all Intel processors)

The INC and DEC instructions do not modify the carry flag but they do modify the other
arithmetic flags. Writing to only part of the flags register costs an extra µop on P4 and P4E.
It can cause a partial flags stalls on other Intel processors if a subsequent instruction reads
the carry flag or all the flag bits. On all processors, it can cause a false dependence on the
carry flag from a previous instruction.

Use ADD and SUB when optimizing for speed. Use INC and DEC when optimizing for size or
when no penalty is expected.
The part marked in bold I'm not sure if it is really correct.
Post 03 Apr 2010, 16:20
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium

LocoDelAssembly,
I don't quite understand, tell you about this?
Code:

mov eax,7
mov ebx,5
x_:
sub eax,1
dec ebx
jc somewhere
jmp x_

    


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 04 Apr 2010, 08:04
View user's profile Send private message Send e-mail Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
yes, in this case jump will be taken if CF was set by SUB EAX, 1
Post 04 Apr 2010, 10:19
View user's profile Send private message Reply with quote
SeproMan



Joined: 11 Oct 2009
Posts: 54
Location: Belgium
I find the original suggestion by Ouadji a very useful one.
In fact I've incorporated it just a few days ago into my own assembler language project by showing an error message like "Target out of reach by 2 bytes"

Thanks Ouadji


In FASM "jz Somewhere" has a range of +-2GB. This is not intuitive.
I advocate a more WYSIWYG approach
jz Somewhere ;[-128,127]
jzw Somewhere ;[-32768,32767]
jzd Somewhere ;[-2GB,2GB-1]

_________________
Real Address Mode.
Post 10 Apr 2010, 14:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16733
Location: In your JS exploiting you and your system
in fasm syntax:

jz byte Somewhere ;[-128,127] [edit] byte doesn't compile. What is the byte override?
jz word Somewhere ;[-32768,32767]
jz dword Somewhere ;[-2GB,2GB-1]

The size override forces it to a particular length.
Post 10 Apr 2010, 14:02
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7318
Location: Kraków, Poland
Actually, this is not the fasm syntax. The fasm syntax is:
Code:
jz short word Somewhere ; [-128;127], EIP masked with 0FFFFh
jz short dword Somewhere ; [-128;127]
jz near word Somewhere ; [-32768,32767], EIP masked with 0FFFFh
jz near dword Somewhere ; [-2GB,2GB-1]    
Post 10 Apr 2010, 14:08
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2019, Tomasz Grysztar.

Powered by rwasa.