CAN YOU SOLVE THIS PROGRAMMING DILEMNA ? (a puzzle)

Thread Starter

sesmd (stan)

Joined Sep 30, 2014
10
You work as a programmer for a moderate-sized hardware/software company. The company is
releasing a 'new' product (pretend it's 1985)... it's a simple microprocessor unit which acts as
a 'bus extender' for the PC's two-way parallel port. The unit must receive and re-transmit bi-
directional byte data - sometimes concurrently. Very little money was put into to processor's
design; it has an ALU, and ONLY two eight bit (byte) registers. Each register acts as both a port
and CPU available register. ROM also exists to hold program code. There is NOT an additional
accumulator. The situation arises where each register has received a byte from it's respective
8-bit bus, and now the ALU must swap these bytes between registers, so they may be sent on
their way.... the engineers who designed the microcode for the ALU included all the typical
arithemetic and logical operations, but they neglected (it was Friday, deadline looming) to
include that SWAP instruction. And, remember, there is no Accunulator. Only the two byte-
addressable registers.

Can you write the code to swap the byte values between the registers, so data can be on it's merry way ?
 

vpoko

Joined Jan 5, 2012
267
Unfortunately, ingineers also neglected to include the XOR operation. Therefore, you're totally doomed.
Unless, of course, the instructions don't say that they forgot the XOR... I bet OP would be safe in assuming that XOR was there since it's a typical logical operation. Who knows, it might be a useful gate.
 

Thread Starter

sesmd (stan)

Joined Sep 30, 2014
10
i CAME BACK ...........
Anyway, sorry'bout answer delay.... lost my disk (and, so my primary brain repository.....) and, having visited 'All about Circuits'
after having worked a 24+ hour shift, just couldn't retrieve the site's name from my secondary (organic) memory.
As if it really matters to anyone..........

I'll cap the hot air, and here comes the overdue answer.... tho I suspect everyone's already figured it out.....

Problem brief :
exchange data in two registers (of same size) without the use of a third temp register/ accumulator -

Method (sort of pseudocode) -
We'll call the registers A and B. Size doesn't matter, as long as the posited system can handle datum in single op.

B = A xor B
A = B xor A
B = B xor A

B now holds A's original value, and A holds B's original value.

It's Magic !!



stan


p.s. Homework is far, far in my past (oh, so many thanks!....)
 

WBahn

Joined Mar 31, 2012
32,852
Well, thanks for coming back.

It's not magic at all. Do you understand WHY this works? Hint, if you feed data into one input of an XOR gate, the other input controls whether the gate buffers or inverts the data.
 
Top