Peek/Poke commands in assembly?

Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Peek/Poke commands in assembly?

Post by Mistrel »

Does anyone know where I can find the ASM equivalents of the Peek/Poke commands for long, float, and string?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

I don't know assembly well at all but isn't this the correct way to mov a variable?

Code: Select all

!mov eax,[v_a]
!mov [eax],dword 7
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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
:)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

There's no reason to use push when you can use mov, as it's way faster.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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

User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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. :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post 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.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Floats are exactly the same as longs - 4 bytes. Only the interpretation of the contents is different.
Post Reply