Page 1 of 1
Peek/Poke commands in assembly?
Posted: Wed Dec 26, 2007 10:40 am
by Mistrel
Does anyone know where I can find the ASM equivalents of the Peek/Poke commands for long, float, and string?
Posted: Wed Dec 26, 2007 12:29 pm
by Trond
Code: Select all
; PokeL(@A, 7)
!mov [v_a], 7
; PokeL(A, 7)
!mov eax, [v_a]
!mov [eax], 7
; PokeF(@F, 7)
!mov [v_f], 1088421888
Peek is the same, you just mov the other way. For strings there's a loop to PokeB() the individual characters.
Posted: Wed Dec 26, 2007 9:34 pm
by Mistrel
I don't know assembly well at all but isn't this the correct way to mov a variable?
Posted: Wed Dec 26, 2007 9:54 pm
by Trond
I prefer "!mov dword [eax], 7", but that two-step way is if the variable is a pointer, so you move 7 into the address pointed to by a.
Posted: Wed Dec 26, 2007 10:31 pm
by Psychophanta
there is another way often used in z80 times:
Code: Select all
A.l
;PokeL(@A,-789):
!push dword -789
!pop dword[v_A]
Debug A.l
b.q
;PokeQ(@b,-123789):
!push dword -1 dword -123789
!pop dword[v_b] dword[v_b+4]
Debug b.q

Posted: Wed Dec 26, 2007 11:16 pm
by Trond
There's no reason to use push when you can use mov, as it's way faster.
Posted: Wed Dec 26, 2007 11:22 pm
by Trond
Here's the full PokeL function by the way:
Code: Select all
!mypokel2: ; (Address+4, Value+8)
!mov edx, [esp+4]
!mov eax, [esp+8]
!mov [edx], eax
!ret 8
; PokeL(@A, 7)
!pushd 7
!push v_a
!call mypokel2
; PokeL(A, 7)
!pushd 7
!pushd [v_a]
!call mypokel2
Posted: Thu Dec 27, 2007 3:21 pm
by Psychophanta
Indeed you are right 'mov' is faster than using stack, so there should be an improvement to redesign the way PB performs Poke and Peek.

Posted: Fri Dec 28, 2007 9:04 pm
by superadnim
Why the need to repost?
http://www.purebasic.fr/english/viewtopic.php?t=29895
I thought people gave good answers in there, enough to implement my own peek/poke set in asm x86 without trouble.
But anyway, for string you will have to ask yourself "do I want to support unicode?", then try about coding it.
Posted: Fri Dec 28, 2007 10:31 pm
by Mistrel
superadnim wrote:Why the need to repost?
http://www.purebasic.fr/english/viewtopic.php?t=29895
I thought people gave good answers in there, enough to implement my own peek/poke set in asm x86 without trouble.
But anyway, for string you will have to ask yourself "do I want to support unicode?", then try about coding it.
That post did not cover floats or strings.
Posted: Fri Dec 28, 2007 10:37 pm
by Trond
Floats are exactly the same as longs - 4 bytes. Only the interpretation of the contents is different.