Skip to content

Instantly share code, notes, and snippets.

@Guevara-chan
Last active March 2, 2017 00:14
Show Gist options
  • Save Guevara-chan/165f10a4f00927a965b3e21ba6d3690d to your computer and use it in GitHub Desktop.
Save Guevara-chan/165f10a4f00927a965b3e21ba6d3690d to your computer and use it in GitHub Desktop.
Procedure.s LongToStr(Val.l, Base.a = 10)
#MaxBase = 36; So far.
Define Sign.a, Accum.s{33}
If Base > 1 And Base <= #MaxBase ; If operation ever applicable...
If Val < 0 : Val = -Val : Sign = '-' : EndIf
EnableASM
MOV EAX, Val
MOVZX EBX, Base
LEA ECX, Accum
DivMore:
SUB EDX, EDX : DIV EBX
MOV DL, byte [EDX+l___ctable]
MOV [ECX], DL : INC ECX
CompilerIf #PB_Compiler_Unicode
INC ECX ; One more.
CompilerEndIf
And EAX, EAX
JNZ l_longtostr_divmore ; Oh yes, Fred, thank you so~ much.
MOV DL, Sign : MOV [ECX], DL
DisableASM
ProcedureReturn ReverseString(Accum)
EndIf ; Modulus-to-char conversion table:
DataSection : __CTable: : Data.a '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' : EndDataSection
EndProcedure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment