Jose's Read Only Forum 2023

IT-Consultant: Charles Pegge => Assembler => Best place to post any assembler code => Topic started by: Aslan Babakhanov on January 15, 2011, 09:09:47 PM

Title: STRPTR in asm
Post by: Aslan Babakhanov on January 15, 2011, 09:09:47 PM
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.
Title: Re: STRPTR in asm
Post by: Charles Pegge on January 15, 2011, 11:03:52 PM
Hi Aslan

This can be simplified to


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


Charles
Title: Re: STRPTR in asm
Post by: Aslan Babakhanov on January 16, 2011, 05:32:51 PM
and this is really short.
Nice!
Title: Re: STRPTR in asm
Post by: Charles Pegge 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
Title: Re: STRPTR in asm
Post by: Bob Zale 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.