lundi 30 octobre 2017

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.

The code below wont work it comes back with these errors: Line (33): error A2008: syntax error : main ENDP Line (35): error A2144: cannot nest procedures Line (46): error A2008: syntax error : RandomString Line (48): error A2144: cannot nest procedures Line (59): warning A6001: no return from procedure Line (66): fatal error A1010: unmatched block nesting

I am still very new with Assembly Language...Any ideas on what I'm doing wrong and how to fix these errors? Thank you.

;Random Strings.

INCLUDE Irvine32.inc TAB = 9 ;ASCII code for Tab strLen=10 ;length of the string

.386 .model flat,stdcall .stack 4096 ExitProcess PROTO, dwExitCode:DWORD

.data str1 BYTE"The 20 random strings are:", 0 arr1 BYTE strLen DUP(?)

.code main PROC mov ed x, OFFSET str1 ;"The c20 random strings are:" call WriteString ;Writes string call Crlf ;Writes an end-of-line sequence to the console window. mov ecx,20 ;Create 20 strings

L1: mov esi,OFFSET arr1 ;ESI: array address mov eax,strLen ;EAX: string length call RandomString ;generates the random string call Display mov al,TAB call WriteChar ;leaves a tab space exit main ENDP

 RandomString PROC USES eax esi
 mov ecx,eax                   ;ECX = string length

L1: mov eax, 26 call RandomRange add eax,65 ;EAX gets ASCII value of a capital letter mov arr1[esi],eax inc esi

 loop L1

 RandomString EXDP

 Display PROC USES eax esi     ;Displays the generated random string

 mov ecx,eax                   ;ECX=string length

L1: mov eax, arr1[esi] ;EAX = ASCII value call WriteChar ;writes the letter

 inc esi

 loop L1

 Display ENDP


    call dumpregs

    INVOKE ExitProcess,0

END main




Aucun commentaire:

Enregistrer un commentaire