summaryrefslogtreecommitdiff
path: root/miniany/cc.c
diff options
context:
space:
mode:
Diffstat (limited to 'miniany/cc.c')
-rw-r--r--miniany/cc.c69
1 files changed, 8 insertions, 61 deletions
diff --git a/miniany/cc.c b/miniany/cc.c
index acba6df..6f4f0a8 100644
--- a/miniany/cc.c
+++ b/miniany/cc.c
@@ -802,9 +802,15 @@ void genPrologue( struct Compiler *compiler )
putstring( "org $1000000" ); putnl( );
putstring( "jmp _start" ); putnl( );
putstring( "putint:" ); putnl( );
- putstring( "mov esi, 0xa" ); putnl( );
+ putstring( "mov esi, 0" ); putnl( );
putstring( "lea edi, [putint_string_fmt]" ); putnl( );
- putstring( "add edi, 9" ); putnl( );
+ putstring( "itoa_init:" ); putnl( );
+ putstring( "mov byte [edi], 0x20" ); putnl( );
+ putstring( "inc edi"); putnl( );
+ putstring( "inc esi"); putnl( );
+ putstring( "cmp esi, 9" ); putnl( );
+ putstring( "jne itoa_init" ); putnl( );
+ putstring( "inc esi"); putnl( );
putstring( "itoa_loop:" ); putnl( );
putstring( "mov edx, 0" ); putnl( );
putstring( "div esi" ); putnl( );
@@ -815,70 +821,11 @@ void genPrologue( struct Compiler *compiler )
putstring( "jnz itoa_loop" ); putnl( );
putstring( "mov eax, 4" ); putnl( );
putstring( "mov ebx, 1" ); putnl( );
- /* TODO: itoa in assembly (yuck!) and print resulting string */
putstring( "mov ecx, putint_string_fmt" ); putnl( );
- /* TODO: compute length with a assemble time function sizeof or so.. */
putstring( "mov edx, 11" ); putnl( );
putstring( "int 0x80" ); putnl( );
putstring( "ret" ); putnl( );
putstring( "_start:" ); putnl( );
-
-/*
-
-fmt: .string "%s\n"
-
-.lcomm converted, 10
-
-
- .section .text
-
-.global _start
-
-_start:
-
- xorl %ecx, %ecx
- xorl %edi, %edi
- movl $NUMBER, %eax
-
-itoa_loop:
- # Limpa para divisão
- xorl %edx, %edx
-
- movl $10, %esi
-
- # Agora nós temos o quociente em %eax
- # e o resto da divisão em %edx
- idiv %esi
-
- # Convertendo para a representação em ASCII
- addl $48, %edx
-
- pushl %edx
- incl %ecx
-
- xorl $0, %eax
- jnz itoa_loop
-
-rev_loop:
- popl %eax
- movl %eax, converted(, %edi, 1)
- incl %edi
- decl %ecx
-
- cmpl $0, %ecx
- jnz rev_loop
-
- pusha
- pushl $converted
- pushl $fmt
- call printf
- addl $8, %esp
- popa
-
- # Exiting
- movl $1, %eax
- int $0x80
- */
}
void genEpilogue( struct Compiler *compiler )