Page 1 of 2
Peek/Poke alternatives
Posted: Mon Feb 16, 2004 6:51 pm
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 ?
Posted: Mon Feb 16, 2004 6:55 pm
by Kale
er...why?
Posted: Mon Feb 16, 2004 7:00 pm
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

Posted: Mon Feb 16, 2004 7:05 pm
by freedimension
Code: Select all
a.l = 23
*ptr.LONG = @a
*ptr\l = 42
Debug a
Posted: Mon Feb 16, 2004 8:27 pm
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
Posted: Mon Feb 16, 2004 11:09 pm
by Polo
Coma => Amazing ! It works fine !
Posted: Mon Feb 16, 2004 11:25 pm
by Polo
Edit: Sorry, I made a mistake

Posted: Mon Feb 16, 2004 11:37 pm
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
Posted: Mon Feb 16, 2004 11:58 pm
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
Posted: Tue Feb 17, 2004 12:12 am
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
Posted: Tue Feb 17, 2004 12:18 am
by Pupil
this should work without the '!' stuff...
Code: Select all
byte.b
*memorybuffer = @byte
MOV al, byte
MOV edi, *memorybuffer
MOV [edi], al
Posted: Tue Feb 17, 2004 1:34 am
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
Posted: Tue Feb 17, 2004 4:34 am
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...
Posted: Wed Feb 18, 2004 5:43 pm
by Fred
Using pointer as freedimension said is the way to go. It's the same than using asm but much more easier

Posted: Wed Feb 18, 2004 6:22 pm
by Polo
I have maked the function works with ASM

I don't know why, but I understand it better than pointer 8O