News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

trying to understand randomize and unsigned??

Started by bcddd214, April 22, 2011, 11:20:58 PM

Previous topic - Next topic

bcddd214

The following program is supposed to randomly generate 3 sets of numbers in a specified range and print them out.

I get stuck in an infinite loop for some reason 'but' it appears to be working in one aspect I was SURE it would fail and that is the use of a negative number.
on line 33 I put -5 into eax. This should crash of spit out a horrible number because it is not signed. I would surely think that I would have to do twos-compliment in some manner.

How do I fix the loop and how did I screw up in reverse?

***************************************code**********************************
TITLE Program to generate random numbers              (random1.asm)


INCLUDE Irvine32.inc

COUNT = 10

.data
commaStr BYTE ", ",0

.code
main PROC
   call Clrscr      
   call Randomize      ; random generator
   mov  ecx,COUNT      ; loop counter

L1:   mov  eax,8      ; generate rand int (0..8)
   call RandomRange
   sub  eax,0      ; 0 range
   call WriteInt      ; display the integer
   mov  edx,OFFSET commaStr
   call WriteString
   loop L1
   
L2:   mov  eax,92      ; generate rand int (25..92)
   call RandomRange
   sub  eax,25
   call WriteInt      ; display the integer
   mov  edx,OFFSET commaStr
   call WriteString
   loop L2
   
L3:   mov  eax,-5      ; generate rand int (-5..6) ???There is no way this should work!!!!?????
   call RandomRange
   sub  eax,6
   call WriteInt
   mov  edx,OFFSET commaStr
   call WriteString
   loop L3

   call Crlf

   exit
main ENDP
END main
*******************************************end code****************************

dedndave

   mov  ecx,COUNT      ; loop counter

L1:
;some code
   loop L1


the above code passes through the loop 10 times (COUNT = 10)
after each pass, ECX is one less
when the loop is complete, ECX = 0
at that point, it passes to the next loop...

L2:
;some more code
   loop L2


the problem here is, the loop starts with a value in ECX of 0
loop still works, but it treats that 0 like 4,294,967,296, because it will again decrement ECX until it is 0

so, you need to initialize the loop count register (ECX) at the beginning of each loop

   mov  ecx,COUNT      ; loop counter

L1:
;
loop L1

   mov  ecx,COUNT      ; loop counter

L2:
;
   loop L2

   mov  ecx,COUNT      ; loop counter

L3:
;
   loop L3


or

   mov  ecx,COUNT      ; loop counter
   push ecx

L1:
;
loop L1

   pop  ecx
   push ecx

L2:
;
   loop L2

   pop  ecx

L3:
;
   loop L3

raymond

And even the first loop could run indefinitely depending on how the ECX is used in the RandomRange, WriteInt and Write String procedures.

The "-5" gets treated as a value of 4,294,967,291 by the assembler and would not raise any exception. It may also be treated in the same manner by the RandomRange procedure; without access to it, it's impossible to tell.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dedndave

Ray,
most of Kip's library functions preserve all registers (except EAX), so he is safe, there   :P
in fact, he could put OFFSET commaStr in EDX at the beginning and remove that from the loops
it will be there all the way through - lol
and, you are right about the negative value - it is treated as unsigned

KeepingRealBusy

When calculating random numbers in a specified range, subtract the low bound from the high bound, then generate the random number based on the difference, then add the low bound to the returned random number.


   mov  eax,8               ;    Set the high.
   sub  eax,0                ;    Less the low.
   call RandomRange   ;    Get the random number.
   add  eax,0               ;    Add the low (0 <= ran <= 8).

  ...

   mov  eax,92               ;    Set the high.
   sub  eax,25                ;    Less the low.
   call RandomRange     ;    Get the random number.
   add  eax,25               ;    Add the low (25 <= ran <= 92).


  ...

   mov  eax,10               ;    Set the high (10).
   sub  eax,-50              ;    Less the low (60).
   call RandomRange     ;    Get the random number.
   add  eax,-50              ;    Add the low (-50 <= ran <= 10).


Dave (a different Dave - KeepingRealBusy)

bcddd214

BWUUUUUUUUUUUUUUUUUUUHahahahahahaha

Can you check this code?
I am guessing it is working because it is sending my avg antivirus going nuts.
It says it's a threat???
Stoopid AVG.

But I cannot even run the file.
My antivirus locks it at first attempt..



*******************************new Code**************************

TITLE Program to generate random numbers              (random1.asm)


INCLUDE Irvine32.inc

COUNT = 10

.data
commaStr BYTE ", ",0

.code
main PROC
   call Clrscr      
   call Randomize      ; random generator
   mov  ecx,COUNT      ; loop counter

L1:   mov  eax,8      ; generate rand int (0..8)
   sub  eax,0      ; 0 range
   call RandomRange
   add eax,0
   call WriteInt      ; display the integer
   mov  edx,OFFSET commaStr
   call WriteString
   loop L1
   
mov  ecx,COUNT      ; loop counter
   
L2:   mov  eax,92      ; generate rand int (25..92)
   sub eax,25
   call RandomRange
   add  eax,25
   call WriteInt      ; display the integer
   mov  edx,OFFSET commaStr
   call WriteString
   loop L2
   
mov  ecx,COUNT      ; loop counter
   
L3:   mov  eax,6      ; generate rand int (-5..6) ???There is no way this should work!!!!?????
   sub  eax,-5
   call RandomRange
   add eax,-5
   call WriteInt
   mov  edx,OFFSET commaStr
   call WriteString
   loop L3

   call Crlf

   exit
main ENDP
END main

**********************end code*************************


Why would the antivirus flag this asm program?

dedndave

step 1) remove AVG - it barks at assembly programs all the time - i use Malwarebyte's Anti-Malware
step 2) try this program   :P
        TITLE   Random

;#########################################################

        INCLUDE Irvine32.inc

;#########################################################

RandLoop PROTO  :DWORD,:DWORD

;#########################################################

COUNT   = 10

;#########################################################

        .DATA

commaStr BYTE ", ",0

;#########################################################

        .CODE

RandLoop PROC   dwMinVal:DWORD,dwMaxVal:DWORD

        LOCAL   dwRange:DWORD

        mov     eax,dwMaxVal
        sub     eax,dwMinVal
        mov     dwRange,eax
        mov     edx,OFFSET commaStr
        mov     ecx,COUNT

RLoop0: mov     eax,dwRange       ; generate rand int
        call    RandomRange
        add     eax,dwMinVal
        call    WriteInt          ; display the integer
        call    WriteString
        loop    RLoop0

        ret

RandLoop ENDP

;*********************************************************

main    PROC

        call    Clrscr     
        call    Randomize      ;initialize random generator
        INVOKE  RandLoop,0,8
        INVOKE  RandLoop,25,92
        INVOKE  RandLoop,-5,6
        call    Crlf
        exit

main    ENDP

;#########################################################

        END     main

bcddd214

A small list of questions.
So nice to see clean code with some thought behind it.


Questions are commented in the code!!


        TITLE   Random

        INCLUDE Irvine32.inc

RandLoop PROTO  :DWORD,:DWORD

;#########################################################

COUNT   = 10

;#########################################################

        .DATA

commaStr BYTE ", ",0

;#########################################################

        .CODE
RandLoop PROC   dwMinVal:DWORD,dwMaxVal:DWORD
        LOCAL   dwRange:DWORD
        mov     eax,dwMaxVal   ;you are loading the registers to prepare for the value here?
        sub     eax,dwMinVal   ;you are loading the registers to prepare for the value here?
        mov     dwRange,eax      ;I am confuse because I am not used to seeing more than one thing in a register at a time?
        mov     edx,OFFSET commaStr
        mov     ecx,COUNT
RLoop0: mov     eax,dwRange       ; generate rand int
        call    RandomRange
        add     eax,dwMinVal
        call    WriteInt          ; display the integer
        call    WriteString
        loop    RLoop0
        ret
RandLoop ENDP
main    PROC
        call    Clrscr     
        call    Randomize      ;initialize random generator
        INVOKE  RandLoop,0,8   ;The use of INVOKE here is incremental from RandLoop? Grabs this one first,
        INVOKE  RandLoop,25,92   ;Then this one second
        INVOKE  RandLoop,-5,6   ;and this one last. No more INVOKEs so the loop terminates?
        call    Crlf
        exit

main    ENDP

;#########################################################

        END     main

dedndave

in this code, i calculate the range and store it in a local variable
that way, we don't repeat the same steps in each pass of the loop
notice that the Range = MaxVal - MinVal
1) load EAX with the MaxVal
2) subtract MinVal, now EAX = Range
3) store Range in the local variable named dwRange
        mov     eax,dwMaxVal   ;you are loading the registers to prepare for the value here?
        sub     eax,dwMinVal   ;you are loading the registers to prepare for the value here?
        mov     dwRange,eax      ;I am confuse because I am not used to seeing more than one thing in a register at a time?


INVOKE is like CALL
INVOKE RandLoop,0,8 generates the following code
        push    8
        push    0
        call    RandLoop

then, the PROC directive for RandLoop tells the routine how to find the parameters on the stack
        INVOKE  RandLoop,0,8   ;The use of INVOKE here is incremental from RandLoop? Grabs this one first,
        INVOKE  RandLoop,25,92   ;Then this one second
        INVOKE  RandLoop,-5,6   ;and this one last. No more INVOKEs so the loop terminates?

the loop code is inside the RandLoop proc
you can place any two values on the INVOKE line and it will do the same thing using those values as min and max
if you want to see just one call, comment out the other two INVOKE's
that may help you get a better understanding for how it works
;        INVOKE  RandLoop,0,8
        INVOKE  RandLoop,25,92
;        INVOKE  RandLoop,-5,6


oh - did the program work correctly ?

bcddd214

YES YOU DID SIR!
:)

And now I am tinkering a little bit more.

I put in a second loop. I am trying to now do a random column down, actually a pair and then add them.
I am getting some crazy numbers and I am following your rule to plug them into a variable.
I am missing something..?

        TITLE   Random

        INCLUDE Irvine32.inc

RandLoop PROTO  :DWORD,:DWORD
RandLoop2 PROTO  :DWORD,:DWORD

;#########################################################

COUNT   = 10

;#########################################################

        .DATA

commaStr BYTE ", ",0
str1 BYTE "Total=  ",0

;#########################################################

        .CODE
RandLoop PROC   dwMinVal:DWORD,dwMaxVal:DWORD
        LOCAL   dwRange:DWORD
        mov     eax,dwMaxVal   
        sub     eax,dwMinVal   
        mov     dwRange,eax
        mov     edx,OFFSET commaStr
        mov     ecx,COUNT

RLoop0: mov     eax,dwRange       ; generate rand int
        call    RandomRange
        add     eax,dwMinVal
        call    WriteInt          ; display the integer
        call    WriteString
        loop    RLoop0
        ret
RandLoop ENDP

;second loop begins here to count to random colums down
RandLoop2 PROC   dwMinVal2:DWORD,dwMaxVal2:DWORD
        LOCAL   dwRange2:DWORD,dwRange3:DWORD
        mov     eax,dwMaxVal2
        sub     eax,dwMinVal2
        mov     dwRange2,eax
        mov     edx,OFFSET commaStr
        mov     ecx,COUNT
      
RLoop1:   mov     eax,dwRange2       ; generate rand int
        call    RandomRange
        add     eax,dwMinVal2
        call    WriteInt          ; display the integer
        call    WriteString

;My problem starts right here. I want to produce a second colum and then add the first
;two colums and produce thier total in a third.
      mov     eax,dwRange3       ; generate rand int
      call    RandomRange
      add     eax,dwMinVal2
                call    WriteInt          ; display the integer
                call    WriteString
      add      eax,dwRange3
      call    WriteInt          ; display the integer
      call    WriteString
;anything I put here to do a basic math function of adding eax and ebx together fails miserably??

      call    Crlf
        loop    RLoop1
        ret
RandLoop2 ENDP
      
main    PROC
        call    Clrscr     
        call    Randomize      ;initialize random generator
        INVOKE  RandLoop,0,8   
        INVOKE  RandLoop,25,92   
        INVOKE  RandLoop,-5,6   
      INVOKE  RandLoop2,1,6
        call    Crlf
        exit

main    ENDP

;#########################################################

        END     main

mineiro

        TITLE   Random
        INCLUDE Irvine32.inc
RandLoop PROTO  :DWORD,:DWORD,:DWORD

.DATA
str1 BYTE "Total=  ",0
commaStr BYTE ", ",0
show_sum byte "the sum is: ",0

        .CODE
RandLoop PROC   dwMinVal:DWORD,dwMaxVal:DWORD,COLUMN:DWORD
;this function show in screen some random number in columns
;return in eax the sum of these numbers
LOCAL   dwRange:DWORD
LOCAL VALUE_FINAL:DWORD

mov VALUE_FINAL,0 ;we initialize this variable with zero
cmp COLUMN,0 ;zero columns?
JE DO_NOTHING ;so do nothing
        mov     eax,dwMaxVal
        sub     eax,dwMinVal
        mov     dwRange,eax
        mov     edx,OFFSET commaStr
        mov     ecx,COLUMN
RLoop0:
mov     eax,dwRange
        call    RandomRange
        add     eax,dwMinVal
add [VALUE_FINAL],eax ;first moment the value_final is zero, second moment is ????????
        call    WriteInt
        call    WriteString
        loop    RLoop0
        mov eax,VALUE_FINAL ;and after we show the sum of the numbers
DO_NOTHING:
        ret
RandLoop ENDP

main    PROC
        call    Clrscr     
        call    Randomize
        INVOKE  RandLoop,0,8,0 ;0 columns, so don't do nothing
call Crlf       
        INVOKE  RandLoop,0,8,1 ;1 colum
call Crlf
        INVOKE  RandLoop,25,92,4 ;4 columns
push eax ;we save the returned value
mov edx,offset show_sum
call WriteString
pop eax ;now, we get it back
call WriteInt
call Crlf
        INVOKE  RandLoop,-5,6,8 ;8 columns
    call Crlf
        exit
main    ENDP
        END     main



        TITLE   Random
        INCLUDE Irvine32.inc
RandLoop PROTO  :DWORD,:DWORD,:DWORD

.DATA
str1 BYTE "Total=  ",0
commaStr BYTE ", ",0

        .CODE
RandLoop PROC   dwMinVal:DWORD,dwMaxVal:DWORD,COLUMN:DWORD
;this procedure show X columns of random value betwen dwMinVal and dwMaxVal
;this procedure add one colum to show the sum of values
        LOCAL   dwRange:DWORD
LOCAL VALUE_FINAL:DWORD

mov VALUE_FINAL,0 ;we initialize this variable with zero
cmp COLUMN,0 ;zero columns?
JE DO_NOTHING ;so do nothing
        mov     eax,dwMaxVal
        sub     eax,dwMinVal
        mov     dwRange,eax
        mov     edx,OFFSET commaStr
        mov     ecx,COLUMN
RLoop0:
mov     eax,dwRange
        call    RandomRange
        add     eax,dwMinVal
add [VALUE_FINAL],eax ;first moment the value_final is zero, second moment is ????????
        call    WriteInt
        call    WriteString
        loop    RLoop0
mov edx, offset str1 ;we show the "total= "
        call    WriteString
        mov eax,VALUE_FINAL ;and after we show the sum of the numbers
        call WriteInt
        call    Crlf ;an enter in the end of column

DO_NOTHING:
        ret
RandLoop ENDP

main    PROC
        call    Clrscr     
        call    Randomize
        INVOKE  RandLoop,0,8,0 ;0 columns, so do not show
        INVOKE  RandLoop,0,8,1 ;1 colum
        INVOKE  RandLoop,25,92,4 ;4 columns
        INVOKE  RandLoop,-5,6,8 ;8 columns
        exit

main    ENDP
        END     main

try these two bcddd214, you are make good progress, keep walking.
I have seen your procedure, and you forgot some thing:
mov     eax,dwRange3      ;in this line, you forgot to start the dwRange3 variable


bcddd214

SOOOOO CLOSE!!!!

My RLoop1 does not seem to want to kick out at the end of adding '2'/'two' numbers.
It wants to add up all the way to the end?


***********************************************
        TITLE   Random

        INCLUDE Irvine32.inc

RandLoop PROTO  :DWORD,:DWORD
RandLoop2 PROTO  :DWORD,:DWORD,:DWORD

;#########################################################

COUNT   = 10

;#########################################################

        .DATA

commaStr BYTE ", ",0
str1 BYTE "Total=  ",0

;#########################################################

        .CODE
RandLoop PROC   dwMinVal:DWORD,dwMaxVal:DWORD
        LOCAL   dwRange:DWORD
        mov     eax,dwMaxVal   ;you are loading the registers to prepare for the value here?
        sub     eax,dwMinVal   ;you are loading the registers to prepare for the value here?
        mov     dwRange,eax      ;I am confuse because I am not used to seeing more than one thing in a register at a time?
        mov     edx,OFFSET commaStr
        mov     ecx,COUNT

RLoop0: mov     eax,dwRange       ; generate rand int
        call    RandomRange
        add     eax,dwMinVal
        call    WriteInt          ; display the integer
        call    WriteString
        loop    RLoop0
      call    Crlf
      call    Crlf
        ret
RandLoop ENDP

;second loop begins here to count to random colums down
RandLoop2 PROC   dwMinVal2:DWORD,dwMaxVal2:DWORD,COLUMN:DWORD
        LOCAL   dwRange2:DWORD,VALUE_FINAL:DWORD
      mov VALUE_FINAL,0 ;we initialize this variable with zero
      cmp COLUMN,0 ;zero columns?
      JE DO_NOTHING ;so do nothing
      mov     eax,dwMaxVal2
        sub     eax,dwMinVal2
        mov     dwRange2,eax
      mov     edx,OFFSET commaStr
        mov     ecx,COLUMN
      
RLoop1:   ;This loop is suppoed to add 2 random numbers side by side and display total next to it THEN return to next line???
      mov     eax,dwRange2       ; generate rand int
        call    RandomRange
        add     eax,dwMinVal2
      add [VALUE_FINAL],eax
        call    WriteInt          ; display the integer
        call    WriteString
      ;when INVOKE runs out, it will exit the loop
      loop RLoop1
      
      mov edx, offset str1 ;we show the "total= "
        call    WriteString
        mov eax,VALUE_FINAL ;and after we show the sum of the numbers
        call WriteInt
        call    Crlf ;an enter in the end of column
      
DO_NOTHING:
        ret
RandLoop2 ENDP

main    PROC
        call    Clrscr     
        call    Randomize      ;initialize random generator
        INVOKE  RandLoop,0,8   ;The use of INVOKE here is incremental from RandLoop? Grabs this one first,
        INVOKE  RandLoop,25,92   ;Then this one second
        INVOKE  RandLoop,-5,6   ;and this one last. No more INVOKEs so the loop terminates?
      INVOKE  RandLoop2,1,6,8
        call    Crlf
        exit

main    ENDP

;#########################################################

        END     main

bcddd214

I am discovering the hard way that INVOKE directly correlates with the number of dword variables declared in PROC?

on line 86, INVOKE declares RandLoop2 with 3 digits. The third one does not need to be there?
The program almost craps at assemble time as is. I am close, but still missing something


*************************************************************
        TITLE   Random

        INCLUDE Irvine32.inc

RandLoop PROTO  :DWORD,:DWORD
RandLoop2 PROTO  :DWORD,:DWORD,:DWORD

;#########################################################

COUNT   = 10

;#########################################################

        .DATA

commaStr BYTE ", ",0
str1 BYTE "Total=  ",0

;#########################################################

        .CODE
RandLoop PROC   dwMinVal:DWORD,dwMaxVal:DWORD
        LOCAL   dwRange:DWORD
        mov     eax,dwMaxVal   ;you are loading the registers to prepare for the value here?
        sub     eax,dwMinVal   ;you are loading the registers to prepare for the value here?
        mov     dwRange,eax      ;I am confuse because I am not used to seeing more than one thing in a register at a time?
        mov     edx,OFFSET commaStr
        mov     ecx,COUNT

RLoop0: mov     eax,dwRange       ; generate rand int
        call    RandomRange
        add     eax,dwMinVal
        call    WriteInt          ; display the integer
        call    WriteString
        loop    RLoop0
      call    Crlf
      call    Crlf
        ret
RandLoop ENDP

;second loop begins here to count to random colums down
RandLoop2 PROC   dwMinVal2:DWORD,dwMaxVal2:DWORD,COLUMN:DWORD
        LOCAL   dwRange2:DWORD,VALUE_FINAL:DWORD
      mov VALUE_FINAL,0 ;we initialize this variable with zero
      cmp COLUMN,0 ;zero columns?
      JE DO_NOTHING ;so do nothing
      mov     eax,dwMaxVal2
        sub     eax,dwMinVal2
        mov     dwRange2,eax
      mov     edx,OFFSET commaStr
        mov     ecx,COLUMN
      
RLoop1:   
      mov     eax,dwRange2       ; generate rand int
        call    RandomRange
      call    WriteInt
      mov      ebx,eax
;      mov      ebx,dwMinVal2
      call    RandomRange
      call    WriteInt
        add     eax,ebx
      call DumpRegs
;      add [VALUE_FINAL],eax
;        call    WriteInt          ; display the integer
      ;when INVOKE runs out, it will exit the loop      
      
      mov edx, offset str1 ;we show the "total= "
;      mov eax,VALUE_FINAL ;and after we show the sum of the numbers
      call    WriteString

      ;      mov eax,VALUE_FINAL ;and after we show the sum of the numbers
      call WriteInt
      call Crlf ;an enter in the end of column
   loop RLoop1
   
DO_NOTHING:
        ret
RandLoop2 ENDP

main    PROC
        call    Clrscr     
        call    Randomize      ;initialize random generator
        INVOKE  RandLoop,0,8   ;The use of INVOKE here is incremental from RandLoop? Grabs this one first,
        INVOKE  RandLoop,25,92   ;Then this one second
        INVOKE  RandLoop,-5,6   ;and this one last. No more INVOKEs so the loop terminates?
      INVOKE  RandLoop2,1,6,9
        call    Crlf
        exit

main    ENDP

;#########################################################

        END     main

dedndave

i think what you really want in RandLoop2 is to add another local variable, not another parameter on the PROC line
parameters are passed to the routine by the INVOKE
local variables are just temporary values stored internally by the routine

although, i am not really sure what you are trying to do with COLUMN   :P

when i showed you what code was generated by the assembler for INVOKE, that was fairly simple
understanding the code that is generated to make the routine is a bit more complicated
i didn't want to throw that at you, yet, because i didn't want to confuse you

it may be best for you to learn a little more about registers, data, etc before delving into stack frames   :P

EDIT - ok - i think i see what you were trying to do
you do want to pass another parameter
but, i don't understand the rest of the modifications to that routine

bcddd214

I think I figured it out.
I went back to what you had sent earlier and took a good long look at it.
1 question and one possible solution.

Question 1
It looks like I have this doing more or less what I want it to but I want to have it do 9 more lines like the last.
Just like the RandLoop.

Should I just turn everything from the PROC definition to the end of RandLoop2 as a procedure of RandLoop?



        TITLE   Random

        INCLUDE Irvine32.inc

RandLoop PROTO  :DWORD,:DWORD
RandLoop2 PROTO  :DWORD,:DWORD,:DWORD

;#########################################################

COUNT   = 10
COUNT2   = 2
;#########################################################

        .DATA

commaStr BYTE ", ",0
str1 BYTE "Total=  ",0

;#########################################################

        .CODE
RandLoop PROC   dwMinVal:DWORD,dwMaxVal:DWORD
        LOCAL   dwRange:DWORD
        mov     eax,dwMaxVal   ;you are loading the registers to prepare for the value here?
        sub     eax,dwMinVal   ;you are loading the registers to prepare for the value here?
        mov     dwRange,eax      ;I am confuse because I am not used to seeing more than one thing in a register at a time?
        mov     edx,OFFSET commaStr
        mov     ecx,COUNT

RLoop0: mov     eax,dwRange       ; generate rand int
        call    RandomRange
        add     eax,dwMinVal
        call    WriteInt          ; display the integer
        call    WriteString
        loop    RLoop0
      call    Crlf
      call    Crlf
        ret
RandLoop ENDP

;second loop begins here to count to random colums down
RandLoop2 PROC   dwMinVal2:DWORD,dwMaxVal2:DWORD,COLUMN:DWORD
;this procedure show X columns of random value betwen dwMinVal and dwMaxVal
;this procedure add one colum to show the sum of values
        LOCAL   dwRange2:DWORD
LOCAL VALUE_FINAL:DWORD

mov VALUE_FINAL,0 ;we initialize this variable with zero
;cmp COLUMN,0 ;zero columns?
;mov COUNT2,0 ;set count2 to zero
JE DO_NOTHING ;so do nothing
        mov     eax,dwMaxVal2
        sub     eax,dwMinVal2
        mov     dwRange2,eax
        mov     edx,OFFSET commaStr
;        mov     ecx,COLUMN
      mov     ecx,COUNT2
RLoop1:
mov     eax,dwRange2
        call    RandomRange
        add     eax,dwMinVal2
add [VALUE_FINAL],eax ;first moment the value_final is zero, second moment is ????????
        call    WriteInt
        call    WriteString
        loop    RLoop1
mov edx, offset str1 ;we show the "total= "
        call    WriteString
        mov eax,VALUE_FINAL ;and after we show the sum of the numbers
        call WriteInt
        call    Crlf ;an enter in the end of column

DO_NOTHING:
        ret
RandLoop2 ENDP


main    PROC
        call    Clrscr     
        call    Randomize      ;initialize random generator
        INVOKE  RandLoop,0,8   ;The use of INVOKE here is incremental from RandLoop? Grabs this one first,
        INVOKE  RandLoop,25,92   ;Then this one second
        INVOKE  RandLoop,-5,6   ;and this one last. No more INVOKEs so the loop terminates?
      INVOKE  RandLoop2,1,6,9
        call    Crlf
        exit

main    ENDP

;#########################################################

        END     main