I am working on an assignment identical to 20 Random Strings containing all capital letters
I need to create a procedure that generates a random string of length L, containing all capital letters. When calling the procedure, I need to pass the value of L in EAX, and pass a pointer to an array of byte that will hold the random string. Then I need to write a test program that calls your procedure 20 times and displays the strings in the console window.
I believe that I have gotten much closer to a solution thanks to the answers there but still have one (I hope) issue. Microsoft Visual Studio 2017 throws the following error:
Exception thrown at 0x004036BE in Project.exe: 0xC0000005: Access violation writing location 0x0080C036. occurred
The error takes place on line 41: mov arr1[EBX], AL
So my best guess is that I have miscalculated the target address of the array but I'm not sure how? I get the error on the 1st run of that loop.
; Random Strings.
INCLUDE Irvine32.inc
TAB = 9 ;ASCII code for Tab
strLen = 10 ;length of the string
numberStrings = 20
.data
str1 BYTE "The 20 random strings are:", 0
arr1 BYTE numberStrings DUP(?)
.code
main PROC
mov EDX, OFFSET str1 ;"The c20 random strings are:"
call WriteString ;Writes string
call Randomize
call Crlf ;Writes an end - of - line sequence to the console window.
mov ECX, numberStrings ;Main Loop Counter Create 20 strings
mov ESI, OFFSET arr1 ;ESI: array address
L1 :
mov EAX, strLen ;EAX: string length
call RandomString ;generates the random string
call Display ;displays the random string to console
mov AL, TAB ;moves tab to register to be passed to WriteChar
call WriteChar ;leaves a tab space
exit
main ENDP
RandomString PROC USES EAX ESI
mov ECX, EAX ;ECX = string length
mov EBX, ESI ;store array address
FillStringWithRandomCharacters :
mov EAX, 26 ;set upper boundry for RandomRange call
call RandomRange ;called with 26 so range will be 0 - 25
add EAX, 65 ;EAX gets ASCII value of a capital letter
mov arr1[EBX], AL ;pass 8 bits of EAX to array
inc EBX ;move array target address
loop FillStringWithRandomCharacters
ret
RandomString ENDP
Display PROC USES EAX ESI ;Displays the generated random string
mov ECX, EAX ;ECX = string length
mov EBX, ESI ;store array address
DisplayRandomString :
mov AL, arr1[EBX] ;retrieve char from array
call WriteChar ;writes the char to console
inc EBX ;move array target address
loop DisplayRandomString
ret
Display ENDP
call dumpregs
INVOKE ExitProcess, 0
END main