Also wenn man 0 - 255 auf 0-39 ist das skaliert /256*40
/256 ist ja in Fixpunktdarstellung <highbyte>.<lowbyte>
Multipliziert man lowbyte mit 40 (= 5*8), hat man im highbyte das skalierte Ergebnis stehen.
Code
; scaling with 40/256
*=$c000
lda #0
sta res+1
lda random ; multiplicant
asl
rol res+1
asl
rol res+1
clc
adc random
sta res
bcc +
inc res+1
+ asl ; *5
rol res+1 ; *10
asl
rol res+1 ; *20
asl
rol res+1 ; *40
sta res
rts
random !by 16
res !by $ff, $ee
Alles anzeigen
Erst wird mit 5 (%101) multipliziert (das ist Wert addieren bzw. erstmals übernehmen, shift ohne addieren und shift mit addieren).
Mal 8 ist dann nur noch 3x Shift.
In res+1 steht dann das Ergebnis.
Das letzte "sta res" kann man sich freilich schenken, wenn man nur res+1 als ergebnis braucht.