• Welcome to Jose's Read Only Forum 2023.
 

STRPTR in asm

Started by Aslan Babakhanov, January 15, 2011, 09:09:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Aslan Babakhanov

Naked STRPTR in assembler :)


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.

Charles Pegge

Hi Aslan

This can be simplified to


MACRO Sptr( pString, retPtr)
! mov eax,pString
! mov retPtr,eax
END MACRO


Charles

Aslan Babakhanov

and this is really short.
Nice!

Charles Pegge

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

Bob Zale

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.