I created an example for Linux 64 Bit and used the following assembler code:
Code: Select all
extern PB_OpenConsole
extern PB_Input
global testcode
SECTION .text
testcode:
call PB_OpenConsole
cmp rax, 0
je .end
call PB_Input
.end:
ret
compiled with nasm
and this PB code to call the function and to provide the libraries:
Code: Select all
Import "test.o"
testcode.i()
EndImport
;This procedure is needed to include the needed libraries
Procedure dummyProcedure()
OpenConsole()
Input()
EndProcedure
testcode()
The assembler code opens a console and waits for user input. It should also work on Windows with some minor changes.
You need to write all needed PB functions in a dummy procedure or at a different position, which is never executed (this time it is an advantage that the PB compiler does not detect dead code), otherwise PureBasic may not include the needed Libraries while linking the executable. This is not necessary if you compile your code as PureBasic User Library.
I would not recommend you to use this solution with strings, because PureBasic uses it's very own and complicated way to handle strings. PureBasic does not pass strings as simple pointers like the rest of the world, but instead a big global buffer is used. If you pass multiple strings to a function, all strings are copied in this buffer after each other and only the index is passed to the function. There is no real documentation about all this stuff, so it would be much easier to directly use the system API and write some assembler string handling functions on your own.
DarkPlayer