ZealOS/src/Doc/HelloWorld.DD

100 lines
1.7 KiB
Text
Raw Normal View History

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()
{
"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)
{
"%s", st;
2020-02-15 20:01:48 +00:00
}
MyPrint("Hello World\n");
2020-02-16 04:57:03 +00:00
--------Hello.CC---------
U0 MyPrint2(U8 *st1, U8 *st2) //Any number of args.
2020-02-15 20:01:48 +00:00
{
"%s %s\n", st1, st2; //Any number of args.
2020-02-15 20:01:48 +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)
{
"" 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 {
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::
//You can only clobber RAX,RBX,RCX,RDX
PUSH RSI
MOV RSI, MESSAGE
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
MOV RAX, 'Hello '
CALL PUT_CHARS //Up to 8 chars packed into one 64-bit int.
MOV RAX, 'World\n'
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
PUSH RBP
MOV RBP, RSP
PUSH RSI
MOV RSI, U64 SF_ARG1[RBP]
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
PUSH RBP
MOV RBP, RSP
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$