Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fragment file (m1u8=m2u8_div_c1u8.asm) for 8-bit division (var / constant):
- lda {m2}
- ldx #{c1}
- jsr _div8_8u._main_
- sta {m1}
- which calls:
- function _div8_8u : Byte; assembler; volatile;
- // input: dividend in A, divisor in X
- // output: result in A, if divisor = 0, result = 0
- //
- var
- dividend, divisor : Byte;
- asm
- cpx #0
- bne !+
- // return 0 as result if divisor = 0
- lda #0
- rts
- !:
- sta dividend
- stx divisor
- // 8bit/8bit division
- // by White Flame
- // https://codebase64.org/doku.php?id=base:8bit_divide_8bit_product
- //
- // Input: dividend, divisor
- // Output: dividend = quotient, .A = remainder
- lda #$00
- ldx #$07
- clc
- !:
- rol dividend
- rol
- cmp divisor
- bcc !+
- sbc divisor
- !:
- dex
- bpl !--
- rol dividend
- lda dividend
- end;
Add Comment
Please, Sign In to add comment