The RandomRange procedure from the Irvine32 library generates a pseudorandom integer between 0 and N - 1.
Question:
The RandomRange procedure from the Irvine32 library generates a pseudorandom integer between 0 and N - 1. Your task is to create an improved version that generates an integer between M and N - 1.
Let the caller pass M in EBX and N in EAX. If we call the procedure BetterRandomRange, the following code is a sample test:
mov ebx, -300 ; lower bound
mov eax, 100 ; upper bound
call BetterRandomRange
Write a test program to prompt messages to ask the user for the lower and upper bounds for 3 times. Each time calls BetterRandomRange from a loop that repeats 30 times.
(Following is my code I've worked with)
; //Irvine32 template (irvine32_template.asm)
; //include Irvine32.inc
INCLUDE Irvine32.inc
.data
String byte "Please enter the lower bound: ",0
String1 byte "Please enter the upper bound: ",0
aName BYTE 51 DUP (0)
nameSize dword ?
.code
main PROC
call Randomize
mov edx,OFFSET String
call WriteString
mov edx, OFFSET aName
mov ecx, 50
call ReadString
call crlf
mov edx,OFFSET String1
call WriteString
mov edx, OFFSET aName
mov ecx, 50
call ReadString
call Crlf
mov ecx,30
L1:
mov ebx,-300
mov eax,100
call BetterRandomRange
call crlf
Loop L1
call WaitMsg
exit
main ENDP
BetterRandomRange PROC
sub eax, ebx
call RandomRange
add eax,ebx
call WriteInt
call Crlf
ret
BetterRandomRange ENDP
END main
Organic Chemistry
ISBN: 978-1118133576
11th edition
Authors: Graham Solomons, Craig Fryhle, Scott Snyder