Skip to content

Instantly share code, notes, and snippets.

@thentenaar
Created November 25, 2012 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thentenaar/4142008 to your computer and use it in GitHub Desktop.
Save thentenaar/4142008 to your computer and use it in GitHub Desktop.
Disassembly of the TI's GPL RAND command
RAND:
LI R4,>6FE5 ; R4 = >6fe5
MPY @>83C0,R4 ; R4,R5 = R4 × @>83C0 (initially >3567 when BASIC loads)
AI R5,>7AB9 ; R5 += >7ab9
MOV *R5,@>83C0 ; R5 -> @>83C0
MOVB R13,R6 ; 'm' (>64 when called from BASIC) -> R6
SRL R6,8 ; R6 & 0xff
INC R6 ; R6++ (prevent division by zero)
CLR R4 ; R4 = 0
SWPB R5 ; Swap bytes in R5
DIV R6,R4 ; R5 / R6 -> R4 (mod -> R5)
MOVB @>83EB,@>8378 ; Return pseudo-random number (R5 % R6)
JMP >02AA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment