pwwit1 Posted July 9, 2021 Share Posted July 9, 2021 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 Quote Link to comment Share on other sites More sharing options...
42bs Posted July 9, 2021 Share Posted July 9, 2021 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. Quote Link to comment Share on other sites More sharing options...
42bs Posted July 9, 2021 Share Posted July 9, 2021 BTW: No need to clear the high byte despite SUZI_MATHE which starts SUZY. Quote Link to comment Share on other sites More sharing options...
pwwit1 Posted July 12, 2021 Author Share Posted July 12, 2021 Cheers thankyou! Interestingly if I don't clear the high byte, in the emulator the math results always return 0xff. Using Handy Quote Link to comment Share on other sites More sharing options...
42bs Posted July 13, 2021 Share Posted July 13, 2021 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.