From: Manigandan Radhakrishnan Subject: [cs366f05] Program 5 Date: Wed, November 23, 2005 1:51 pm I was talking to another student after class and here are the notes on what we discussed. Just thought it might be helpful: Division ======== The table is part of the .mem file and is organized as follows: TStart | +-->--------------+ (0,2) | 0000 0000 | +--------------+ (0,4) | 0000 0000 | +--------------+ (1,2) | 0000 0000 | +--------------+ (1,4) | 0000 0000 | +--------------+ (2,2) | 0000 0001 | +--------------+ (2,4) | 0000 0000 | +--------------+ (3,2) | 0000 0001 | +--------------+ (3,4) | 0000 0000 | +--------------+ (4,2) | 0000 0010 | +--------------+ (4,4) | 0000 0001 | +--------------+ ... | ... | +--------------+ (63,2)| 0111 1111 | +--------------+ (63,4)| 0011 1111 | +--------------+ Let say the starting address to the table is called TStart. Then the quotient for the any N when divided by D is stored at the memory location TStart + 2*N + (if (D==4) then 1 else 0) If TStart is stored in register r3, then the result of the division (rj/rk stored in ri): ri <-- MEM[r3 + 2*rj + (1 or 0)] The 2*rj can be computed as rj + rj. And the 1 or 0 is decided by comparing rk against 2 or 4. For example, if you compare against 2, then it becomes 0 if it is 2 and 1 if it is not 2 (which could be 0, 1, 3, 4, ...). You don't have to worry about those cases. You can assume that it is either 2 or 4. Hope this helps. -- Mani.