Permalink
Browse files

added ftoa

  • Loading branch information...
1 parent 280b881 commit 21bf12a2cf25b70cf7c3e161b194dbe5285f25c0 @xeth137 committed Apr 16, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 include/dcpu16/dcpulib.dasm
@@ -76,9 +76,50 @@ JSR _global_utoa
SET A, POP
SET PC, POP
;
+;extern char* ftoa( float, char* );
+;
+:_global_ftoa
+SET C, 10
+SET PUSH, B
+SET PUSH, A
+IFG 0x7FFE, A
+SET PC, __ftoa_cont
+SET [B], 45
+ADD B, 1
+SET I, 0
+SUB I, A
+SET A, I
+:__ftoa_cont
+SHR A, 8
+JSR _global_utoa
+SET A, POP
+IFG 0x7FFE, A
+SET PC, __ftoa_cont2
+SET I, 0
+SUB I, A
+SET A, I
+:__ftoa_cont2
+AND A, 0x00FF
+IFE A, 0
+SET PC, __ftoa_done
+SET [B], 46
+ADD B, 1
+MUL A, 100
+DIV A, 256
+IFG O, 128
+ADD A, 1
+JSR _global_utoa
+:__ftoa_done
+SET A, POP
+SET PC, POP
+;
;extern char* utoa( unsigned, char*, int );
;
:_global_utoa
+IFG 2, C
+SET C, 10
+IFG C, 16
+SET C, 10
SET PUSH, X
SET PUSH, Z
SET X, B
@@ -93,6 +134,7 @@ ADD B, 1
DIV A, C
IFN A, 0
SET PC, __itoa_loop
+SET PUSH, B
SET [B], 0
SUB B, 1
SET A, X
@@ -110,6 +152,7 @@ SUB B, 1
IFN A, Z
SET PC, __itoa_loop2
SET A, X
+SET B, POP
SET Z, POP
SET X, POP
SET PC, POP

0 comments on commit 21bf12a

Please sign in to comment.