Question & Answer: You have 3 variables X,Y and Z stored in the following locations X @ 0 times 30 in bank 0 and Y ox31 also in bank 0 and Z at…..

Problem 1. You have 3 variables X,Y and Z stored in the following locations X @ 0x30 in bank 0 and Y ox31 also in bank 0 and Z at OxA0 in bank 1. Earlier in the program X and Y have been loaded with data. That part of the program has already been written and debugged. Now, you have to write a segment of code that will switch X and Y. You may use location Z if you need to without having to save Z. Hints: Dont forget BANKSELs where you need them. Remember, you must not destroy the data before you move it. You will need to use MOVF AND MOVWF instructions. Dont forget that you need the 2nd operand with the MOVF but not with the MovwF instruction. It might be a good idea to do a block diagram of a flow chart before you write your code.

You have 3 variables X,Y and Z stored in the following locations X @ 0 times 30 in bank 0 and Y ox31 also in bank 0 and Z at 0 times A0 in bank 1. Earlier in the program X and Y have been loaded with data. That part of the program has already been written and debugged. Now, you have to write a segment of code that will switch X and Y. You may use location Z if you need to without having to save Z.

Expert Answer

 

;X contains A,Y contains B and W contains M
movwf Z
movf Y,W
movf X,Y
movwf X
movf Z,W

X contains B,Y contains A and W contains M

All others values remain the same except for X and Y as they got switched

Still stressed from student homework?
Get quality assistance from academic writers!