flat assembler
Message board for the users of flat assembler.

Index > Main > jcxz and JECXZ error

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1819
Roman 08 Jan 2021, 19:53
I try compile in 64 bits jcxz and JECXZ and get error
illegal instruction.

Op code E3h
Post 08 Jan 2021, 19:53
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1819
Roman 08 Jan 2021, 19:59
I check in IDA Pro this and get jrcxz !
And this code work fine in IDA Pro.
Code:
mov       ecx,2
ll:  db 0E3h,5 ;this is jrcxz    l2 
     dec cx
     jmp ll
l2:  
    


jrcxz compile ok.
How i understood in 64 bits jecxz not support.
Post 08 Jan 2021, 19:59
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 719
Ali.Z 08 Jan 2021, 22:04
jcxz cannot be encoded in long-mode.

the default is jrcxz in long-mode.

jecxz is supported by using address size prefix.

_________________
Asm For Wise Humans
Post 08 Jan 2021, 22:04
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1819
Roman 09 Jan 2021, 10:14
Funny but asm op. code the same.
A mean jrcxz and jecxz have op. code 0E3h
Post 09 Jan 2021, 10:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 09 Jan 2021, 10:20
In 64-bit there is no jcxz, The binary code it used for jecxz instead. This is known as a "promoted" instruction, because the base case is jrcxz.

The is the same for pop and push. The same binary code is used for 64-bits push/pop as that used for 32-bit mode. Meaning there is no 32-bit push/pop at all in 64-bit mode.
Post 09 Jan 2021, 10:20
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2523
Furs 09 Jan 2021, 14:04
Yeah, but jcxz is 16-bit, not 32-bit, so it's not the same as push/pop situation.
Post 09 Jan 2021, 14:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 09 Jan 2021, 14:10
Yes, you are correct. I could have made that clearer.
Post 09 Jan 2021, 14:10
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 09 Jan 2021, 14:54
This all traces back to how 386 used special prefix rules for LOOP/JCXZ family of instructions. The choice of CX or ECX was controlled (unusually) by 67h prefix, while 66h prefix controlled the size of target address computation. You can easily test all the combinations:
Code:
format PE at 400000h

        jecxz   dword 401000h   ; E3
        jecxz   word 1000h      ; 66 E3
        jcxz    dword 401000h   ; 67 E3
        jcxz    word 1000h      ; 66 67 E3    

In long mode the 67h prefix was kept, this time choosing between RCX and ECX, while 66h was discontinued, as obviously it would be quite useless.
Post 09 Jan 2021, 14:54
View user's profile Send private message Visit poster's website Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 19 Jan 2021, 02:18
So db 4x has totally no effect on E3, right?
Post 19 Jan 2021, 02:18
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 719
Ali.Z 19 Jan 2021, 12:30
no, because *CX register is used implicitly.

_________________
Asm For Wise Humans
Post 19 Jan 2021, 12:30
View user's profile Send private message Reply with quote
uu



Joined: 20 Jul 2024
Posts: 44
uu 14 Sep 2024, 08:12
Just now I tested jcxnz (Jump if CX/ECX not zero), and FASM said illegal instruction.

I check online, really no jcxnz, only got jcxz.
Post 14 Sep 2024, 08:12
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 986
Location: Russia
macomics 14 Sep 2024, 10:11
Code:
use16
inc cx
loop labelname ; dec cx & jcxnz labelname
labelname:    
Post 14 Sep 2024, 10:11
View user's profile Send private message Reply with quote
uu



Joined: 20 Jul 2024
Posts: 44
uu 14 Sep 2024, 10:34
macomics wrote:
Code:
use16
inc cx
loop labelname ; dec cx & jcxnz labelname
labelname:    


Very creative! Thumbs up.
Post 14 Sep 2024, 10:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 14 Sep 2024, 11:10
uu wrote:
Just now I tested jcxnz (Jump if CX/ECX not zero), and FASM said illegal instruction.

I check online, really no jcxnz, only got jcxz.
The x86 instruction set is nowhere orthogonal. There are many special cases of instructions using fixed hard coded registers.

MUL
DIV
LODS
etc.

It was all done with the desire to save those precious expensive bytes for other uses.

One even weirder, seemingly contradictory, case is AAM/AAD with needing an extra byte for the base. There was no room in the microcode to encode the value of 10, so it was left up to the assembler to provide the constant.
Post 14 Sep 2024, 11:10
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 986
Location: Russia
macomics 14 Sep 2024, 17:17
Code:
use16
inc cx ; cx = 0xFFFF + 1 = 0 -> nojmp (CF)
       ; cx = 0x0000 + 1 = 1 -> nojmp (CXz)
       ; cx = 0x0001 + 1 = 2 -> jmp (nCF & nCXz)
loopnz labelname ; dec cx & jcxnz_and_nc labelname
labelname:    

however
Code:
use16
inc cx ; cx = 0xFFFF + 1 = 0 -> jmp (CF)
       ; cx = 0x0000 + 1 = 1 -> nojmp (CXz)
       ; cx = 0x0001 + 1 = 2 -> nojmp (nCF)
loopz labelname ; dec cx & jecxnz_and_cf labelname
labelname:    
Post 14 Sep 2024, 17:17
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.