It is currently Wed Jun 03, 2020 4:13 am

 All times are UTC

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: guess numberPosted: Fri May 02, 2014 5:15 pm

Joined: Fri May 02, 2014 5:02 pm
Posts: 2
pls help me write this program:
first specify the number range, generates a random number from the range, the player then has to guess that random number, the program than indicates whether the correct answer, bigger or smaller. after correctly guessing the number, marks are awarded according to no of attempts and time taken to get the correct answer.

Top

 Post subject: Re: guess numberPosted: Fri May 02, 2014 5:59 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
We do not answer homework questions on this forum. That would defeat their entire purpose. Approach this as you would any programming assignment: create a flowchart or pseudocode representation of the program algorithm, code the program using clear well documented code, test, test, test, repeat as necessary.

_________________
Prof. Kelly

Top

 Post subject: Re: guess numberPosted: Wed May 07, 2014 2:45 pm

Joined: Fri May 02, 2014 5:02 pm
Posts: 2
i'm trying to modify your tutorial2 code, but i have no idea how to generate a random number for a specific range for example 50 to 140, is it possible??? please help me with this part.

Top

 Post subject: Re: guess numberPosted: Wed May 07, 2014 6:13 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
From Tutorial 2
Code:
* Generate random number for player to guess
* Uses timer as random number generator. This may not be the best way to
* generate a random number but it will work for this demonstration.
* Trap code 8 returns time in hundredths of a second since midnight in D1.L

move.b  #8,d0
trap    #15
and.l   #\$5FFFFF,d1     prevent overflow in divu
divu    #100,d1         time count / 100
swap    d1              swap upper and lower words of D1 to put remainder in low word
addq.w  #1,d1           d1.w contains number from 1 to 100

The range of the random number is limited by the divu #100,d1 instruction. In the 68000, the divu instruction places the modulus in the upper word of the result. So, d1 = d1 modulo 100 limits the range of the numbers in d1 to 0 through 99. Adding 1 gives us numbers in the range 1 through 100.

If you want the limit to be 50 through 140 then take the number modulo 91 and then add 50. So:
Code:
and.l   #\$5FFFFF,d1     prevent overflow in divu
divu    #91,d1          time count / 91
swap    d1              swap upper and lower words of D1 to put remainder in low word
addq.w  #50,d1          d1.w contains number from 50 through 140

_________________
Prof. Kelly

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 4 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 14 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects