2020-02-15 20:01:48 +00:00
|
|
|
$HL,1$//Press F5 in the editor to compile and run.
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-02-15 20:01:48 +00:00
|
|
|
"Hello World\n";
|
|
|
|
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-02-15 20:01:48 +00:00
|
|
|
U0 Main()
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
"Hello World\n";
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
Main;
|
|
|
|
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-02-15 20:01:48 +00:00
|
|
|
U0 MyPrint(U8 *st)
|
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
"%s", st;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
MyPrint("Hello World\n");
|
|
|
|
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-12-23 23:27:18 +00:00
|
|
|
U0 MyPrint2(U8 *st1, U8 *st2) //Any number of args.
|
2020-02-15 20:01:48 +00:00
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
"%s %s\n", st1, st2; //Any number of args.
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
2020-12-23 23:27:18 +00:00
|
|
|
MyPrint2("Hello", "World");
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-02-15 20:01:48 +00:00
|
|
|
U0 MyPrint(U8 *st)
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
"" st; //Empty with no comma means first is format str.
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
MyPrint("Hello World\n");
|
|
|
|
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-02-15 20:01:48 +00:00
|
|
|
asm {
|
2020-12-23 23:27:18 +00:00
|
|
|
MESSAGE: DU8 "Hello World\n", 0;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
//The convention is underscore on C callable.
|
|
|
|
//Two colons means exported symbol.
|
|
|
|
_HELLO_WORLD::
|
2020-02-23 07:54:39 +00:00
|
|
|
//You can only clobber RAX,RBX,RCX,RDX
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSH RSI
|
2020-12-23 23:27:18 +00:00
|
|
|
MOV RSI, MESSAGE
|
2020-02-20 23:40:10 +00:00
|
|
|
CALL PUT_STR
|
|
|
|
POP RSI
|
|
|
|
RET
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
Call(_HELLO_WORLD);
|
|
|
|
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-02-15 20:01:48 +00:00
|
|
|
asm {
|
|
|
|
_HELLO_WORLD::
|
|
|
|
//You can only clobber RAX,RBX,RCX,RDX
|
2020-12-23 23:27:18 +00:00
|
|
|
MOV RAX, 'Hello '
|
2020-02-20 23:40:10 +00:00
|
|
|
CALL PUT_CHARS //Up to 8 chars packed into one 64-bit int.
|
2020-12-23 23:27:18 +00:00
|
|
|
MOV RAX, 'World\n'
|
2020-02-20 23:40:10 +00:00
|
|
|
CALL PUT_CHARS
|
|
|
|
RET
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
Call(_HELLO_WORLD);
|
|
|
|
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-02-15 20:01:48 +00:00
|
|
|
asm {
|
|
|
|
_MY_PRINT::
|
|
|
|
//You can only clobber RAX,RBX,RCX,RDX
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSH RBP
|
2020-12-23 23:27:18 +00:00
|
|
|
MOV RBP, RSP
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSH RSI
|
2020-12-23 23:27:18 +00:00
|
|
|
MOV RSI, U64 SF_ARG1[RBP]
|
2020-02-20 23:40:10 +00:00
|
|
|
CALL PUT_STR
|
|
|
|
POP RSI
|
|
|
|
POP RBP
|
|
|
|
RET1 8 //Callee pops the stack to clear args.
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
_extern _MY_PRINT U0 MyPrint(U8 *st);
|
|
|
|
MyPrint("Hello World\n");
|
|
|
|
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
--------Hello.CC---------
|
2020-02-15 20:01:48 +00:00
|
|
|
asm {
|
|
|
|
_MY_PRINT::
|
|
|
|
//You can only clobber RAX,RBX,RCX,RDX
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSH RBP
|
2020-12-23 23:27:18 +00:00
|
|
|
MOV RBP, RSP
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSH U64 SF_ARG1[RBP]
|
|
|
|
CALL &PutS //Callee pops the stack to clear args.
|
|
|
|
POP RBP
|
|
|
|
RET1 8
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
_extern _MY_PRINT U0 MyPrint(U8 *st);
|
|
|
|
MyPrint("Hello World\n");
|
|
|
|
$HL,0$
|