Author Topic: STRPTR in asm  (Read 3305 times)

0 Members and 1 Guest are viewing this topic.

Offline Aslan Babakhanov

  • Newbie
  • *
  • Posts: 28
STRPTR in asm
« on: January 15, 2011, 09:09:47 PM »
Naked STRPTR in assembler :)

Code: [Select]
MACRO Sptr( pString, retPtr)
 ! push ebx
 ! lea ebx, pString
 ! mov edi, dword ptr [ebx]
 ! pop ebx
 ! mov retPtr, edi
END MACRO 
...
LOCAL s AS STRING, R AS DWORD
S = "STRPTR"
SPTR (S,R)

? STR$(R)

Using stackless function may replace macro and increase readability of the code.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
    • Charles Pegge
Re: STRPTR in asm
« Reply #1 on: January 15, 2011, 11:03:52 PM »
Hi Aslan

This can be simplified to

Code: [Select]
MACRO Sptr( pString, retPtr)
 ! mov eax,pString
 ! mov retPtr,eax
END MACRO

Charles

Offline Aslan Babakhanov

  • Newbie
  • *
  • Posts: 28
Re: STRPTR in asm
« Reply #2 on: January 16, 2011, 05:32:51 PM »
and this is really short.
Nice!

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
    • Charles Pegge
Re: STRPTR in asm
« Reply #3 on: January 16, 2011, 06:24:02 PM »
While I have not peeked into PB compiled code, I believe VARPTR() and STRPTR() are not functions but generate inline instructions.

A simple VARPTR translates to

lea eax,var

whereas STRPTR becomes

mov eax,var

Then assigning the result to a local variable would be something like:

mov [ebp-8],eax

Charles

Offline Bob Zale

  • Newbie
  • *
  • Posts: 39
Re: STRPTR in asm
« Reply #4 on: January 16, 2011, 10:34:42 PM »
That would be true for pure scalar variables.  But that couldn't account for variables which require multiple operations to locate.  Arrays, pointer targets, Threaded, Instance...

Bob Zale
PowerBASIC Inc.