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

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

Step by Step Solution

3.49 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Following is the program in Assembly Language that calls a proc... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Chemistry Questions!