flat assembler
Message board for the users of flat assembler.

Index > Main > no jump

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
r22



Joined: 27 Dec 2004
Posts: 805
r22
Speed-wise I think CMOV would be the fastest method.

Here's my 9 byte variation
Code:
SETZ al
SETNZ ah
ADD ax,0AFFh
    
Post 08 May 2009, 20:17
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
r22 wrote:
Here's my 9 byte variation
Code:
SETZ al
SETNZ ah
ADD ax,0AFFh
    
Oops, what happened there? That won't work.

[edit]Sorry, my mistake, this code works just fine.[/edit]


Last edited by revolution on 11 May 2009, 21:52; edited 1 time in total
Post 09 May 2009, 00:16
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Yeah right, wheres the CMOV?
Post 09 May 2009, 05:29
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 313
Mac2004
bitshifter wrote:
It's cool to see so many people getting involved
in this and sharing their ideas with each other.
I love to see threads like this.


It seems like many board members wish to share "the fun of optimization" Smile

regards,
Mac2004
Post 09 May 2009, 06:56
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2941
Location: vpcmipstrm
bitRAKE
I had thought about using LAHF and grabbing the ZF bit directly, but can't manage a smaller version. If we allow a massive data table it becomes easy to produce smaller variants, but that ignores the size of the data.
Post 09 May 2009, 15:58
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
revolution wrote:
r22 wrote:
Here's my 9 byte variation
Code:
SETZ al
SETNZ ah
ADD ax,0AFFh
    
Oops, what happened there? That won't work.


Can you clearify ... It seems to work for me ...

Test
Code:
format PE CONSOLE
include 'win32ax.inc'
        cinvoke printf,<'Start',13,10,0>
        xor eax,eax
        test eax,eax; zf=1
        jnz  .exit ;ut-oh?
        setz al
        setnz   ah
        add     ax,0AFFh
        cinvoke printf,<'ZF = 1 THEN AX = %X ',13,10,0>,eax
        mov     eax,1
        test eax,eax; zf=0
        jz   .exit ;ut-oh?
        setz al
        setnz   ah
        add     ax,0AFFh
        cinvoke printf,<'ZF = 0 THEN AX = %X ',13,10,0>,eax
.exit:
        invoke  system,"pause"
        invoke  ExitProcess,0

data import

 library kernel32,'KERNEL32.DLL',\
         user32,'USER32.DLL',\
         msvcrt,'MSVCRT.DLL'

 import kernel32,\
        ExitProcess,'ExitProcess'

 import user32,\
        MessageBoxA,'MessageBoxA'

 import msvcrt,\
        printf,'printf',\
        system,'system'

end data  
    

Output
Code:
Start
ZF = 1 THEN AX = B00
ZF = 0 THEN AX = BFF
Press any key to continue . . .
    
Post 11 May 2009, 16:19
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
It only works because you have "mov eax,1" in there pre-initialising the value of AX. Cheater! Wink

[edit]My mistake, as above.[/edit]


Last edited by revolution on 11 May 2009, 21:53; edited 1 time in total
Post 11 May 2009, 19:45
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
LocoDelAssembly
Come on revolution, you'll confuse some people. (I even believed you when you said it won't work...)

r22's code works because of the following:
Code:
SETZ al ; IF ZF THEN AL = 1; else AL = 0
SETNZ ah ; IF ZF THEN AH = 0; else AH = 1

ADD ax,0AFFh
; AX = $BFF WHEN AL = 0 and AH = 1 ; i.e. lower part of $0AFF intact, higher part incremented
; AX = $B00 WHEN AL = 1 and AH = 0 ; i.e. lower part of $0AFF incremented and wrapped around to zero, higher part incremented because of the carry from the lower part.
    
Post 11 May 2009, 21:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
It only works if AX has some known value before execution. If I have the following what happens:
Code:
mov eax,0x12345678
cmp ebx,ecx
SETZ al
SETNZ ah
ADD ax,0AFFh     


[edit]Please ignore, what I said is not true.[/edit]


Last edited by revolution on 11 May 2009, 21:54; edited 1 time in total
Post 11 May 2009, 21:39
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
LocoDelAssembly
AX will be either $0B00 or $0BFF. And before AX is set with those values it was either $0001 or $0100.
Post 11 May 2009, 21:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
LocoDelAssembly wrote:
AX will be either $0B00 or $0BFF. And before AX is set with those values it was either $0001 or $0100.
Oh, yeah, I have been working with ARM for too long. Very sorry to mislead you all. The code will work.
Post 11 May 2009, 21:45
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
The confusion is caused by source code obfuscation perhaps. I hope nobody writes real source code like this Smile
Code:
SETZ al
SETNZ ah
ADD ax,0AFFh    
Post 12 May 2009, 09:17
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
12 posts for 3 lines of ASM I think we've reached a new exciting level ... of insanity Razz

@LocoDel - Rev had me convinced as well, and I wrote the original snippet ! I had to compile an example just to prove myself right ... to myself

@MazeGen - I should of put SETNZ AH as the first instruction instead of the confusing SETZ AL Very Happy Very Happy
Post 12 May 2009, 12:43
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.