Thursday, 21 March 2019

Microcode for a SWAP Reg0, Reg1 (3 Clock Cycles)




For those wanted to extend their instruction set - without adding too much complexity to microcode instructions - a SWAP instruction, where two registers are swapped over - can be implemented in 3 clock cycles just by using a series of 3 exclusive-or operations between the two registers. I'm assuming that 'setting a register' is done on the opposing edge of the exclusive-or operation. We can achieve a swap with the following microcode instructions. SWAP A, B A <- A XOR B CLK 1 B <- A XOR B CLK 2 A <- A XOR B CLK 3 For example, if we start off with the two registers A and B A = 3, B = 32 CLK 0 A = 35, B = 32 CLK 1 A = 35, B = 3 CLK 2 A = 32, B = 3 CLK 3 I hope - someone finds this helpful!

No comments:

Post a Comment