Page 1 of 1

calling a string function in assembly

Posted: Wed Jun 18, 2008 5:01 pm
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)

Posted: Wed Jun 18, 2008 8:04 pm
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

Posted: Sun Jun 22, 2008 8:50 pm
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.