0

I am stuck on my assignment where it tells me to generate a random letter in range A to J I know that I should be using the ascii table but how to I write the code in easy68k? I have tried everything but I can only seem to generate a random number, not a letter. Please help

1 Answers1

0

From a quick check of the list of "trap tasks" it seems task 8 returns current time in milliseconds. You could/should use this as a seed to a proper random number generator, but for now let's just run with that number alone.

I'd do something like:

random_character:
  moveq.w #8,d0
  trap    #15   ; returns ms in d1
  divu.w  #10,d1
  moveq.w #0,d1 ; clear lower word
  swap    d1    ; get remainder, i.e. compute d1 % 10
  addi.w  #'A',d1
  rts

Something like that should work. Of course, if you call it too quickly you will get the same letter until the clock has progressed.

unwind
  • 391,730
  • 64
  • 469
  • 606