Last active
December 3, 2023 19:00
-
-
Save hausdorff/5993556 to your computer and use it in GitHub Desktop.
mod and div implemented in 6502 asm
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
; load some data up | |
LDA #$7 | |
STA $00 ; memory addr A | |
LDA #$05 | |
STA $01 ; memory addr B | |
JMP Divide | |
;modulus, returns in register A | |
Mod: | |
LDA $00 ; memory addr A | |
SEC | |
Modulus: SBC $01 ; memory addr B | |
BCS Modulus | |
ADC $01 | |
;division, rounds up, returns in reg A | |
Division: | |
LDA $00 | |
LDX #0 | |
SEC | |
Divide: INX | |
SBC $01 | |
BCS Divide | |
TXA ;get result into accumulator | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome :)