Within ecx is a number between 0 and 12
What I want is this...

if ecx = 11
I want
String = "11"

if ecx = 9
String = "09"

(or 0# where # is any number between 1 and 9)

Now I must be tired, because the solution I've done blows... :(
Can someone please give me a better solution then this :) At least one that is a little nice (used .if .else .endif because it was a somewhat rush job)

.if (ecx < 10)
;use 2 string: TempString and TempString2
;TempString = "0",0
;TempString2 = "(The number in ecx)"
lea edi, TempString
mov al, "0"
mov byte ptr [edi], al
inc edi
mov al, 0
mov byte ptr [edi], al
lea edi, TempString2
mov al, 0
mov byte ptr [edi], al
invoke dw2a, ecx, addr TempString2
invoke lstrcat, addr TempString, addr TempString2
invoke lstrcpy, addr Month, addr TempString

invoke dw2a, ecx, ADDR Month



I'd prefer not to have to use 2 strings in this solution... So if you could get rid of the use of one of them I'd appreciate it
Posted on 2002-04-03 00:49:48 by Sliver


INCLUDE \masm32\include\windows.inc
INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib
INCLUDE \masm32\include\user32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDE \masm32\include\masm32.inc
INCLUDELIB \masm32\lib\masm32.lib


Bufr DB 3 DUP(0)



mov eax, 99
mov ebx, 1
mov ecx, 10

mov esi, OFFSET Bufr
mov BYTE PTR [esi], 48


xor edx, edx
div ecx
add dl, 48
mov BYTE PTR [esi+ebx], dl
or eax, eax
jz @F
dec ebx
jmp @B


invoke MessageBox, 0, OFFSET Bufr, 0, 0
invoke ExitProcess, 0

END Start

I warn you that this is limited from 0 - 99 only. But this should suffice the condition you set. :)
Posted on 2002-04-03 01:01:58 by stryker
Thanks stryker :)

I appreciate the help... I'll check it out and get back to you if any problems

Posted on 2002-04-03 01:11:04 by Sliver
wsprintf has exactly the feature you're looking for..

myNum db "ecx has the value of %02u",0

mov ecx,9
invoke wsprintf,ADDR Buffer,ADDR myNum,ecx

should do it ;)
Posted on 2002-04-03 01:12:20 by JimmyClif

The string functions in the MASM32 library will do what you are after with no problems. Append your results to a buffer that has at least the number of zeros you need then use the szRight function to take as many characters as you need.

The append can be done with either of the szCat functions.


Posted on 2002-04-03 01:25:25 by hutch--
Nuts to masms lib Intel has provided you with a handy bite sized op code to do it for you!

If you shuffle your count so its in AX just do this

add ah, 30 ;Contains the ASCII char for the tens
add al, 30 ;Contains the ASCII char for the units
mov string, ah
mov string + 1, al

It may not be fast, and it may not be optimised, but it sure as hell beats div, or a function call (and also avoids some waste of space format string).
Of course this is only useable if your number is between 0 and 99, but you yourself said it was in the range of 0-12.

Posted on 2002-04-03 03:42:10 by Mirno
Nice idea but the following code will do any length.

STRING zeros,"00000000"

mov edx, 123456
invoke dwtoa,edx,ADDR buffer2

invoke szMultiCat,2,ADDR buffer1,ADDR zeros,ADDR buffer2

invoke szRight,ADDR buffer1,ADDR buffer2,8

invoke MessageBox,hWin,ADDR buffer2,
ADDR szDisplayName,MB_OK


Posted on 2002-04-03 05:14:20 by hutch--