Low word without peek?

Just starting out? Need help? Post your questions and find answers here.
Justin
Addict
Addict
Posts: 958
Joined: Sat Apr 26, 2003 2:49 pm

Low word without peek?

Post by Justin »

Is there any way(i guess using shift operators) to get the low word of a long without using peekw(@long) ? , i do this to reduce exe size.

i did this asm proc but i think can be done using operators ¿?

Code: Select all

procedure peekw_(hbuf)
r.w
mov edi,hbuf 
mov ax,word [edi]
mov r,ax
procedurereturn r
endprocedure
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Code: Select all

LoWord = Long & $FFFF
HiWord = Long >> 16
Timo
quidquid Latine dictum sit altum videtur
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Low word without peek?

Post by traumatic »

loWord = var.l & $FFFF
hiWord = var.l >> 16
Good programmers don't comment their code. It was hard to write, should be hard to read.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Low word without peek?

Post by traumatic »

ahhhh, too late... damn dial-up!
Justin
Addict
Addict
Posts: 958
Joined: Sat Apr 26, 2003 2:49 pm

Post by Justin »

Ok thanks, much easier. Do you know if it's faster or slower?, i'll use to process the WM_COMMAND msg inside the window callback.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Justin wrote:Ok thanks, much easier. Do you know if it's faster or slower?, i'll use to process the WM_COMMAND msg inside the window callback.
Don't know about quicker, but I guess using the & and >> operators would be preferrable as your peek method relies on little endian byte ordering (i.e. would not work on 68k, probably not on PPC depending on what mode it was in). I guess it only matters if you care about portability and hope that there is one day a PPC/Linux or Mac version of PB ;)

I think Fred once said that simple commands like Peek, Sin, etc were all made inline by the compiler, but I could be wrong.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Freak's code is much faster than calling that peekw procedure, no doubt.
El_Choni
Post Reply