This homework is, in style, similar to Homework 8.
Write an LC-2 assembly language subroutine that performs the C ^ operator. You should write the subroutine so that it processes its input arguments in registers R1 and R2 and returns its result in register R0.
Review your notes for the 21 March lecture to see an example that uses this argument passing style. Review your notes for the 22 January lecture for a little more information about the exclusive-OR. All you really need to know is that the following C exression is always true:
(A ^ B) == (A & ~B | ~A & B)
This solution was given by Tom Albright.
.Orig x4000 ;Tom Albright's XOR subroutine ;A B |~A |~B |~A&~B|~(~A&~B)|A&B|~(A&B)|~(~A&~B)&~(A&B) ; (Regular Or) (Exclusive Or) ;0 0 | 1 | 1 | 1 | 0 | 0 | 1 | 0 ;0 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 ;1 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 ;1 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 ;XOR == A & ~B | ~A & B == ~(~A & ~B) & ~(A & B) TomsXOR ST R3, Reg3 ;Store original register values ST R4, Reg4 Not R3, R1 Not R4, R2 And R3, R3, R4 Not R3, R3 ;~(~A & ~B) And R0, R1, R2 Not R0, R0 ;~(A & B) And R0, R0, R3 ;~(~A & ~B) & ~ (A & B) LD R3, Reg3 ;Restore registers to original values LD R4, Reg4 Ret ;Return to original program Reg3 .Fill x0 Reg4 .Fill x0 .end