Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a program using PIC assembly to copy an arbitrary number of bytes from

ID: 664551 • Letter: 1

Question

1. Write a program using PIC assembly to copy an arbitrary number of bytes from one bank of memory to another, as in a memcpy. The memcpy function copies “count” number of bytes from the source address to the destination. Using the PIC processor, we are developing a memcpy to copy between banks. This requires the use of indirect addressing. Assume the addresses are passed in the common memory locations. Also, make sure count is less than equal to 0x50 and that the low bytes of the dst and src addresses plus the count do not exceed 0x6f. Dst address: 0x70, 0x71 - big endian Src address: 0x72, 0x73 Count: 0x74 Key: 0x75 (question #2) bool memcpy(dst addr, src addr, count)

2. Modify the memcpy program to have as an additional argument a single 8-bit key. Use this key to encrypt the destination data, using XOR. bool memcpy(dst addr, src addr count, key)

3. Write a program to swap nibbles in the FSR0L register and store in the W register. Show both the assembly code and the opcode(s) in machine language.

4. Describe how a RETW instruction can be used to allow the programmer set up a Data Table in program memory.

Explanation / Answer

1)
#include <p18f4550.h>
#include <stdlib.h>
#include <string.h>
int k;
unsigned char src[4]; //arrays are declaring to hold source and destination
unsigned char dest[4];

void main()
{
for(k=0; k<4; k++)
{
src[k] = 0x70; //address are initalizing given in question
dest[k] = 0x72;
}

memcpy(dest, src, 4); //sending paramters destination source address as well as counter

while(1);
}

2)
#include <p18f4550.h>
#include <stdlib.h>
#include <string.h>
int k;
unsigned char src[4]; //arrays are declaring to hold source and destination
unsigned char dest[4];
unsigned char key[4];
unsigned char count[4];
void main()
{
for(k=0; k<4; k++)
{
src[k] = 0x70; //address are initalizing given in question
dest[k] = 0x72;
count=0x74;
key[k] = 0x75;
}

memcpy(dest, src, count,key); //sending paramters destination source address,count as well as key

while(1);
}

3)

SWAPF FSR0L , 0, 1 ; Swap nibbles in register
Before swap instruction
FSR0L = 0xA4
WREG = x
After swap Instruction
FSR0L = 0xA4
WREG = 0x4A

4)
The RETW instruction os used to set up data table and to look-up tables in PIC assembly. we can access thr table address using
CALL instruction, at the table address that adds an offset to the PCl to get correct data.