flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2, 3 Next |
Author |
|
bitshifter
Check out my win32 utility - BitBox
http://board.flatassembler.net/topic.php?t=11615 It has routines for the following conversions: binary to string decimal to string hexadecimal to string string to binary string to decimal string to hexadecimal Note: they are not the safest or most robust routines. Mainly because of under\overflow checking is not performed. I have an updated version with more features i will upload soon. Also if you search around there are routines which do all 3 in one proc. Have fun ![]() |
|||
![]() |
|
Overflowz
Mate, I'm starter I dont understand lot of code from that code.. I need just simple code
![]() |
|||
![]() |
|
revolution
Overflowz: windwakr already gave you the code:
http://board.flatassembler.net/topic.php?p=119655#119655 |
|||
![]() |
|
Overflowz
Yes I know but isn't there more easy way ?
![]() |
|||
![]() |
|
Overflowz
If not, can someone rewrite that without error messages and things like that.. just MAIN functions what will convert integer to string. I'll learn that things later. thank you. !
![]() |
|||
![]() |
|
revolution
Overflowz wrote: ... but isn't there more easy way ? |
|||
![]() |
|
Overflowz
never mind. just little example, not so much >.<
|
|||
![]() |
|
LocoDelAssembly
BTW, do you really want itoa functionality or just simple, homework-like, convert to decimal (i.e. base 10) string?
|
|||
![]() |
|
Overflowz
Just convert so I can display that in MessageBox API
![]() |
|||
![]() |
|
Overflowz
Nobody knows ?
![]() |
|||
![]() |
|
revolution
Nobody cares. There are so many examples already on this board you can just search to find one to your liking.
Besides, we don't much fancy doing your homework for you. ![]() |
|||
![]() |
|
Overflowz
I dont have any homework it's just for interest. Can you write the EASY Examples of that code what you're saying ?
|
|||
![]() |
|
bitshifter
First to have decimal to convert...
Code: g_value dd 1234 Then to have a buffer for string... Code: g_buffer rb 256 Now to have conversion routine... Code: dec2str: ; EAX = value ; EDI = buffer mov ecx,10 .stack_dec: xor edx,edx div ecx add edx,'0' push edx test eax,eax jz .purge_dec call .stack_dec .purge_dec: pop dword[edi] inc edi ret Then to format number into buffer... Code: mov eax,[g_value] mov edi,g_buffer call dec2str Then to display results... Code: invoke MessageBox,0,g_buffer,0,0 Are you able to integrate into your own app, or do you need full example? Last edited by bitshifter on 26 Sep 2010, 19:19; edited 1 time in total |
|||
![]() |
|
Nameless
i hope this helps, i re-wrote it in Delphi, almost porting the asm code line by line to Delphi.
if u want it in C just ask Code: { Base (var) = ecx Number (var) = eax div instruction in performs Unsigned division of edx:eax by r/m32 (ecx in out case), with result stored in eax = Quotient edx = Remainder so Reminder (var) = edx } function Dec2Str(Number, Base: Integer):string; var Reminder: Integer; i: Integer; begin i := 1; while Number <> 0 do begin Reminder := Number mod Base; //store the reminder of the division in Reminder = edx Number := Number div Base; //eq. to "div ecx", in delphi 2 steps needs, no function for division and reminder at the same time Inc(Reminder, Ord('0')); //eq. to " add edx, '0' ", add the POSITION of zero in the ascii table to each reminder to get its ASCII equivalent SetLength(Result, I); //Delphi Stuff..... Result[i] := chr(Reminder); //convert ASCII code to its Char equivalent Inc(i); //More Delphi Stuff..... end; Result := ReverseString(Result); //works the same way as " pop dword[edx] ", since stack follows LIFO, reversing is required end; //Usage: // _String := Dec2Str(2588, 10); take a look at the ascii table here to know what " add edx, '0' " means http://www.asciitable.com/ |
|||
![]() |
|
Overflowz
bitshifter thank you!! No, I was just interested how to do that.. nothing special
![]() ![]() Nameless I dont know delphi but thanks for reply anyway. ![]() |
|||
![]() |
|
Picnic
Simple itoa & atoi 16-bit implementations along with a whole bunch of other routines can also be found inside MBASIC source code.
|
|||
![]() |
|
Overflowz
simple right ?.. mate its hard for me I'm starter >.< and btw I need in 32bit mode
![]() ![]() |
|||
![]() |
|
shoorick
Code: proc fitoa num, string local buf: rb 10 finit fild [num] ; load integer fbstp tword [buf] ; store packed bcd mov ecx,9 ; counter: 18 digits - 9 bytes mov edx,[string] ; pointer to the string to fill cmp [buf + ecx],0 ; if highest byte is not null - negative number je @F mov byte [edx],"-" ; then set "-" at the string start inc edx @@: mov al,[buf + ecx - 1] ; get bytes in backward direction (higher bytes have higher address mov ah,al ; split packed bcd in al to two unpacked in al/ah shr al,4 and ah,15 add ax,3030h ; add 30h to each number to get ascii code mov [edx],ax ; store couple of digits into string inc edx ; get next string address inc edx loop @B ; get next offset in buf, if 0 - done mov [edx],cl ; set end of string ret endp ![]() Last edited by shoorick on 28 Sep 2010, 13:31; edited 1 time in total |
|||
![]() |
|
Overflowz
fbstp! Thank you but can you write with comments and how to use ?
![]() |
|||
![]() |
|
Goto page 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.