EASy68K
http://www.easy68k.com/EASy68Kforum/

easy instructions
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1152
Page 1 of 1

Author:  sam1991 [ Sat Dec 15, 2012 12:49 pm ]
Post subject:  easy instructions

Move.B #59,D1
MOVE.B #18,D3

MOVE.B #10,D4
DIVU D4,D3
MULU D3,D1
Hi all, when I execute these instruction the value of D1 does not change after multiplication can anyone answer me why this happen?

Author:  profkelly [ Sat Dec 15, 2012 1:01 pm ]
Post subject:  Re: easy instructions

The MULU instruction multiplies the 16 bit source times the 16 bit destination.

In your code example the lower 16 bits of D3 contains 1, so D1 does not change
because it is being multiplied by 1.

Author:  sam1991 [ Sat Dec 15, 2012 1:20 pm ]
Post subject:  Re: easy instructions

thanks alot prof kelly, but I want to ask you how can I fix this problem

Author:  lee [ Sat Dec 15, 2012 1:50 pm ]
Post subject:  Re: easy instructions

What problem? The result you're getting is correct for integer maths.

If what you want is to calculate 18 / 10 * 59 what you should do is 59 * 18 / 10 instead. That way you will get more effective digits in your result.

Lee.

Author:  sam1991 [ Sat Dec 15, 2012 2:02 pm ]
Post subject:  Re: easy instructions

No , it is not the correct answer.

Author:  lee [ Sat Dec 15, 2012 2:39 pm ]
Post subject:  Re: easy instructions

The correct answer is 106 with a remainder of two, which is what you get if you do ..
Code:
      ORG   $1000

start
      MOVEQ       #59,D1
      MOVEQ       #18,D3
      MOVEQ       #10,D4

      MULU.w      D1,D3       * 59 x 18
      DIVU        D4,D3       * / 10

      NOP

      END   start
Lee.

Author:  sam1991 [ Sat Dec 15, 2012 4:43 pm ]
Post subject:  Re: easy instructions

OK , I knew that but I am wondering why the output is 131178? it must give me 106.2 right?

Author:  lee [ Sat Dec 15, 2012 5:04 pm ]
Post subject:  Re: easy instructions

Read the description for DIVU. What you are seeing is the result and the remainder as one longword.
Quote:
it must give me 106.2 right?
No, it will never give you 106.2, the 68000 can only do integer maths.

Lee.

Author:  sam1991 [ Sat Dec 15, 2012 5:17 pm ]
Post subject:  Re: easy instructions

mmmmmm, I am confused what actually am doing is to convert temperature from Celsius (°C) to Fahrenheit (°F) depends on relation
[°F] = [°C] × 9⁄5 + 32. the result is not true if the out put shown before.

Author:  lee [ Sat Dec 15, 2012 6:16 pm ]
Post subject:  Re: easy instructions

Go read about DIVU again and also learn carefully the difference between words and longwords.

Lee.

Author:  sam1991 [ Sat Dec 15, 2012 6:20 pm ]
Post subject:  Re: easy instructions

OK, thanks

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/