Is there a way to write single instruction for fractional multiplication?

312 views Asked by At

I am trying to write a single 68000 instruction to multiply the 32-bit unsigned value in D0 by 0.125. Yet fractional multiplication is not available. So I am wondering if there is any way to go around it? It's supposed to be unsigned and 0.125 = 1/8. Thus, the way I thought it would work is:

LSL (LSR #0,#3),D0

This didn't even run, and I have no idea how else I could do it.

2

There are 2 answers

5
Marco Bonelli On

This is assembly, you cannot just compose expressions combining instructions like that. Each instruction needs to be on its own line. If you want to implement (x >> 3) << 3 you'll have to first shift right, then shift left, which are two separate instructions:

LSR.L #3,D0
LSL.L #3,D0

By the way, note that (x >> N) << N is equivalent to x & -(1 << N), which in the case of N=3 is: x & -8, or in 68k assembly AND.L #-8,D0 (or in hex AND.L #$fffffff7,D0).

However, if you want to just multiply by 0.125 (i.e. divide by 8), one right shift will suffice:

LSR.L #3,D0
0
paxdiablo On

Not sure what you're trying to acheive with:

LSL (LSR #0,#3),D0

If you want to logical-shift-right the value in d0 by three bits (i.e., divide by 8, or multiply by 0.125), that would be the much simpler:

lsr #$03, d0 ;; or lsr.l