Note that there are some explanatory texts on larger screens.

plurals
  1. POAssembly Random Number Using Irvine
    primarykey
    data
    text
    <p>When I implement the random number generator procedure that was provided for us in Assembly, half the time it gives me a division by zero error and the other half of the time it works perfectly. I believe that I am implementing the code properly, but will provide you how I have it written. </p> <pre><code>randomCompNum PROC call Randomize ;Sets seed mov eax,10 ;Keeps the range 0 - 9 call RandomRange mov compNum1,eax ;First random number L1: call RandomRange .IF eax == compNum1 ;Checks if the second number is the same as the first jmp L1 ;If it is, repeat call .ENDIF mov compNum2,eax ;Second random number L2: call RandomRange .IF eax == compNum1 ;Checks if the third number is the same as the first jmp L2 ;If it is, repeat .ELSEIF eax == compNum1 ;Checks if the third number is the same as the second jmp L2 ;If it is, repeat .ENDIF mov compNum3,eax ;Third random number stored ret randomCompNum ENDP </code></pre> <hr> <p>Here's the disassembly for RandomRange that Visual Studios provided me</p> <pre><code>_RandomRange@0: 004019C1 push ebx 004019C2 push edx 004019C3 mov ebx,eax 004019C5 call _Random32@0 (4019A6h) ;&lt;---- This function doesn't touch ebx 004019CA mov edx,0 004019CF div eax,ebx ;&lt;---- That's where the error occurs 004019D1 mov eax,edx 004019D3 pop edx 004019D4 pop ebx 004019D5 ret </code></pre> <p>Do you know what could be causing this error? </p> <p>I'm tempted to just create my own random number generator.</p> <p><strong>Background on the RandomRange method:</strong> It's simple. You set the seed with Randomize, moving 10 into eax keeps the RandomRange between 0 - 9. That's all the documentation I could find for that function, so that's all I believe there is about it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload