cpp_is_king
Member
I'm trying to write a program that converts an integer into a string. But I'm having trouble because neither my textbook nor the professor really covered STOSB, and we're required to use it.
Code:writeVal PROC pushad mov eax, [esp+40] ;number to convert to string mov edi, [esp+36] ;tempString address mov ebx, 10 ;will need to divide by 10 std numToString: mov edx, 0 div ebx ;divide by 10 add edx, 48 ;add 48 to convert from int to ascii push eax mov eax, edx stosb pop eax cmp eax, 0 jne numToString mov edx, [esp+36] call WriteString popad ret 8 writeVal ENDP
Numbers are entered 10 at a time into an array. They are then passed individually (looping through the array) to this procedure.
Any help would be appreciated. I'm getting really odd results.
Like entering: 15, 23, 222, 445, 232, 12, 112, 3, 21, 2
gives: 15
23
,222
,445
,232
212
,112
13
121
22
So I'm getting random commas, and just plain wrong numbers at certain points.
http://www.intel.com/content/dam/ww...r-instruction-set-reference-manual-325383.pdf
is a better reference than both your textbook and your teacher.
That said, you haven't posted the code that prints the comma or the newline, and "WriteString" seems kind of dubious. What does it do?
I also find it a little strange that you are not setting up a proper stack frame.