Question: Write a program to copy 10 bytes of data at ROM address 500H to RAM starting at location 40H. Start with creating a look-up table at a convenient location
ORG 500H TABLE: DB 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
ORG 40H START: MOV DPTR, #TABLE ;SOURCE POINTER MOV R1, #40H ;DESTINATION POINTER MOV R3, #10 ;COUNTER
BACK: MOVC A, @A+DPTR ;GET A BYTE FROM THE SOURCE MOV @R1, A INC R1 INC DPTR DJNZ R3, BACK ;Does this 10 times END
This is what I have but I have no idea if it is right or working correctly. Can anyone help me out?
That code sample is so small and simple that you can easily take a piece of paper and a pencil and just simulate that code. Just write down the current register contents and the program counter and do the (few) steps. If you are unsure, review in the manual what the instructions actually do.
Then you see and learn what happens.
Surely, your teacher must have shown you that?
That is the most basic way to test a piece of code!
uVision also has a simulator: http://www.keil.com/support/man/docs/uv4cl/uv4cl_simulation.htm
Please also pay attention to the instructions for posting source code - look at this picture: www.danlhenry.com/.../keil_code.png
My class isn’t based off this stuff so when she taught it, it was kind of vague. I’m just trying to get some help. I understand it might not be copying the correct thing. But I’m not sure what to fix exactly.
So do the paper & pencil exercise to map out what you think should be happening.
Cross-check what you think the instructions do with the descriptions in the Instruction Set Manual.
Then run you code in the Simulator; see where the simulator results differ from your paper & pencil results - then go back to the Instruction Set Manual; re-read and understand the instructions ...
Always question what your teachers say if it is vague!
View all questions in Keil forum