Jump to content
IGNORED

Suzy and her division results


pwwit1

Recommended Posts

Hello,

 

I'm really starting to like programming the Lynx, what a great little platform!

Recently I started to play around with doing simple divides with suzi, and they mostly work. Except when I have a remainder :\

 

So here is my little program that I test by inspecting the accumulator it reads the result in a debugger.

It takes the decimal value 15 and divides it by 20.

 

DCBA return 0, as expected

ML, the remainder, returns 15 - which I find weird. I would expect the remainder would be .75 in 16bit fixed point (7FFF or something similar). Am I reading the remainder correctly? Code is below

 

; Divisor
	lda #20
	sta SUZI_MATHP 
	stz SUZI_MATHN 

	; LSB of numerator
	lda #15
	sta SUZI_MATHH
	stz SUZI_MATHG
	stz SUZI_MATHF
	stz SUZI_MATHE

	SYS_SUZY_MATH_WAIT

	; result
	lda SUZI_MATHD   ; 0
	lda SUZI_MATHC   ; 0
	lda SUZI_MATHB   ; 0
	lda SUZI_MATHA   ; 0

	; remainder
	lda SUZI_MATHM   ; Remainder is 15?!
	lda SUZI_MATHL	 ; 0

My question is is there any simple way to divide two numbers that give a fractional result (say 0.5) and use that to multiply another number? Something like 20 / 40 * 100 = 50.

It seems so cumbersome using remainders to do this, I must be missing something.

 

Any suggestions are welcome :)

 

Link to comment
Share on other sites

The remainder of 15 is correct (15 modulo 20 = 15).

 

SUZY does integer only. So if you want fixed point, you need to shift the input value accordingly.

 

So divide (15*100) by 20 and you get 75 (which is .75).

 

See apfel_2a.asm in new_bll.

 

 

 

Link to comment
Share on other sites

4 hours ago, pwwit1 said:

nterestingly if I don't clear the high byte, in the emulator the math results always return 0xff. Using Handy

Well, no my version (else my 128/256 byte intros would not work). But what you pay attention for is that the emulator does not use the same number of cycles for multiplication/division.

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...