FAQ  •  Register  •  Login

Passing strings to assembler

<<

Uto

Posts: 10

Joined: Sat Jul 16, 2016 12:02 pm

Post Sun Oct 09, 2016 11:28 am

Passing strings to assembler

Hi,

I have this code:

  Code:
   

.....   
PRINT "Please enter text:"
LET a$= INPUT(8)
SAVEFILE(a$)
.....

SUB fastcall SAVEFILE(name as String)
ASM
.....
END ASM
END SUB


I need to get the string value in the ASM function, and I was expecting having a pointer to it as the second value in stack (so POP HL, POP DE, PUSH HL will keep the return adress in stack and DE as pointer to the string), but it doesn't seem to work like that, How could I get the string parameter from assembler?
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Nov 09, 2016 4:33 pm

Re: Passing strings to assembler

Uto wrote:Hi,

I have this code:

  Code:
   

.....   
PRINT "Please enter text:"
LET a$= INPUT(8)
SAVEFILE(a$)
.....

SUB fastcall SAVEFILE(name as String)
ASM
.....
END ASM
END SUB


I need to get the string value in the ASM function, and I was expecting having a pointer to it as the second value in stack (so POP HL, POP DE, PUSH HL will keep the return adress in stack and DE as pointer to the string), but it doesn't seem to work like that, How could I get the string parameter from assembler?

I overlook this message! Sorry!! :(


If your function only have one parameter like in your case, and you use FASTCALL, the pointer comes *already* in HL. You have to do nothing :)

For FASTCALL the convention is:

- 8 bits (Byte, UByte) -> A register
- 16 bits (Integer, UInteger, STRING) -> HL
- 32 Bits (LONG, FIXED) -> HL, DE (HL = Low part, DE = High Part)
- 40 Bits (Float) -> HL,DE -> Mantissa. A -> Exponent

For strings, better use ByVar to really get the pointer to the pointer. If not, remember to call FREE upon return or you will end UP with a memory leak.

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO