Skip to content

Instantly share code, notes, and snippets.

@deckarep
Created January 23, 2021 06:49
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 deckarep/bf165c1f930e3222e6f9befacc8b3212 to your computer and use it in GitHub Desktop.
Save deckarep/bf165c1f930e3222e6f9befacc8b3212 to your computer and use it in GitHub Desktop.
6502 assembly - simple RAND subroutine
rand equ $04
;uint8_t next_rnd(void)
;{
; static uint8_t rnd;
; rnd = rnd * 5 + 17;
; return rnd;
;}
; returns a pseudo rand store at memory location: rand
next_rand:
lda rand
asl ; A = RND * 2
asl ; A = RND * 4
clc
adc rand ; A = RND * 5
clc
adc #17 ; A = RND * 5 + 17
sta rand
rts
@deckarep
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment