Skip to content

Instantly share code, notes, and snippets.

@renormalist
Forked from hausdorff/math.asm
Created March 3, 2020 12:02
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 renormalist/f08c0418f3fc32cb5444bd1c0381ef89 to your computer and use it in GitHub Desktop.
Save renormalist/f08c0418f3fc32cb5444bd1c0381ef89 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment