flat assembler
Message board for the users of flat assembler.
Index
> Linux > problem printing output to screen |
Author |
|
crc 19 Nov 2005, 00:58
You'd need to convert the number to a string, then pass the write() system call the address of the string and its length and the device to write the string to. As a simple example:
Code: format elf executable mov ecx, string_address ; address of string mov edx, [string_address.length] ; length of string mov ebx, 1 ; stdout mov eax, 4 ; sys_write int $80 mov eax, 1 ; sys_exit int $80 ; string_address db 'hello, world!' .length dd $ - string_address |
|||
19 Nov 2005, 00:58 |
|
Endre 19 Nov 2005, 17:14
The conversion routine is a bit tricky but for a real programmer it's never a problem .
Code: format ELF executable entry start section readable executable start: ; calculate factorial of eax mov eax, 5 call factorial ; convert result to string mov ecx, buffer mov edx, buffer.size call convert_uint32_to_str ; print the string mov eax, 4 mov ebx, 1 int 0x80 ; exit mov eax, ebx xor ebx, ebx int 0x80 ; input: ; eax - unsigned value whose factorial is to be calculated ; output: ; eax - factorial factorial: cmp eax, 1 jbe .finish lea ecx, [eax-1] .loop: mul ecx loop .loop .finish: ret ; inputs: ; eax - unsigned value to be converted ; ecx - buffer the string is to be written to ; edx - length of buffer ; outputs: ; ecx - offset of string ; edx - length of string convert_uint32_to_str: xor edi, edi add ecx, edx mov ebx, 10 .loop: dec ecx inc edi xor edx, edx div ebx add dl, '0' mov [ecx], dl test eax, eax jnz .loop .finish: mov edx, edi ret section writeable buffer rb 16 .size = $ - buffer |
|||
19 Nov 2005, 17:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.