Электроника МК-61/Dice Program
From Wiki
Dice Roller for MK-61
Every programmable calculator should be able to roll dice because everyone capable of programming a calculator will find themselves playing a role-playing game sooner or later. Really. So, without further ado, here's a dice roller for the MK-61. It only takes 17 seconds to roll three six-sided dice!
USAGE:
- Enter program listed below
- Press В/0
- Enter number of dice to roll
- Press В↑
- Enter number of sides on die
- Press С/П
- Repeat as needed from step 3
| Main Program | |||
|---|---|---|---|
| Addr | Code | Instruction | Comment |
| 00 | 47 | П→X 7 | Store die faces in R7 |
| 01 | 25 | ⁐ | Rotate stack down |
| 02 | 41 | П→X 1 | Store number of dice in loop counter R1 |
| 03 | 25 | ⁐ | Rotate stack down |
| 04 | 0Г | СX | Clear X Register |
| 05 | 53 | ПП | Start of rolling loop Roll one die (using subroutine at 20) |
| 06 | 20 | 20 | |
| 07 | 10 | + | Accumulate roll into total |
| 08 | 5L | L1 | Decrement loop counter R1 jump back to 05 if >= 1 |
| 09 | 05 | 05 | |
| 10 | 50 | С/П | Stop until С/П pressed again |
| 11 | 51 | БП | Then jump back to the top and do it all again |
| 12 | 00 | 00 | |
| | |||
| Addr | Code | Instruction | Comment |
| 20 | 60 | П→X 0 | Recall seed value from R0 |
| 21 | 0E | В↑ | Copy to Y register (because the manual said so) |
| 22 | 3L | СЧ | Call internal random number generator |
| 23 | 40 | X→П 0 | Copy generated value as new seed |
| 24 | 67 | П→X 7 | Recall faces on die |
| 25 | 12 | × | Multiply by random number |
| 26 | 01 | 1 | Add 1 to put result in interval 1..x |
| 27 | 10 | + | |
| 28 | 34 | [X] | Truncate to integer |
| 29 | 14 | ↔ | Stack cleanup: swap out Y register... |
| 30 | 25 | ⁐ | ...and rotate it out of the way. |
| 31 | 52 | В/0 | Return to main program |
Back to Электроника МК-61


