Advertisement
nontawat1996

random.asm - Computer Organization

Feb 16th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;random.asm            Designed and written by Wilson Seto
  2.       page   60,130
  3. cseg      segment
  4.       assume cs:cseg, ds:cseg
  5.       assume es:cseg, ss:cseg
  6.       org    100h
  7. start:    jmp    short check
  8. ;---------TSR routine-----------------------------------------------------------
  9. constant  dw     8405h             ;multiplier value
  10. seed1     dw     ?
  11. seed2     dw     ?             ;random number seeds
  12. int_62h   proc   far
  13.       or     ax,ax             ;range value <> 0?
  14.       jz     abort             ;if not then abort
  15.       push   bx
  16.       push   cx
  17.       push   dx
  18.       push   ds
  19.       push   ax            ;save the range value
  20.       push   cs
  21.       pop    ds            ;ds = cs
  22.       mov    ax,seed1
  23.       mov    bx,seed2          ;load seeds
  24.       mov    cx,ax             ;save seed
  25.       mul    constant          ;(dx,ax) = ax * constant
  26.       shl    cx,1
  27.       shl    cx,1
  28.       shl    cx,1
  29.       add    ch,cl
  30.       add    dx,cx
  31.       add    dx,bx
  32.       shl    bx,1              ;begin scramble algorithm
  33.       shl    bx,1
  34.       add    dx,bx
  35.       add    dh,bl
  36.       mov    cl,5
  37.       shl    bx,cl
  38.       add    ax,1
  39.       adc    dx,0
  40.       mov    seed1,ax
  41.       mov    seed2,dx          ;save results as the new seeds
  42.       pop    bx            ;get back range value
  43.       xor    ax,ax             ;clear register
  44.       xchg   ax,dx             ;adjust ordering
  45.       div    bx            ;ax = trunc((dx,ax) / bx), dx = (r)
  46.       xchg   ax,dx             ;return remainder as the random number
  47.       pop    ds
  48.       pop    dx
  49.       pop    cx
  50.       pop    bx
  51. abort:    iret                 ;return to caller
  52. int_62h   endp
  53. ;-------------------------------------------------------------------------------
  54.  
  55. ;---------Initialization routine------------------------------------------------
  56. check:    mov    ax,3000h          ;get DOS version
  57.       int    21h
  58.       cmp    al,3              ;DOS version 3.0 or higher?
  59.       jae    chk_vec
  60.       mov    dx,offset wrong_dos   ;incorrect DOS version, inform user
  61. quit:     mov    ah,9
  62.       int    21h
  63.       int    20h               ;back to DOS
  64. chk_vec:  mov  ax,3562h        ;get interrupt vector for int 62h - es:bx
  65.       int    21h
  66.     mov  di,bx           ;es:di points to int 62h
  67.     mov  si,offset int_62h     ;point to our copy of int 62h
  68.       mov    cx,16             ;# of bytes to compare
  69.       cld                  ;forward string movement
  70.       repe   cmpsb             ;compare memory regions
  71.       jnz    install           ;if not identical then not installed
  72.       mov    dx,offset loaded      ;already loaded, inform user
  73.       jmp    short quit
  74. install:  mov    ah,2ch            ;get current time
  75.       int    21h
  76.       mov    seed1,cx
  77.       mov    seed2,dx          ;save as initial seeds
  78.       mov    dx,offset ready
  79.       mov    ah,9              ;print ready message
  80.       int    21h
  81.     mov  dx,offset int_62h     ;point to routine to install - ds:dx
  82.     mov  ax,2562h        ;change interrupt 62h vectors
  83.       int    21h
  84.       mov    dx,offset check       ;end of resident code
  85.       int    27h               ;TSR
  86. ;-------------------------------------------------------------------------------
  87.  
  88.  
  89.  
  90.  
  91. ;---------Data area-------------------------------------------------------------
  92. wrong_dos db     13,10,10,'Requires DOS V3.0 or higher!',13,10,10,7,7,36
  93. loaded      db     13,10,10,'Random number generator is already loaded.'
  94.           db     13,10,10,7,7,36
  95. ready       db     13,10,10,'Random number generator V1.1 loaded.',13,10,10,36
  96. ;-------------------------------------------------------------------------------
  97. cseg      ends
  98.       end    start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement