Skip to content

Instantly share code, notes, and snippets.

@leobm
Forked from hausdorff/math.asm
Created January 10, 2020 12:24
Show Gist options
  • Save leobm/21c517eaaa1fe9aae77cb2708db5ee48 to your computer and use it in GitHub Desktop.
Save leobm/21c517eaaa1fe9aae77cb2708db5ee48 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