News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Store a 8 digit random number as ASCII

Started by patriciocs, January 09, 2020, 11:06:41 AM

Previous topic - Next topic

patriciocs

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

hutch--

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.

deeR44

The random number you will generate will be 0 (zero) to 99999999.