flat assembler
Message board for the users of flat assembler.

Index > Main > no jump

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
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.
Post 07 May 2009, 06:39
View user's profile Send private message Reply with quote
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.
Post 07 May 2009, 07:16
View user's profile Send private message Visit poster's website Reply with quote
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.
Post 07 May 2009, 07:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20308
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    
Post 07 May 2009, 08:06
View user's profile Send private message Visit poster's website Reply with quote
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.
Post 07 May 2009, 08:25
View user's profile Send private message Reply with quote
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!
Post 07 May 2009, 08:54
View user's profile Send private message Visit poster's website Reply with quote
Madis731



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 Smile).
Post 07 May 2009, 10:09
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
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).
Post 07 May 2009, 14:54
View user's profile Send private message Reply with quote
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):
vmadd231ps v0 {k1},v5,[rbx+rcx*4]
vcmpleps k2,{k2},v25,[ConstantFloatOne] {1to16}

Really! Laughing
Post 07 May 2009, 15:25
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 07 May 2009, 15:33
Very Happy Yeah, I know Smile
Post 07 May 2009, 15:33
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
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)
Post 07 May 2009, 15:41
View user's profile Send private message Visit poster's website Reply with quote
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.
Post 07 May 2009, 17:48
View user's profile Send private message Reply with quote
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    
Post 07 May 2009, 19:59
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: 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.
Post 07 May 2009, 20:23
View user's profile Send private message Reply with quote
comrade



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    
Post 07 May 2009, 20:31
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 08 May 2009, 06:21
Smile 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 Smile

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 Smile

_________________
My updated idol Very Happy http://www.agner.org/optimize/
Post 08 May 2009, 06:21
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
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.
Post 08 May 2009, 15:25
View user's profile Send private message Visit poster's website Reply with quote
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.
Post 08 May 2009, 15:44
View user's profile Send private message Reply with quote
Madis731



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

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

PCMPISTRI xmm0,xmm1,100b is my line-of-the-day Smile
Post 08 May 2009, 16:31
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
bitshifter



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

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

Right on, brother Razz
Quote:

And I'm not 13 ...

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

_________________
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.
Post 08 May 2009, 19:04
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.