flat assembler
Message board for the users of flat assembler.
Index
> Main > Byte to Integer |
Author |
|
gunblade 16 Mar 2006, 19:59
That would depend on the operating system you are on.
First, to convert the value to a string equivalent of it, use this code: Code: IntToStr: ; eax = number, ebx = base, edi = buffer push ecx edx xor ecx,ecx .new: xor edx,edx div ebx push edx inc ecx test eax,eax jnz .new .loop: pop eax add al,30h cmp al,'9' jng .ok add al,7 .ok: stosb loop .loop mov al,0 stosb pop edx ecx ret This isnt mine, I found it on this board somewhere, sorry to whoever wrote it for not putting your name here, I just never noted it down. But great code. You would then output it using the OS-specific API. For linux, you would use something along the lines of: Code: mov eax, 4 mov ebx, 1 mov ecx, addressofstring mov edx, lengthofstring int 0x80 Oh, and a tip, you can find the length of the string made by the code at the top by doing: Code: sub edi, addressofstring after calling it. Good luck, gunblade |
|||
16 Mar 2006, 19:59 |
|
Patrick_ 16 Mar 2006, 20:21
Thanks for the response. However, I have a few questions:
First, since it's my third day of learning/programming in assembly, could you please comment the lines? I can understand some of it, but I'm not quite sure what's totally going on. Also, the comment says that ebx is the base... what do you mean by base? Like base-10, base-6 (hex), etc? Or something else? Thanks for that tip, too. I was wondering how I'd do that. |
|||
16 Mar 2006, 20:21 |
|
rugxulo 16 Mar 2006, 22:38
Check here for a fast bin2dec routine (Terje Mathisen, GPL): http://board.flatassembler.net/topic.php?t=3924
|
|||
16 Mar 2006, 22:38 |
|
Madis731 17 Mar 2006, 08:08
Yeah, it should be the fastest (60 clocks) against the traditional divide_by_10_and_take_the_reminder approach where every such division takes at least 49 clocks and you need upto ten of these.
|
|||
17 Mar 2006, 08:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.