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.
The only thing i will say is you DO have a bug.
It wont copy what you think.
FIX IT!
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!
Please note, that we actually try to help you to 'learn' what's wrong. Not by telling you exactly what's wrong in the code, then you only learn little or nothing. By using the paper and do it yourself, YOU (yourself) learn to understand it. This can be done in a couple of minutes, even a beginner can do that in approx. 30 minutes; I'm pretty sure about that.
I really appreciate the help don’t get me wrong. I’m just not sure where to exactly start. I’ll try something with that simulator when I get home. Is there any hints that you can give me of where I might start with my code? Or maybe which lines are incorrect. I think I’m more confused with the actual table part.
It's really very simple:
You start with a pencil and a piece of paper, and the Instruction Set Manual.
Squared paper is probably best - so you can have columns for register values, data values, etc.
On the paper, write down the starting conditions for the registers & data you use (remember - these could be "undefined")
Write down the first instruction of your program; refer to the Instruction Set Manual to see what that instruction does.
Write down how that instruction changes the registers & data.
Rinse and repeat for each instruction in sequence.
As you have a loop, some instructions will get repeated...
You really should do this manually before using the simulator - you will learn more that way.
Your teacher should be able to demonstrate this to you.
Please note, that we actually try to help you to 'learn' what's wrong. Not by telling you exactly what's wrong in the code, then you only learn little or nothing give a man a log and he is warm for a day, set him on fire and he is warm fur the rest of his life.