Assembly Language For x86 Processors 7th edition When you write programs to solv
ID: 3605841 • Letter: A
Question
Assembly Language For x86 Processors 7th edition
When you write programs to solve the programming exercises, use multiple procedures when possible. Follow the style and naming conventions used in this book. Use explanatory comments in your programs at the beginning of each procedure and next to nontrivial statements.
Random Strings
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.
Explanation / Answer
;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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.