The MASM Forum

General => The Campus => Topic started by: patriciocs on January 09, 2020, 11:06:41 AM

Title: Store a 8 digit random number as ASCII
Post by: patriciocs on January 09, 2020, 11:06:41 AM
Hello,

I am learning ASM and I am trying to solve a problem which involves to store a 8 digit randomly generated decimal number (1 to 99999999) as 8 ASCII characters at memory address ptrString (i.e. number 452346 should be stored as "  452346" and 12345678 as "12345678").

I think I have managed to generate the random number:


.data?
lpszNumber db 2 dup (?)

.code invoke GetTickCount
    invoke nseed, eax
    invoke nrandom, 100000000
    invoke dwtoa, eax, offset lpszNumber
    invoke atob, eax, offset lpszNumber
  move dword ptr[ptrString], lpszNumber


But from here an on I am lost. I have read many man pages and forum but I haven't been able to find a way to store in the ptrString address the ASCII codes for the string representing the number in decimal.

I would really appreciate your help. Any suggestion how to proceed?

Regards
Title: Re: Store a 8 digit random number as ASCII
Post by: hutch-- on January 09, 2020, 11:22:09 AM
The single line,

dwtoa proc dwValue:DWORD, lpBuffer:DWORD

Will do it for you.

The dwValue is what you get from the random number generator, lpBuffer is the memory address where the result is written.
Title: Re: Store a 8 digit random number as ASCII
Post by: deeR44 on April 07, 2020, 05:27:31 PM
The random number you will generate will be 0 (zero) to 99999999.