calling a string function in assembly

Everything else that doesn't fall into one of the other PB categories.
veganisafreak
User
User
Posts: 32
Joined: Mon Jun 02, 2008 6:55 pm
Location: UK

calling a string function in assembly

Post by veganisafreak »

I'm not very good with assembly as I've shown in my other posts.

Can someone show me how to call a function IN PURE ASM (windows) that takes a string and returns a string?

I tried looking at the asm output of pb for such a function but it was full of macros and weirdness, I was worried I might make mistakes if I tried to copy what pb does.

I don't suppose there's any technique that will guaranteed to work in future version of pb? I want the assembly equivalent of this:

Code: Select all

Procedure.s func(s.s)
Protected s2.s
; misc code goes here
ProcedureReturn s2
EndProcedure

s.s
s2.s
s2 = func(s)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

There is no standard way of doing this. If you do it the PB way it will only work with PB functions and so on. And it's not guaranteed to work in future versions. In fact, it as soon as you enable threadsafe or unicode mode the code needs to be different.
I tried looking at the asm output of pb for such a function but it was full of macros and weirdness,
There is not a single macro there. But PB uses a system which I haven't quite grasped after looking at it tons of times.

I suggest you start with a function that returns a string first. Then you try a function that takes a string parameter. Not before you understand both should you try to mix them.

Code: Select all

; Calling a procedure that returns a string
; Test()
  PUSH   dword [_PB_StringBasePosition]
  CALL  _Procedure0
  POP    dword [_PB_StringBasePosition]

Code: Select all

; The same, but assignment as well.
; A.s = Test()
  PUSH   dword [_PB_StringBasePosition]
  CALL  _Procedure0
  LEA    ecx,[v_A]
  POP    edx
  CALL   SYS_AllocateString
veganisafreak
User
User
Posts: 32
Joined: Mon Jun 02, 2008 6:55 pm
Location: UK

Post by veganisafreak »

Thanks for your help. I decided after all the threadsafe/unicode scare you gave me, lol, just to use a workaround instead. It's not worth the coding effort for something that will probably break in the next version of PB.
Post Reply