Digital Stronghold

September 6, 2006

Random number generator in 16-bit DOS assembly

Filed under: Progressive Studies

Most code for randomizing is not as short as this one. Try to incorporate this procedure in your code and see how it works!

randomize:
        in al, 40h	; read micro-clock for initial seed
        mov ah, al
        in al, 40h
        xchg al, ah
        or ax, 1
        mov rnum, ax
ret

Random number will be stored in rnum. Fairly straightforward isn’t it?

[Edit]

Here’s another solution by sir Eugene Kanindot. This is a 3-digit random number generator.

jmp start
	
xxx:
mov ah, 02ch
int 21h
and dl, 0fh
cmp dl, 9
ja xxx
add dl, 30h
mov [di], dl
ret
	
delay:
mov cx, 0
	
yyy:
mov dx, 0a00h
	
zzz:
xor ax, ax
dec dx
cmp dx, 0
jne zzz
	
loop yyy
ret
	
start:
lea di, numb
call xxx
inc di
call delay
call xxx
inc di
call delay
call xxx
mov ah, 09h
lea dx, numb
int 21h
int 20h
	
numb db 4 dup('$')

Comments »

The URI to TrackBack this entry is: http://eradicus.blogsome.com/2006/09/06/random-number-generator-in-16-bit-dos-assembly/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Theme designed by Joset Anthony Zamora