Chapter 5
Procedures
Assembly Language Programming Exercise
Problem # 6:
Create a procedure that generates a random string of length L, containing all capital letters. When calling the procedure, pass the value of L in EAX, and pass a pointer to an array of byte that will hold the random string. Write a test program that calls your procedure 20 times and displays the strings in the console window.
Solution:
INCLUDE Irvine32.inc
strLen=10
.data
arr BYTE strLen DUP(?)
.code
main PROC
call Clrscr
mov esi, offset arr
mov ecx, 20
L1:
call GenerateRandomString
Loop L1
call WaitMsg
exit
main ENDP
GenerateRandomString PROC USES ecx
mov ecx, lengthOf arr
L2:
mov eax, 26
call RandomRange
add eax, 65
mov [esi], eax
call WriteChar ; write character
loop L2
call Crlf
ret
GenerateRandomString ENDP
END main
strLen=10
.data
arr BYTE strLen DUP(?)
.code
main PROC
call Clrscr
mov esi, offset arr
mov ecx, 20
L1:
call GenerateRandomString
Loop L1
call WaitMsg
exit
main ENDP
GenerateRandomString PROC USES ecx
mov ecx, lengthOf arr
L2:
mov eax, 26
call RandomRange
add eax, 65
mov [esi], eax
call WriteChar ; write character
loop L2
call Crlf
ret
GenerateRandomString ENDP
END main
Let me know in the comment section if you have any question.
Previous Post:
Program to BetterRandomRange Procedure in Assembly Language using Visual Studio