0

我被困在我的作业上,它告诉我在 A 到 J 范围内生成一个随机字母我知道我应该使用 ascii 表,但是如何在 easy68k 中编写代码?我已经尝试了一切,但我似乎只能生成一个随机数,而不是一个字母。请帮忙

4

1 回答 1

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.

于 2014-04-11T10:01:42.763 回答