Question: Using SASM: Random-Example file: This lab will use the library functions that allow us to generate random numbers in Assembler. There are two types of
Using SASM:

Random-Example file:

This lab will use the library functions that allow us to generate random numbers in Assembler. There are two types of random functions. The first is named random 32 that generates a number from 0 to 4,294,967,295 which is not really practical in general terms. The other is named randomrange which generates a random number between 0 and the value in register EAX minus 1. This is the function we will use regularly in our course. 1. Open the SASM IDE and create a new file. Remove any old code created by SASM. 2. Download and type the contents of the file Random-Example in this new file. It would be helpful to also read the comments as they help understand how the instructions work. Note: The procedure named randomize on line 30 must be called prior to using the other generators. It is required to initialize the seed just as in CH. It is done only once in any program. 3. You may type my program to see how it works and when it's done change the program so that it generates two random numbers satisfying the following conditions: a) The first number, N1 ranging from 17 - 62 and store it in a variable named number1 b) The second number, N2 ranging from 23 28 and store it in a variable named number2 4. Using the previous labs write the code to add the two randomly generated numbers above and output the following message, where #N1, #N2, and #sum are the first and second random numbers and its respective sum. Confirm the random numbers and the sum is correct. The sum of #N1 and #N2 is: #sum The code generates a random number from 1 - 100 but also initializes the seed : Library for I/0 and other purposes 2 3 4 5 6 7 8 9 10 Include c: asmio asm32.inc includelib c:asnio asm32.lib inclucielib c:asmio user32.lib includelib c:asmio kernel32.lib ; Need these two files for SASM with I/O ; Need these two files for SASM with I/O 12 13 14 1.5 16 17 18 .Const NULL nin max eoul egu etu 1 100 Constant i Constant 1 100 ; Uninitialized data section .data? rumb data dword ? 20 byte byte byte ; strings must be null terminated! "A random number from", NULL " to ", NULL is: , NULL msal mag2 msg3 : . code 90 22 23 24 25 26 27 28 main proc i Start of the main procedure 30 31 32 33 Random generating code: we need to start the seed at the current time ; call Randomize ; Sets the seed - MUST BE DONE ONCE!! call Randon32 Finds A random number and puts it in EAX call writeDec ; Not good for our purposes call crlf skip a line 34 ; RandomRange returns in EAX a value from 0 - (EAX-1): configure it for [a, b] 35 36 37 38 39 mov call add call call eax, Max RandomRange eax, nin WriteDec crlf ; FAX = 100 i generate 0 - 99 shifted: 1 - 100 40 41 i skip a line 43 44 45 ; Create code for a generic range such as a number from 17 - 67? Change the constants The final number will be in register EAX ; Enter the new code here 47 48 49 50 51 52 53 54 ; Prepare proper output : mov edx, OFFSET mag1 call WriteString mov eax, min call Write Dec ; String must be in edx ; NOT CASE SENSITIVE Best not to have sign mov call mov call edx, OFFSET msg2 WriteString eax, max Write Dec 56 57 58 59 60 62 62 63 mov call edx, OFFSET msg3 WriteString ret main end end i Must always reto ; End of main procedure End of program 66 main 67 68 This lab will use the library functions that allow us to generate random numbers in Assembler. There are two types of random functions. The first is named random 32 that generates a number from 0 to 4,294,967,295 which is not really practical in general terms. The other is named randomrange which generates a random number between 0 and the value in register EAX minus 1. This is the function we will use regularly in our course. 1. Open the SASM IDE and create a new file. Remove any old code created by SASM. 2. Download and type the contents of the file Random-Example in this new file. It would be helpful to also read the comments as they help understand how the instructions work. Note: The procedure named randomize on line 30 must be called prior to using the other generators. It is required to initialize the seed just as in CH. It is done only once in any program. 3. You may type my program to see how it works and when it's done change the program so that it generates two random numbers satisfying the following conditions: a) The first number, N1 ranging from 17 - 62 and store it in a variable named number1 b) The second number, N2 ranging from 23 28 and store it in a variable named number2 4. Using the previous labs write the code to add the two randomly generated numbers above and output the following message, where #N1, #N2, and #sum are the first and second random numbers and its respective sum. Confirm the random numbers and the sum is correct. The sum of #N1 and #N2 is: #sum The code generates a random number from 1 - 100 but also initializes the seed : Library for I/0 and other purposes 2 3 4 5 6 7 8 9 10 Include c: asmio asm32.inc includelib c:asnio asm32.lib inclucielib c:asmio user32.lib includelib c:asmio kernel32.lib ; Need these two files for SASM with I/O ; Need these two files for SASM with I/O 12 13 14 1.5 16 17 18 .Const NULL nin max eoul egu etu 1 100 Constant i Constant 1 100 ; Uninitialized data section .data? rumb data dword ? 20 byte byte byte ; strings must be null terminated! "A random number from", NULL " to ", NULL is: , NULL msal mag2 msg3 : . code 90 22 23 24 25 26 27 28 main proc i Start of the main procedure 30 31 32 33 Random generating code: we need to start the seed at the current time ; call Randomize ; Sets the seed - MUST BE DONE ONCE!! call Randon32 Finds A random number and puts it in EAX call writeDec ; Not good for our purposes call crlf skip a line 34 ; RandomRange returns in EAX a value from 0 - (EAX-1): configure it for [a, b] 35 36 37 38 39 mov call add call call eax, Max RandomRange eax, nin WriteDec crlf ; FAX = 100 i generate 0 - 99 shifted: 1 - 100 40 41 i skip a line 43 44 45 ; Create code for a generic range such as a number from 17 - 67? Change the constants The final number will be in register EAX ; Enter the new code here 47 48 49 50 51 52 53 54 ; Prepare proper output : mov edx, OFFSET mag1 call WriteString mov eax, min call Write Dec ; String must be in edx ; NOT CASE SENSITIVE Best not to have sign mov call mov call edx, OFFSET msg2 WriteString eax, max Write Dec 56 57 58 59 60 62 62 63 mov call edx, OFFSET msg3 WriteString ret main end end i Must always reto ; End of main procedure End of program 66 main 67 68
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
