Discussion in 'Programmer's Corner' started by sesmd (stan), Sep 30, 2014.

  1. sesmd (stan)

    Thread Starter New Member

    Sep 30, 2014
    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 ?
  2. NorthGuy

    Active Member

    Jun 28, 2014
    Unfortunately, ingineers also neglected to include the XOR operation. Therefore, you're totally doomed.
    ErnieM likes this.
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    That's what an exengineer will do to you when it's beer-o-clock.
  4. vpoko

    Active Member

    Jan 5, 2012
    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.
  5. WBahn


    Mar 31, 2012
    This has the look and smell of a homework problem. Though by now it is probably a moot point. Since the OP hasn't come back, it's probably a safe bet that it was homework that the due date has come and gone for.
    theonewho, Eric007 and killivolt like this.
  6. sesmd (stan)

    Thread Starter New Member

    Sep 30, 2014
    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 !!


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


    Mar 31, 2012
    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.
  8. nsaspook

    AAC Fanatic!

    Aug 27, 2009