In: Computer Science
WE ARE DOING COPY CONTENTS OF FIRST LOCATION AND STORE INTO THIRD LOCATION THEN AGAIN COPY CONTENT OF SECOND LOCATION INTO FIRST AND THEN THIRD TO SECOND,
THIS IS THE WAY WE ARE GOING TO SWAP THE CONTENTS.
CLEAR
STORE INDEX
WHILE, LOAD STR1_BASE //THROUGH THIS LOOP WE ARE COPYING CONTENT OF FIRST LOCATION
ADD INDEX INTO THIRD LOCATION.
STORE ADDR // FIRST LOAD THE ADDRESS OF FIRST STRING AND THEN ADD OFFSET
CLEAR AND INTO ANOTHER LOCATION ADDR.
LOAD TEMP_BASE //THIS IS OUR THIRD LOCATION
ADD INDEX
STORE ADDR2
CLEAR
ADDI ADDR .// FETCH VALUE AT ADDRESS ADDR .
STORE ADDR2
SKIPCOND 400 // SKIP IF CHAR IS NULL
JUMP DO
JUMP NEXT
DO, LOAD INDEX
ADD ONE // INCREMENT OFFSET
STORE INDEX
JUMP WHILE
NEXT CLEAR
LOAD ZERO
STORE INDEX
WHILE2, LOAD STR2_BASE //SIMILARLY WE WILL DO FOR SECOND LOCATION
ADD INDEX
STORE ADDR
CLEAR
LOAD STR1_BASE
ADD INDEX
STORE ADDR2
CLEAR
ADDI ADDR
STORE ADDR2
SKIPCOND 400
JUMP LOOP2
JUMP AGAIN
LOOP2, LOAD INDEX
ADD ONE
STORE INDEX
JUMP WHILE2
AGAIN, CLEAR
LOAD ZERO
STORE INDEX
CLEAR
WHILE3, LOAD TEMP_BASE
ADD INDEX
STORE ADDR
CLEAR
LOAD STR2_BASE
ADD INDEX
STORE ADDR2
CLEAR
ADDI ADDR
STORE ADDR2
SKIPCOND 400
JUMP LOOP3
JUMP END
LOOP3, LOAD INDEX
ADD ONE
STORE INDEX
JUMP WHILE3
END, HALT