flat assembler
Message board for the users of flat assembler.

 Index > Main > no jump Goto page 1, 2  Next
Author
bitshifter

Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 07 May 2009, 06:39
How could this operation be done without jumps?
I tried a few different ideas but none very good.
Maybe someone can show me a nice trick for this.

psuedo
Code:
```if ZF == 1 then AX = 0x0B00

else AX = 0x0BFF    ```

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
07 May 2009, 06:39
MazeGen

Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 07 May 2009, 07:16
Code:
```mov ax, 0x0BFF
mov bx, 0x0B00
cmovz ax, bx    ```

Requires Pentium Pro.

CMOVcc is similar to conditional jumps, you can use CMOVZ, CMOVNZ etc.
07 May 2009, 07:16
bitshifter

Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 07 May 2009, 07:40
Yes MazeGen, that was exactly what my first attempt looked like.
I also thought there might be a nice way to use lahf with a mask.
I had even considred a method using set* with a twist.

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
07 May 2009, 07:40
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20302
Location: In your JS exploiting you and your system
revolution 07 May 2009, 08:06
If you wanted "if CF==1 then ax=0xbff, else 0xb00" then:
Code:
```salc
mov ah,0xb    ```
07 May 2009, 08:06
bitshifter

Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 07 May 2009, 08:25
Very cool revolution, but it only can use ZF.

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
07 May 2009, 08:25
Picnic

Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 07 May 2009, 08:54
MazeGen wrote:
Code:
```mov ax, 0x0BFF
mov bx, 0x0B00
cmovz ax, bx    ```

Requires Pentium Pro.

I never use those instructions so far, but they look very handy!
07 May 2009, 08:54

Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 07 May 2009, 10:09
Careful, though, when you start using them and realize there's a 64-bit world, then some of these "ingenious" instructions are overwritten for better compacting of more usual code!

CMOVcc stayed, but AA* instructions were removed and SALC (which is even in FASM code ).
07 May 2009, 10:09
bitshifter

Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 07 May 2009, 14:54
Im still stuck in the 16/32 bit world. lol
Pretty soon we will have instructions like jncgfrwasioxprtn
How bad is that gonna suck?
You can keep your 64 bit system (no offense intended).
07 May 2009, 14:54
bitRAKE

Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 07 May 2009, 15:25
Code:
```setz al
mov ah,\$0B
dec al    ```
Oh, so many ways!

Nah, the new instructions will be like (LRBni):
vcmpleps k2,{k2},v25,[ConstantFloatOne] {1to16}

Really!
07 May 2009, 15:25

Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 07 May 2009, 15:33
Yeah, I know
07 May 2009, 15:33
Coddy41

Joined: 18 Jan 2009
Posts: 384
Location: Ohio, USA
Coddy41 07 May 2009, 15:41
bitshifter wrote:
Im still stuck in the 16/32 bit world. lol.

You meen I'm not the only one?

_________________
Want hosting for free for your asm project? You can PM me. (*.fasm4u.net)
07 May 2009, 15:41
bitshifter

Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 07 May 2009, 17:48
bitRAKE wrote:
Code:
```setz al
mov ah,\$0B
dec al    ```
Oh, so many ways!

Yes!
Thats the one i wanted!
I was playing with setz for a while but couldnt get it to work right.
My version was off by one, but i never considered just letting it wrap around.
*dances in circles*

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
07 May 2009, 17:48
MHajduk

Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 07 May 2009, 19:59
If you want EFLAGS register untouched you can do something like that:
Code:
```setz al
movzx     eax, al
lea  eax, [eax - 1]
movzx eax, al
mov  ah, 0x0B    ```
07 May 2009, 19:59
LocoDelAssembly
Your code has a bug

Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 07 May 2009, 20:23
MHajduk, you don't really need to zero extend anything, it will work without it:

Code:
```setz    al
lea     eax, [eax - 1]
; EAX[7:0] = 0xFF if not ZF
; EAX[7:0] = 0x00 if ZF
mov     ah, 0x0B     ```

EAX[31:16] will hold garbage instead of zero of course but setting it to zero is also destroying the original value so no extra harm here.
07 May 2009, 20:23

Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 07 May 2009, 20:31
Here is another one, FWIW:

Code:
```setnz al
neg al
mov ah, \$0B    ```
07 May 2009, 20:31

Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 08 May 2009, 06:21
Sometimes its even useful to read TFM
Intel Instruction Set Reference 2B p. 391 wrote:

Some languages represent a logical one as an integer with all bits set. This representation can be obtained by choosing the logically opposite condition for the SETcc instruction, then decrementing the result. For example, to test for overflow, use the SETNO instruction, then decrement the result.

That's exactly the case as I understand. I'm really glad that they decided to keep the SETcc in 64-bit and even extend it with RAX supporting all the r15b and r9d

I would really like to defend my choice of 64-bit. I know everyone has their own flavour, but 16-bit is starting to die out and it has memory concerns as well. 64-bit is a nice desert where "all your flat memorys are belong to us".

In usual scenarios it will compile in less bytes than 16-bit code would. I'm not talking about weird hacks, but still in this bit-twiddling example 32/64-bit wins:
Code:
```use16 ;9 bytes
setz    al
lea     ax,[eax-1] ;Original with eax is even 10 bytes
mov     ah,0x0B

use32 ;8 bytes
setz    al
lea     eax,[eax-1]
mov     ah,0x0B

use64 ;8 bytes
setz    al
lea     eax,[rax-1]
mov     ah,0x0B
```

So if not 64-bit then at least 32-bit

_________________
My updated idol http://www.agner.org/optimize/
08 May 2009, 06:21
bitRAKE

Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 08 May 2009, 15:25
Well, to be fair,
Code:
```setz al    ; 0F 94 C0
dec ax     ; 48
mov ah,\$0B ; B4 0B    ```
...is smaller than can be done in long mode, but also works in 32-bit.
08 May 2009, 15:25
bitshifter

Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 08 May 2009, 15:44
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.
08 May 2009, 15:44

Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 08 May 2009, 16:31
6 bytes... nice, can everyone make a 5-byte one?

Why I get involved: Optimization is my true guiding light I want to be a game-programmer in the future and write the most efficient 3D-game-engine EVER !!! And I'm not 13 ...

PCMPISTRI xmm0,xmm1,100b is my line-of-the-day
08 May 2009, 16:31
bitshifter

Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 08 May 2009, 19:04
6 bytes... nice, can everyone make a 5-byte one?

Guess its time to break tho old TSCWin
Quote:
and write the most efficient 3D-game-engine EVER

Right on, brother
Quote:

And I'm not 13 ...

The last time i cut my hair was before some of this kids were even born.

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
08 May 2009, 19:04
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area
Goto page 1, 2  Next

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum