Lesson 6: Copying Data

One of the most basic tasks a computer must be able to do is copy values between data memory locations (a = b in the C language). We can see from the instruction set table that there is no single instruction to do this so instead we must use the following sequence:

movf 3, w // Copy value at address 3 to working register movwf 8 // Copy working register to address 8

Having to specify the address directly is quite tiresome and we could easily make a mistake, so the simulator provides the ability to assign a name to a register. The simulator already includes names for the special function registers, and we can add a name to an unused register by clicking on the middle column of its row. Do this for row 08h and enter the name my_var. We can now use these labels to rewrite our code in a more readable way:

movf STATUS, w movwf my_var

Remember that the chip itself only deals in raw memory address and these labels are just for our benefit as programmers. What you might be able to see though, is that a variable in a high level program is nothing more than a reserved memory location on the chip. In assembler we have to manually reserve the memory but once this is done we have essentially declared an 8-bit global variable.

Next Lesson >>