flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
decard
Try this (not tested):
Code: macro itoa int,destination,counter { mov eax,[int] mov edi,destination add edi,[counter] dec edi mov [edi+1],byte 0 ;0 ended strings! mov ecx,[counter] ;number of loops mov ebx,10 .loop: xor edx,edx ;se necesita para la division div ebx ;eax=number divided by ten. edx=modulo add edx,'0' ;"0" is added to convert number to ascii char (0 + "0" = "0", 1+"0"="1", 5+"0"=5 etc.) mov [edi],dl ;move the char to the string dec edi ;continue with another char loop .loop ;alternative way; ;cmp edi,destination ;jne .loop } |
|||
![]() |
|
DC740
i found the bug!!
![]() it was here: Code: mov [edi],edx ;move the char to the string you were right, it should be Code: mov [edi],dl ;move the char to the string but i found that in your code you used [counter]... and the correct use is counter without brackets... be cause the macro is called like this Code: itoa in_value,stringdestination,4 this is the working macro Code: ;Converts an in into a string macro itoa int,destination,counter { mov eax,[int] mov edi,destination add edi,counter;-1 dec edi mov [edi+1],byte 0 ;0 ended strings! mov ecx,counter ;number of loops mov ebx,10 .loop: xor edx,edx ;se necesita para la division div ebx ;eax=number divided by ten. edx=modulo add edx,'0' ;"0" is added to convert number to ascii char (0 + "0" = "0", 1+"0"="1", 5+"0"=5 etc.) mov [edi],dl ;move the char to the string dec edi ;continue with another char loop .loop ;alternative way; ;cmp edi,destination ;jne .loop } thanx a lot decard, you save me a headache... i'll work a little more in the macro to stop using the counter value... (i don't like it ![]() good bye and happy coding[/code] |
|||
![]() |
|
decard
DC740 wrote: but i found that in your code you used [counter]... and the correct use is counter without brackets... be cause the macro is called like this ok, I just thought that counter is a variable, not constant. |
|||
![]() |
|
Tommy
lol, reinventing the wheel will never be easy
![]() |
|||
![]() |
|
RedGhost
Tommy wrote: lol, reinventing the wheel will never be easy skip the wheel and invent a hovercraft _________________ redghost.ca |
|||
![]() |
|
DC740
now i'm frustrated as a programmer....
![]() why in this world i can't make an atoi simple macro... i don't need negative number, i don't use floating point... so why ![]() i deleted my code about 20 times and started all again with diferent ways of doing the same thing... but i can't make it work... this is the last thing i tryed ecx is the lenght of the string Code: mov esi,string mov edi,destinationinteger .loop2: sub esi,'0' mov eax,[edi] mov ebx,10 mul ebx mov [edi],eax add [edi],esi inc esi loop .loop2 at the beginning i thought that maybe i was doing somethin wrong in the agorithm that i had thought, but after five minutes of searching in google i found that i was not wrong... well... my code was wrong, but not my algorithm.... i'm trying to do the next thing: Quote: To convert an ASCII string representation of a integer into the corresponding good bye |
|||
![]() |
|
KronosRJ
Here is a suggestion (NOT TESTED):
Code: macro atoi{ mov esi , string mov ecx , stringsize mov edi , DestInt mov edx , 0 local .loop .loop: movzx eax , byte [esi] shl edx , 1 ; <== edx = edx * 2 sub eax , '0' lea edx , [edx * 4 + edx] ; <== edx = edx * 5 add edx , eax dec ecx jnz .loop } Now, let's talk about problems with your code: 1 - Mov eax , [edi] will move 4 bytes, not only one... 2 - mul will affect eax and edx... You don't want that, since you are using edx... I think you still have to work a little on your programming, but everybody has to learn somewhere... Stick to it and you will get there... |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.