Created
January 23, 2021 06:49
-
-
Save deckarep/bf165c1f930e3222e6f9befacc8b3212 to your computer and use it in GitHub Desktop.
6502 assembly - simple RAND subroutine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.dabeaz.com/superboard/asm6502.py