Peek/Poke alternatives

Everything else that doesn't fall into one of the other PB categories.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Peek/Poke alternatives

Post by Polo »

I'm searching an alternative to all the peek/poke function, I mean, I want to do the same things as these functions do, but without using them. Is it possible ?
If yes, ... how ?
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

er...why?
--Kale

Image
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Because I'm searching to do things more complicated than they are actually :)
And because the size of the misc memory is 4.45k, and it's too big for me :)
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

Code: Select all

a.l = 23

*ptr.LONG = @a

*ptr\l = 42

Debug a
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post by coma »

or use asm.

poke :

Code: Select all

MOV eax,val
MOV edi,*mem
MOV [edi],eax
peek:

Code: Select all

MOV edi,*mem
MOV eax,[edi]
MOV val,eax
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Coma => Amazing ! It works fine !
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Edit: Sorry, I made a mistake :D
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

I can't make it work for byte...

*MemoryBuffer = AllocateMemory(0, 16, 0)
byte.b=1
MOV eax,byte
MOV edi,*MemoryBuffer
MOV [edi],eax
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

You have to specify the operand size, because EAX doesn't match with byte. Therefore you have to use ASM-syntax directly (by using a ! at start of the line) and therefore you have to refer to your variable's value as [v_variable].

Code: Select all

*MemoryBuffer = AllocateMemory(0, 16, 0) 
byte.b=1 
!MOV eax, dword [v_byte]
MOV edi,*MemoryBuffer 
MOV [edi],eax
Read the flatassembler-help for all details. You get it here: http://www.flatassembler.net
%1>>1+1*1/1-1!1|1&1<<$1=1
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Polo wrote:Because I'm searching to do things more complicated than they are actually :)
And because the size of the misc memory is 4.45k, and it's too big for me :)
lol 8O
--Kale

Image
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

this should work without the '!' stuff...

Code: Select all

byte.b
*memorybuffer = @byte

MOV al, byte
MOV edi, *memorybuffer
MOV [edi], al
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

The rest of the eax is not resetted when copying to al only, so you would have to be very careful in the following not to use MOV [edi], eax
%1>>1+1*1/1-1!1|1&1<<$1=1
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post by filperj »

They say you have to protect every register exept EAX and EDX when writing a userlib, maybe should do the same for an inline-asm block... No?
:roll: I wonder what really need to be protected or not...
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Using pointer as freedimension said is the way to go. It's the same than using asm but much more easier :wink:
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

I have maked the function works with ASM :) I don't know why, but I understand it better than pointer 8O
Post Reply