flat assembler
Message board for the users of flat assembler.

Index > Main > Fasm 1.73 Many cmp one jz.

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



Joined: 11 Jul 2020
Posts: 202
Overclick
It doesn't seems to work as you reloading reg0

Your code in fasm will looks like this:
Code:
macro cmp a,[b] {
     sub rsp,8
     irp c, b  \{
        cmp       a,c
        pushfq
        pop      a
        or        [rsp],a
     \}
     popfq
}
    


Final version of my one. It accepts any size of operands as usual cmp does (figured by compiler ofcourse)
Code:
macro cmp a,[b] {
     c=0
     forward
     c=c+1
     common
     if c > 1
        push rax
        push qword 0
     forward
        if `a in <'rax','eax','ax','ah','al'> | \
           `b in <'rax','eax','ax','ah','al'>
            mov      rax,[rsp+8]
        end if
        cmp          a,b
        lahf
        or           [rsp],ah
     common
        pop rax
        shl          ax,8
        sahf
        pop rax
     else
        cmp          a,b
     end if
}    


Last edited by Overclick on 23 Jul 2020, 22:36; edited 1 time in total
Post 23 Jul 2020, 20:20
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17664
Location: In your JS exploiting you and your system
revolution
Overclick: If any flag is set upon entry then the compares have no effect, and those same flags are always set upon exit.

Also, consider making c local to avoid clashes.
Code:
local c
;...
     if c > 1
        push rax
        pushq 0 ;reset all flags
     forward    


Last edited by revolution on 23 Jul 2020, 22:27; edited 1 time in total
Post 23 Jul 2020, 22:05
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3043
Location: vpcmipstrm
bitRAKE
Overclick wrote:
It doesn't seems to work as you reloading reg0

Your code in fasm will looks like this:
Code:
macro cmp a,[b] {
     sub rsp,8
     irp c, b  \{
        cmp       a,c
        pushfq
        pop      a
        or        [rsp],a
     \}
     popfq
}
    
not really. the flags aren't POP'd until the end. "if % = %%"

_________________
¯\(°_o)/¯ unlicense.org
Post 23 Jul 2020, 22:12
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 202
Overclick
bitRAKE, operand for cmp replaced for next interaction


revolution, you right.
Post 23 Jul 2020, 22:23
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3043
Location: vpcmipstrm
bitRAKE
do you mean for:
Code:
compare r15, 1,2,3
compare r15, 6,7,8    
Then yes, R15 would be overwritten.

_________________
¯\(°_o)/¯ unlicense.org
Post 23 Jul 2020, 22:27
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 202
Overclick
Edited last version, there also I'm worried about full pack of flags replaced to 0. That why I changed popfq to:
Code:
        pop rax
        shl          ax,8
        sahf
        pop rax    
Post 23 Jul 2020, 22:40
View user's profile Send private message 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 GitHub, YouTube, Twitter.

Website powered by rwasa.