Assembly language random number generator

I recently started to learn assembly language. For the project I'm working on, I have to create a random number generator using linear congruence. I suppose to take three numbers. The upper bound, the lower bound, and how many random numbers I want. As for the formula for getting a random number, I came up with ....

randomNumber = (seed% (upper lower) + lower)

Then I tried to put this in code. I came up with this

.data
  upper BYTE 100      ;setting upper limit 100
  lower BYTE 0        ;setting lower limit 0
  number BYTE 5       ;number of random numbers

.code
call main
exit

main proc

   cls    
   mov bx,upper            ;moving upper bound into bx
   mov dx,lower            ;moving lower bound into dx
   mov ax,2914017          ;taking a random number for this trial
   mov ecx,number          ;setting the loop counter
L1:
   sub bx,dx               ;(upper-lower)
   div bx               
   add ah,dx               ;(randomNumber mod (bx) + lower

main endp

I am curious how I will print a random number at the end of each cycle of the cycle. And if the above code makes sense.

Thanks in advance!

+3
source share
1 answer

, , .

(, MS-DOS) - SO ( ).

(% - , NASM , , ):

%macro printLn 1
        mov ah, 09h ; 9h means "write a string" on screen
        mov edx, %1
        int 21h ; call the ISR for MS-DOS Services
%endmacro        

[SECTION .text]

mystart:
        printLn string
        ret

[SECTION .data]
string  db      "This is a string of text", 13, 10, '$'

, C-Lib .

ASCII.

, , , , ISR, , . "" . , .

+1

All Articles