A89: Re: Assembly-89 Digest V1 #715
[Prev][Next][Index][Thread]
A89: Re: Assembly-89 Digest V1 #715
>Date: Sun, 11 Apr 1999 00:07:55 EDT
>Date: Sun, 11 Apr 1999 00:36:18 EDT
>From: ZeromusMog@aol.com
>Subject: Re: A89: Random number help
>
>In a message dated 4/10/99 1:41:28 PM Pacific Daylight Time,
>bentensai@yahoo.com writes:
>
>> You can userlib::random
>> Here is an example.
>>
>> you can write your question before this and this will
>> send you randomly to an answer.
>>
>> move.w #14,d0 ;uperlimit of random number
>> jsr userlib::random :put's a random number 0<x<14
>> in d0.
>> cmp.w #0,d0 ; 0 is lowest number that can be gotten
>> beq answer1 ; branches to answer one.
>> cmp.w #1,d0 ; check to see if one
>> beq answer2 ; goes to answer two.
>> And so on until it is 14. I hope this helps.
>
>Wouldn't some form of lookup table be more efficient?
>::Runs away before he gets caught talking about things above his head::
Depends - If there's a different routine for every number, then it would.
If you're just checking for a couple numbers and execute some default code
if it's any other number (an ELSE label, essentially), then no. If you want
a lookup table, try this:
RandomCheck:
move.w #14,d0
jsr userlib::random
;Random number is now in d0
;
;Since all the addresses in
;the table are 4 bytes
;(1 londword), we must
;multiply this number by 4
lsl.l #2,d0 ;Shifting left 2 = mulu #4,d0
lea RandomTable(PC),a0 ;address of table in a0
add.l d0,a0 ;Now points to proper label
bra (a0)
RandomTable:
dc.l Random0 ;These all correspond
dc.l Random1 ;to the labels to jump
dc.l Random2 ;to for their number
dc.l Random3
dc.l Random4 ;They can be replaced
dc.l Random5 ;With any label name
dc.l Random6
dc.l Random7
dc.l Random8
dc.l Random9
dc.l Random10
dc.l Random11
dc.l Random12
dc.l Random13
dc.l Random14
-Scott Noveck (SMN)
smn@calc.org
Lead Programmer:
Pokemon - Zelda 89
http://ccia.calc.org
Follow-Ups: