views:

155

answers:

2

I'm using shift operations to divide a long word in register D3 by three and storing the result in memory address specified by A2:

        MOVE.L  D1, D2, D3, -(SP)
        CLR.L   D5
        MOVE.B  #1, D4

Loop    LSR.L   D2, D3
        ROXR.L  #1,D5
        BCS     DONE
        SUBI.B  #1, D2
        BLT     Loop
        CLR.B   D4

DONE    MOVE.L  (SP)+, D3, D2, D1
        RTS

Is this correct?

+1  A: 

No, this cannot be correct. There are at least these faults with the code:

  • Incorrect syntax in the register-saving/restoring on the first and last lines. You should use the MOVEM instruction (move multiple) for this.
  • Inconsistent register usage; you store D1/D2/D3, yet clobber other registers.
  • Not writing any result to the address specified by A2.

I'm not sure at all about the algorithm itself, and if its properly implemented. Perhaps you can enhance the question with a description of the register, and what the inputs to the routine are (which register contain the numbers for the division?).

unwind
D3 contain the numbers for the division
kIngcross
Please edit the question, so that it becomes more complete. And a division typically requires _two_ numbers, how does a single register contain them both? You need to be more specific.
unwind
+1  A: 

Minor point use ASR not ROXR as you continually compare, subtract and shift and try again there is no need to bring stuff in from the X flag.

mP