paul_nicholls

Untitled

Feb 18th, 2024 (edited)
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fragment file (m1u8=m2u8_div_c1u8.asm) for 8-bit division (var / constant):
  2. lda {m2}
  3. ldx #{c1}
  4. jsr _div8_8u._main_
  5. sta {m1}
  6.  
  7. which calls:
  8. function _div8_8u : Byte; assembler; volatile;
  9. // input:  dividend in A, divisor in X
  10. // output: result in A, if divisor = 0, result = 0
  11. //
  12. var
  13.   dividend, divisor : Byte;
  14. asm
  15.   cpx #0
  16.   bne !+
  17.   // return 0 as result if divisor = 0
  18.   lda #0
  19.   rts
  20.   !:
  21.   sta dividend
  22.   stx divisor
  23. // 8bit/8bit division
  24. // by White Flame
  25. // https://codebase64.org/doku.php?id=base:8bit_divide_8bit_product
  26. //
  27. // Input: dividend, divisor
  28. // Output: dividend = quotient, .A = remainder
  29.  
  30.  lda #$00
  31.  ldx #$07
  32.  clc
  33. !:
  34.   rol dividend
  35.   rol
  36.   cmp divisor
  37.   bcc !+
  38.   sbc divisor
  39. !:
  40.  dex
  41.  bpl !--
  42.  rol dividend
  43.  
  44.  lda dividend
  45. end;
  46.  
Add Comment
Please, Sign In to add comment