Pseudorandom generator in Assembly Language

前端 未结 9 1024
予麋鹿
予麋鹿 2021-01-05 11:07

I need a pseudorandom number generator algorithm for a assembler program assigned in a course, and I would prefer a simple algorithm. However, I cannot use an external libra

9条回答
  •  执笔经年
    2021-01-05 11:46

    Using masm615 to compiler:

    delay_function macro
        mov cx,0ffffh
    .repeat
        push cx
        mov cx,0f00h
        .repeat
            dec  cx
            .until cx==0
        pop cx
        dec cx
        .until cx==0
    endm
    
    random_num macro
       mov  cx,64    ;assum we want to get 64 random numbers
       mov  si,0
    
    get_num:    
       push cx
       delay_function    ;since cpu clock is fast,so we use delay_function
       mov  ah,2ch  
       int  21h
       mov  ax,dx     ;get clock 1/100 sec
       div  num       ;assume we want to get a number from 0~num-1
       mov  arry[si],ah   ;save to array you set
       inc  si
       pop  cx
       loop get_num   ;here we finish the get_random number 
    

提交回复
热议问题