Skip to content

Instantly share code, notes, and snippets.

@hausdorff
Last active December 3, 2023 19:00
Show Gist options
  • Save hausdorff/5993556 to your computer and use it in GitHub Desktop.
Save hausdorff/5993556 to your computer and use it in GitHub Desktop.
mod and div implemented in 6502 asm
; 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
@pslind69
Copy link

pslind69 commented Sep 8, 2021

Awesome :)

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