Jump to content
IGNORED

div_mul16.asm


bogax

Recommended Posts

edit: Multiply is buggy! I forgot to propagate the carry :dunce:

 

 

 

Here is a replacement for the 8 * 8 = 16 multiplication
and 8 / 8 division with remainder routines.

I haven't tested them exhaustively yet but they seem to work ;)




  ; enter with multipcands in a, y
  ; a * b result hi in temp2, lo in a
  ; by bogax
 
mul16
  dey
  sty temp1
  sta temp2
  ldx #$07
  lda #$00
mul_loop
  asl
  rol temp2
  bcc mul_no_add
  adc temp1
mul_no_add
  dex
  bpl mul_loop
  rts

  ; a / y 
  ; returns quotient in a, remainder in y and temp1, divisor in temp2
  ; by bogax

div16
  sty temp2 ; divisor
  asl ; dividend
  sta temp1 ; quotient/dividend
  lda #$00
  ldx #$07
div_loop
  rol ; remainder
  cmp temp2 ; divisor
  bcc div_next
  sbc temp2 ; divisor
div_next
  rol temp1 ; quotient/dividend
  dex
  bpl div_loop
  tay
  lda temp1
  sty temp1
  rts
Edited by bogax
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...