Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 18th, 2010 | Syntax: ASM (NASM) | Size: 1.26 KB | Hits: 85 | Expires: Never
Copy text to clipboard
  1. .model small
  2. .386
  3. .stack 200h
  4. .data
  5.     c       dd  1013904223
  6.     a       dd  1664525
  7.     seed    dd  ?
  8.     text    db  'Initial random seed: $'
  9.  
  10. .code
  11. start:
  12.     mov     ax, @data
  13.     mov     ds, ax
  14.  
  15.     mov     dx, offset text
  16.     mov     ah, 9h
  17.     int     21h
  18.  
  19.     call    Randomize
  20.     call    Print
  21.  
  22.     mov     cx, 20
  23.  
  24. main_loop:
  25.     push    cx
  26.     call    Random
  27.     shr     eax, 24
  28.     call    Print
  29.     pop     cx
  30.     dec     cx
  31.     jnz     main_loop
  32.  
  33.     mov     ax, 4c00h
  34.     int     21h
  35.  
  36. Randomize proc
  37.     mov     ah, 2ch
  38.     int     21h
  39.     mov     bx, dx
  40.     shl     ebx, 16
  41.     mov     bx, cx
  42.     mov     seed, ebx
  43.     mov     eax, ebx
  44.     ret
  45. Randomize endp
  46.  
  47. Random proc
  48.     xor     edx, edx
  49.     mov     eax, seed
  50.     mul     a
  51.     add     eax, c
  52.     mov     seed, eax
  53.     ret
  54. Random endp
  55.  
  56. Print proc
  57.     mov     ebx, 10
  58.     xor     cx,cx
  59.  
  60. print_calc:
  61.     xor     edx, edx
  62.     div     ebx
  63.     push    dx
  64.     inc     cx
  65.     test    eax, eax
  66.     jnz     print_calc
  67.  
  68.     mov     ah, 2h
  69.  
  70. print_out:
  71.     pop     dx
  72.     add     dl, '0'
  73.     int     21h
  74.     dec     cx
  75.     jnz     print_out
  76.  
  77.     mov     dl, 13
  78.     int     21h
  79.     mov     dl, 10
  80.     int     21h
  81.  
  82.     ret
  83. Print endp
  84.  
  85. end start