Initial (manual) import
This commit is contained in:
1 parent
f39611c506
commit
895fe109de
661 files changed
+245862
No files matched your search
@@ -0,0 +1,75 @@
|
||||
/*Asm labels can only be defined once
|
||||
in a task. <F5> will spawn a new task
|
||||
each time, so you don't get redefine
|
||||
error, like when repeatedly #including
|
||||
it from the cmd line.
|
||||
*/
|
||||
|
||||
asm {
|
||||
//Opcodes are slightly different to make writing my x86_64 assembler easier.
|
||||
//See $LK,"::/Compiler/OpCodes.DD"$.
|
||||
|
||||
IMPORT Beep;
|
||||
|
||||
_BEEPS::
|
||||
//You can always clobber RAX,RBX,RCX,RDX,R8,R9. The compiler expects that.
|
||||
//See $LK,"REGG_CLOBBERED",A="MN:REGG_CLOBBERED"$ and $LK,"REGG_STK_TMP",A="MN:REGG_STK_TMP"$.
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RCX,U64 SF_ARG1[RBP] //$LK,"SF_ARG1",A="FF:::/Kernel/KernelA.HH,SF_ARG1"$
|
||||
|
||||
@@05: PUSH RCX
|
||||
//U0 $LK,"Beep",A="MN:Beep"$(I8 ona=62,Bool busy=FALSE)
|
||||
PUSH FALSE //Do not busy (spin) wait
|
||||
PUSH 62 //500 Hz
|
||||
CALL Beep
|
||||
POP RCX
|
||||
LOOP @@05
|
||||
|
||||
POP RBP
|
||||
RET1 8 //Use special return. Pop one arg off of stack.
|
||||
|
||||
//HolyC return vals are in RAX. This function has no return value.
|
||||
}
|
||||
|
||||
//_extern binds a asm sym to a function.
|
||||
//My convention is to put an underscore
|
||||
//on C callable asm routines.
|
||||
_extern _BEEPS U0 Beeps(I64 cnt);
|
||||
|
||||
I64 AsmAndC1()
|
||||
{
|
||||
I64 noreg i; //Normally this would be stored in a reg
|
||||
//Check by unassembling with $LK,"Uf",A="MN:Uf"$("AsmAndC1").
|
||||
|
||||
i=GetI64("Num of beeps 1-5 (%d):",3,1,5);
|
||||
Beeps(i);
|
||||
|
||||
asm {
|
||||
//You can clobber RAX,RBX,RCX,RDX. The compiler expects that.
|
||||
|
||||
IMPORT Snd; //Import an not use & or don't import and use &Snd.
|
||||
MOV RCX,&i[RBP] //You can clobber RAX,RBX,RCX,RDX.
|
||||
//You better preserve the rest.
|
||||
@@05: PUSH RCX
|
||||
|
||||
//U0 $LK,"Snd",A="MN:Snd"$(I8 ona);
|
||||
MOV RAX,RCX //ona=loop*10+50
|
||||
IMUL2 RAX,10 //TempleOS uses nonstandard opcodes
|
||||
//to avoid multiple form of the same one.
|
||||
//See $LK,"::/Compiler/OpCodes.DD"$.
|
||||
ADD RAX,40
|
||||
PUSH RAX
|
||||
CALL Snd
|
||||
|
||||
MOV RCX,cnts.time_stamp_freq>>3 //JIT Const. Simple delay loop
|
||||
@@10: LOOP @@10
|
||||
|
||||
POP RCX
|
||||
LOOP @@05
|
||||
}
|
||||
Snd;
|
||||
return i;
|
||||
}
|
||||
|
||||
"Beeps:%d\n",AsmAndC1;
|
||||
@@ -0,0 +1,85 @@
|
||||
/*Asm labels can only be defined once
|
||||
in a task. <F5> will spawn a new task
|
||||
each time, so you don't get redefine
|
||||
error, like when repeatedly #including
|
||||
it from the cmd line.
|
||||
*/
|
||||
|
||||
//This is to demo glbl var access.
|
||||
//Glbs defined elsewhere can accessed too, like cnts.jiffies.
|
||||
I64 glbl_ona=Freq2Ona(400),glbl_ona_step=10,glbl_ona_base=Freq2Ona(100);
|
||||
|
||||
asm {
|
||||
//Opcodes are slightly different to make writing my x86_64 assembler easier.
|
||||
//See $LK,"::/Compiler/OpCodes.DD"$.
|
||||
|
||||
JIFFIES_MSG: DU8 "Jiffies:",0;
|
||||
|
||||
//See $LK,"::/Kernel/StrA.HC",A="FL:::/Kernel/StrA.HC,1"$ and $LK,"::/Kernel/KUtils.HC"$.
|
||||
|
||||
_BEEPS2::
|
||||
//You can clobber RAX,RBX,RCX,RDX,R8,R9. The compiler expects that.
|
||||
//See $LK,"REGG_CLOBBERED",A="MN:REGG_CLOBBERED"$ and $LK,"REGG_STK_TMP",A="MN:REGG_STK_TMP"$.
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RCX,U64 SF_ARG1[RBP] //$LK,"SF_ARG1",A="FF:::/Kernel/KernelA.HH,SF_ARG1"$
|
||||
|
||||
PUSH U64 [&cnts.jiffies]
|
||||
|
||||
@@05: PUSH RCX
|
||||
//U0 $LK,"Beep",A="MN:Beep"$(I8 ona=62,Bool busy=FALSE)
|
||||
PUSH FALSE //Do not busy (spin) wait
|
||||
PUSH U64 [&glbl_ona] //evaluated at run time
|
||||
CALL &Beep
|
||||
POP RCX
|
||||
LOOP @@05
|
||||
|
||||
PUSH RSI //See $LK,"REGG_LOCAL_VARS",A="MN:REGG_LOCAL_VARS"$ & $LK,"REGG_LOCAL_NON_PTR_VARS",A="MN:REGG_LOCAL_NON_PTR_VARS"$
|
||||
MOV RSI,JIFFIES_MSG
|
||||
CALL PUT_STR
|
||||
POP RSI
|
||||
|
||||
POP RAX
|
||||
SUB RAX,U64 [&cnts.jiffies]
|
||||
NEG RAX
|
||||
CALL PUT_HEX_U64
|
||||
MOV RAX,'\n'
|
||||
CALL PUT_CHARS
|
||||
|
||||
POP RBP
|
||||
RET1 8
|
||||
}
|
||||
|
||||
//My convention is to put an underscore
|
||||
//on C callable asm routines.
|
||||
_extern _BEEPS2 U0 Beeps2(I64 cnt);
|
||||
|
||||
U0 AsmAndC2()
|
||||
{
|
||||
I64 reg R15 i;
|
||||
|
||||
i=GetI64("$$PURPLE$$\n\nNum of beeps 1-5 (%d):$$FG$$",3,1,5);
|
||||
Beeps2(i);
|
||||
|
||||
asm {
|
||||
LIST
|
||||
//You can clobber RAX,RBX,RCX,RDX, but preserve the rest.
|
||||
MOV RCX,R15 //You can clobber RAX,RBX,RCX,RDX. Preserve the rest.
|
||||
@@05: PUSH RCX
|
||||
|
||||
//U0 $LK,"Snd",A="MN:Snd"$(I8 ona);
|
||||
MOV RAX,RCX //ona=loop*10+100.0Hz
|
||||
IMUL2 RAX,glbl_ona_step //Intentionally evaluated at compile time
|
||||
ADD RAX,U64 [&glbl_ona_base] //Intentionally evaluated at run time
|
||||
PUSH RAX
|
||||
CALL &Snd //We can skip IMPORT with & if JIT compiling.
|
||||
MOV RCX,cnts.time_stamp_freq>>3 //JIT Const. Simple delay loop.
|
||||
@@10: LOOP @@10
|
||||
|
||||
POP RCX
|
||||
LOOP @@05
|
||||
}
|
||||
Snd;
|
||||
}
|
||||
|
||||
AsmAndC2;
|
||||
@@ -0,0 +1,23 @@
|
||||
/*Asm labels can only be defined once
|
||||
in a task. <F5> will spawn a new task
|
||||
each time, so you don't get redefine
|
||||
error, like when repeatedly #including
|
||||
it from the cmd line.
|
||||
*/
|
||||
|
||||
U0 AsmAndC3()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<3;i++) {
|
||||
"Meaning of life:";
|
||||
MOV AL,0x41
|
||||
STC
|
||||
ADC AL,0 //Round-about way to make the not-special constant, 0x42.
|
||||
CALL PUT_HEX_U8
|
||||
MOV RCX,cnts.time_stamp_freq>>5 //JIT Const. Simple delay loop.
|
||||
@@1: LOOP @@1
|
||||
'\n';
|
||||
}
|
||||
}
|
||||
|
||||
AsmAndC3;
|
||||
@@ -0,0 +1,50 @@
|
||||
/*Asm labels can only be defined once
|
||||
in a task. <F5> will spawn a new task
|
||||
each time, so you don't get redefine
|
||||
error, like when repeatedly #including
|
||||
it from the cmd line.
|
||||
|
||||
These are many useful kernel
|
||||
routines $LK,"::/Kernel/StrA.HC",A="FF:::/Kernel/StrA.HC,PUT_CHARS"$
|
||||
intended to be called from
|
||||
asm. Generally, they preserve
|
||||
regs.
|
||||
|
||||
You can call any routine you
|
||||
like, C or asm, if you import it.
|
||||
Be aware that C routines do not
|
||||
preserve RAX,RBX,RCX,RDX,R8,R9.
|
||||
When calling from the shell or
|
||||
from C, preserve all other regs.
|
||||
|
||||
*/
|
||||
|
||||
asm {
|
||||
//Opcodes are slightly different to make writing my x86_64 assembler easier.
|
||||
//See $LK,"::/Compiler/OpCodes.DD"$.
|
||||
|
||||
MY_WORLD_MSG:
|
||||
//Define U8 does not put terminating zeros
|
||||
//on strings.
|
||||
DU8 "World\n",0;
|
||||
|
||||
//My convention is to put an underscore
|
||||
//on C callable asm routines.
|
||||
_HELLO_WORLD::
|
||||
PUSH RSI //See $LK,"REGG_LOCAL_VARS",A="MN:REGG_LOCAL_VARS"$ & $LK,"REGG_LOCAL_NON_PTR_VARS",A="MN:REGG_LOCAL_NON_PTR_VARS"$
|
||||
MOV RCX,10
|
||||
@@05: MOV RAX,RCX
|
||||
CALL PUT_HEX_U8
|
||||
MOV RAX,CH_SPACE
|
||||
CALL PUT_CHARS
|
||||
MOV RAX,'Hello ' //Supports multi-byte char consts
|
||||
CALL PUT_CHARS
|
||||
//We broke it in two pieces to show different ways.
|
||||
MOV RSI,MY_WORLD_MSG
|
||||
CALL PUT_STR
|
||||
LOOP @@05
|
||||
POP RSI
|
||||
RET
|
||||
};
|
||||
|
||||
Call(_HELLO_WORLD);
|
||||
@@ -0,0 +1,184 @@
|
||||
#define RANGE_START 1
|
||||
#define RANGE_END 100
|
||||
|
||||
#define FIZZ_SPAN 6
|
||||
#define BUZZ_SPAN 7
|
||||
|
||||
asm {
|
||||
_BUZZ_FIZZ::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP //Always set-up stk frame. (Stack Gets Traced)
|
||||
PUSH RSI //See $LK,"REGG_LOCAL_VARS",A="MN:REGG_LOCAL_VARS"$ & $LK,"REGG_LOCAL_NON_PTR_VARS",A="MN:REGG_LOCAL_NON_PTR_VARS"$
|
||||
PUSH RDI
|
||||
MOV RSI,FIZZ_SPAN-RANGE_START%FIZZ_SPAN+1
|
||||
MOV RDI,BUZZ_SPAN-RANGE_START%BUZZ_SPAN+1
|
||||
MOV RAX,RANGE_START
|
||||
|
||||
@@05: CALL PUT_HEX_U64
|
||||
PUSH RAX
|
||||
MOV RAX,CH_SPACE
|
||||
CALL PUT_CHARS
|
||||
|
||||
DEC RSI
|
||||
JNZ @@10
|
||||
MOV RAX,'FIZZ '
|
||||
CALL PUT_CHARS
|
||||
MOV RSI,FIZZ_SPAN
|
||||
|
||||
@@10: DEC RDI
|
||||
JNZ @@15
|
||||
MOV RAX,'BUZZ '
|
||||
CALL PUT_CHARS
|
||||
MOV RDI,BUZZ_SPAN
|
||||
|
||||
@@15: MOV RAX,'\n'
|
||||
CALL PUT_CHARS
|
||||
POP RAX
|
||||
INC RAX
|
||||
CMP RAX,RANGE_END //Actually only a 32-bit inst.
|
||||
JBE @@05
|
||||
|
||||
POP RDI
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET
|
||||
}
|
||||
|
||||
Call(_BUZZ_FIZZ);
|
||||
|
||||
/*
|
||||
_BUZZ_FIZZ+0x0000 55 PUSH U64 RBP
|
||||
_BUZZ_FIZZ+0x0001 488BEC MOV U64 RBP,U64 RSP
|
||||
_BUZZ_FIZZ+0x0004 56 PUSH U64 RSI
|
||||
_BUZZ_FIZZ+0x0005 57 PUSH U64 RDI
|
||||
_BUZZ_FIZZ+0x0006 BE06000000 MOV U32 ESI,U32 00000006
|
||||
_BUZZ_FIZZ+0x000B BF07000000 MOV U32 EDI,U32 00000007
|
||||
_BUZZ_FIZZ+0x0010 B801000000 MOV U32 EAX,U32 00000001
|
||||
_BUZZ_FIZZ+0x0015 E8C51F2BC0 CALL I32 PUT_HEX_U64+0x0000
|
||||
_BUZZ_FIZZ+0x001A 50 PUSH U64 RAX
|
||||
_BUZZ_FIZZ+0x001B B820000000 MOV U32 EAX,U32 00000020
|
||||
_BUZZ_FIZZ+0x0020 E81E202BC0 CALL I32 PUT_CHARS+0x0000
|
||||
_BUZZ_FIZZ+0x0025 48FFCE DEC U64 RSI
|
||||
_BUZZ_FIZZ+0x0028 7514 JNZ I8 _BUZZ_FIZZ+0x003E
|
||||
_BUZZ_FIZZ+0x002A 48B846495A5A MOV U64 RAX,I64 000000205A5A4946
|
||||
_BUZZ_FIZZ+0x0030 20000000
|
||||
_BUZZ_FIZZ+0x0034 E80A202BC0 CALL I32 PUT_CHARS+0x0000
|
||||
_BUZZ_FIZZ+0x0039 BE06000000 MOV U32 ESI,U32 00000006
|
||||
_BUZZ_FIZZ+0x003E 48FFCF DEC U64 RDI
|
||||
_BUZZ_FIZZ+0x0041 7514 JNZ I8 _BUZZ_FIZZ+0x0057
|
||||
_BUZZ_FIZZ+0x0043 48B842555A5A MOV U64 RAX,I64 000000205A5A5542
|
||||
_BUZZ_FIZZ+0x0049 20000000
|
||||
_BUZZ_FIZZ+0x004D E8F11F2BC0 CALL I32 PUT_CHARS+0x0000
|
||||
_BUZZ_FIZZ+0x0052 BF07000000 MOV U32 EDI,U32 00000007
|
||||
_BUZZ_FIZZ+0x0057 B80A000000 MOV U32 EAX,U32 0000000A
|
||||
_BUZZ_FIZZ+0x005C E8E21F2BC0 CALL I32 PUT_CHARS+0x0000
|
||||
_BUZZ_FIZZ+0x0061 58 POP U64 RAX
|
||||
_BUZZ_FIZZ+0x0062 48FFC0 INC U64 RAX
|
||||
_BUZZ_FIZZ+0x0065 4883F864 CMP U64 RAX,I8 64
|
||||
_BUZZ_FIZZ+0x0069 76AA JNA I8 _BUZZ_FIZZ+0x0015
|
||||
_BUZZ_FIZZ+0x006B 5F POP U64 RDI
|
||||
_BUZZ_FIZZ+0x006C 5E POP U64 RSI
|
||||
_BUZZ_FIZZ+0x006D 5D POP U64 RBP
|
||||
_BUZZ_FIZZ+0x006E C3 RET
|
||||
|
||||
0000000000000001
|
||||
0000000000000002
|
||||
0000000000000003
|
||||
0000000000000004
|
||||
0000000000000005
|
||||
0000000000000006 FIZZ
|
||||
0000000000000007 BUZZ
|
||||
0000000000000008
|
||||
0000000000000009
|
||||
000000000000000A
|
||||
000000000000000B
|
||||
000000000000000C FIZZ
|
||||
000000000000000D
|
||||
000000000000000E BUZZ
|
||||
000000000000000F
|
||||
0000000000000010
|
||||
0000000000000011
|
||||
0000000000000012 FIZZ
|
||||
0000000000000013
|
||||
0000000000000014
|
||||
0000000000000015 BUZZ
|
||||
0000000000000016
|
||||
0000000000000017
|
||||
0000000000000018 FIZZ
|
||||
0000000000000019
|
||||
000000000000001A
|
||||
000000000000001B
|
||||
000000000000001C BUZZ
|
||||
000000000000001D
|
||||
000000000000001E FIZZ
|
||||
000000000000001F
|
||||
0000000000000020
|
||||
0000000000000021
|
||||
0000000000000022
|
||||
0000000000000023 BUZZ
|
||||
0000000000000024 FIZZ
|
||||
0000000000000025
|
||||
0000000000000026
|
||||
0000000000000027
|
||||
0000000000000028
|
||||
0000000000000029
|
||||
000000000000002A FIZZ BUZZ
|
||||
000000000000002B
|
||||
000000000000002C
|
||||
000000000000002D
|
||||
000000000000002E
|
||||
000000000000002F
|
||||
0000000000000030 FIZZ
|
||||
0000000000000031 BUZZ
|
||||
0000000000000032
|
||||
0000000000000033
|
||||
0000000000000034
|
||||
0000000000000035
|
||||
0000000000000036 FIZZ
|
||||
0000000000000037
|
||||
0000000000000038 BUZZ
|
||||
0000000000000039
|
||||
000000000000003A
|
||||
000000000000003B
|
||||
000000000000003C FIZZ
|
||||
000000000000003D
|
||||
000000000000003E
|
||||
000000000000003F BUZZ
|
||||
0000000000000040
|
||||
0000000000000041
|
||||
0000000000000042 FIZZ
|
||||
0000000000000043
|
||||
0000000000000044
|
||||
0000000000000045
|
||||
0000000000000046 BUZZ
|
||||
0000000000000047
|
||||
0000000000000048 FIZZ
|
||||
0000000000000049
|
||||
000000000000004A
|
||||
000000000000004B
|
||||
000000000000004C
|
||||
000000000000004D BUZZ
|
||||
000000000000004E FIZZ
|
||||
000000000000004F
|
||||
0000000000000050
|
||||
0000000000000051
|
||||
0000000000000052
|
||||
0000000000000053
|
||||
0000000000000054 FIZZ BUZZ
|
||||
0000000000000055
|
||||
0000000000000056
|
||||
0000000000000057
|
||||
0000000000000058
|
||||
0000000000000059
|
||||
000000000000005A FIZZ
|
||||
000000000000005B BUZZ
|
||||
000000000000005C
|
||||
000000000000005D
|
||||
000000000000005E
|
||||
000000000000005F
|
||||
0000000000000060 FIZZ
|
||||
0000000000000061
|
||||
0000000000000062 BUZZ
|
||||
0000000000000063
|
||||
0000000000000064
|
||||
*/
|
||||
@@ -0,0 +1,22 @@
|
||||
asm {
|
||||
_DIV_U64_BY_U64::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
XOR RDX,RDX
|
||||
MOV RCX,64
|
||||
MOV RAX,SF_ARG1[RBP]
|
||||
MOV RBX,SF_ARG2[RBP]
|
||||
@@1: SHL1 RAX
|
||||
RCL1 RDX
|
||||
CMP RBX,RDX
|
||||
JA @@2
|
||||
INC RAX
|
||||
SUB RDX,RBX
|
||||
@@2: LOOP @@1
|
||||
POP RBP
|
||||
RET1 16
|
||||
}
|
||||
|
||||
_extern _DIV_U64_BY_U64 I64 DivU64ByU64(I64 dividend,I64 divisor);
|
||||
|
||||
"123456/10=%d\n",DivU64ByU64(123456,10);
|
||||
@@ -0,0 +1,69 @@
|
||||
/*When I was a kid with a Commodore 64,
|
||||
the 6502 chip had no multiply inst
|
||||
and this is how we had to do it, except,
|
||||
I used more regs in this example.
|
||||
*/
|
||||
asm {
|
||||
//Opcodes are slightly different to make writing my x86_64 assembler easier.
|
||||
//See $LK,"::/Compiler/OpCodes.DD"$.
|
||||
|
||||
//You can clobber RAX,RBX,RCX,RDX,R8,R9. The compiler expects that.
|
||||
|
||||
MUL_BY_HAND_U8_U8_TO_U16: //This is only for fun.
|
||||
//8bit * 8bit-->16bit
|
||||
//AL*BL-->AX
|
||||
MOV CL,8
|
||||
SHL AX,8
|
||||
@@05: SHL1 AX
|
||||
JNC @@10
|
||||
ADD AL,BL
|
||||
@@10: DEC CL
|
||||
JNZ @@05
|
||||
RET
|
||||
|
||||
_MUL_BY_HAND_U8_U8_TO_U16:: //C callable
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV AL,U8 SF_ARG1[RBP] //$LK,"SF_ARG1",A="FF:::/Kernel/KernelA.HH,SF_ARG1"$
|
||||
MOV BL,U8 SF_ARG2[RBP]
|
||||
CALL MUL_BY_HAND_U8_U8_TO_U16
|
||||
MOVZX RAX,AX
|
||||
POP RBP
|
||||
RET1 16
|
||||
|
||||
_MUL_U64_U64_TO_U128::
|
||||
//64bit * 64bit-->128bit
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RBX,U64 SF_ARG3[RBP]
|
||||
MOV RAX,U64 SF_ARG1[RBP] //$LK,"SF_ARG1",A="FF:::/Kernel/KernelA.HH,SF_ARG1"$
|
||||
MUL U64 SF_ARG2[RBP] //Res RDX:RAX 128bit
|
||||
MOV U64 [RBX],RAX
|
||||
MOV U64 8[RBX],RDX
|
||||
POP RBP
|
||||
RET1 24
|
||||
};
|
||||
|
||||
//My convention is to put an underscore
|
||||
//on C callable asm routines.
|
||||
_extern _MUL_BY_HAND_U8_U8_TO_U16 U16 MulU8(U8 n1,U8 n2);
|
||||
|
||||
class U128
|
||||
{
|
||||
U64 lo,hi;
|
||||
};
|
||||
|
||||
_extern _MUL_U64_U64_TO_U128 U0 MulU64(I64 n1,I64 n2,U128 *_prod);
|
||||
|
||||
U0 MulByHand()
|
||||
{
|
||||
U128 p;
|
||||
"2*7 =0x%X\n",MulU8(2,7);
|
||||
"100*10=0x%X\n",MulU8(100,10);
|
||||
|
||||
MulU64(0x0123456789ABCDEF,0x1000001,&p);
|
||||
"0x0123466789ABCDEF*0x1000001=0x%016X%016X\n",p.hi,p.lo;
|
||||
}
|
||||
|
||||
MulByHand;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
asm {
|
||||
PUT_DEC_U64::
|
||||
//RAX is number to print in decimal.
|
||||
//Preserves all regs.
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
SUB RSP,24 //24 char buffer on stack
|
||||
|
||||
//$LK,"Save regs",A="FF:::/Kernel/KernelA.HH,PUSH_C_REGS"$ which C code is free to clobber. We don't have to for C callers,
|
||||
//but this function will be nice for ASM callers if it saves all regs.
|
||||
PUSH_C_REGS
|
||||
|
||||
PUSH RSI //See $LK,"REGG_LOCAL_VARS",A="MN:REGG_LOCAL_VARS"$&$LK,"REGG_LOCAL_NON_PTR_VARS",A="MN:REGG_LOCAL_NON_PTR_VARS"$
|
||||
LEA RSI,-1[RBP] //Load addr of end of buffer.
|
||||
//We picked RSI because of PUT_STR
|
||||
//We'll move bwd
|
||||
MOV U8 [RSI],0 //Terminator
|
||||
|
||||
TEST RAX,RAX //Special case -- zero
|
||||
JNZ @@05
|
||||
DEC RSI
|
||||
MOV U8 [RSI],'0'
|
||||
JMP @@15
|
||||
|
||||
@@05: MOV RBX,10 //Divides by 10
|
||||
|
||||
@@10: XOR RDX,RDX
|
||||
DIV RBX //RAX=(RDX:RAX)/RBX with remainder in RDX
|
||||
ADD RDX,'0'
|
||||
DEC RSI
|
||||
MOV U8 [RSI],DL
|
||||
TEST RAX,RAX
|
||||
JNZ @@10
|
||||
|
||||
@@15: CALL PUT_STR
|
||||
POP RSI
|
||||
POP_C_REGS
|
||||
LEAVE
|
||||
RET
|
||||
|
||||
_DO_IT:: //The convention is C-callable routines have underscores.
|
||||
MOV RAX,122333221
|
||||
CALL PUT_DEC_U64
|
||||
MOV RAX,'\n'
|
||||
CALL PUT_CHARS
|
||||
RET
|
||||
}
|
||||
|
||||
Call(_DO_IT);
|
||||
Reference in new issue
Block a user