Skip to content

Instantly share code, notes, and snippets.

@thentenaar
Created November 25, 2012 01:18
Embed
What would you like to do?
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