We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
here are few questions which are troubling me.. kindly help...
1) Why should we always start 8051 program with the following piece of code? (starting code) org 0h ljmp 8000h org 8000h
2) since the address location 0000h is eprom.. we cant save data on that address.. then where is the starting code(above said code) saved??
3)what happens if we remove starting code and end statement in the end of program??
4) why only direct addressing is alllowed for push and pop instruction....
waiting for answers....
Here are some:
Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
The memory Map of the 8052 look something like this:
0000 - Reset Vector ----- Interupt Vector ----- Interupt Vector ----- Interupt Vector ----- Interupt Vector...
The Long jump skips over the interupt vectors. Why to 8000? I do not know. This is not required by the 8052.
"1) Why should we always start 8051 program with ..."
We shouldn't since that's an artificial constraint.
"2) since the address location 0000h is eprom."
Says who? Somebody just made that up. 0000h is an equally valid external RAM memory address where you can save data.
"3)what happens if we remove starting code and end statement in the end of program??
Removing starting code might yield incomplete initialization for those systems that need it. What "end statement", what program, what language?
"4) why only direct addressing is alllowed for push and pop instruction...."
Because that's the only addressing mode that Intel chose to implement.
1) org 0h - does not matter even if not mentioned. It starts there by default most of the time. Check for your compiler.
ljmp stmt need not always be written, it is mostly used while writing ISRs. There are some already written ISRs loaded at these addresses, so ljmp jumps over those locations. We can write to any valid address, 8000 is kind of a safe bet.
the second ORG stmt is used when a ljmp is mentioned.
3) end stmt Its the end of a program, ignores all further statements.
Some programs end with RET, (never ending loop) Still some compilers insist on writing an END after that Else, it generates an error.
4) Dan henry has answered this. Operations involving Stack are handled carefully, as we know it holds important information .. flow of program ie addresses, interrupts... etc direct addressing should be good enough.
org 0h - does not matter even if not mentioned. It starts there by default most of the time. Check for your compiler.
"most of the time" Male cow manure, the start at 0 is HARDWARE and has nothing to do with compiler or linker or whatever.
We can write to any valid address, 8000 is kind of a safe bet. *8000 is where the eval version goes to be an 'unusable for production' eval and if you need a "safe bet" (i.e. have no idea where your code is) you better go buy a broom.
Some programs end with RET, (never ending loop) And "Some programs" end in neverneverland including those that end with a RET. a RET will not create an eternal loop.
Still some compilers insist on writing an END after that Else, it generates an error. I know no compiler that do "insist on" and END statement and I kinow no assemb;er that do not
Erik
Says who? Somebody just made that up. 0000h is an equally valid external RAM memory address
To clarify: there is more than one address 0 in the 8051 architecture. It is a "Harvard" architecture, so it has separate code and data address spaces. The CPU core always begins execution at code address 0. External memory address 0 may well be RAM, and is not necessarily the same physical location as code address 0. There's also internal data address 0, which is still another byte of memory.
Many 8051 designs have hardware to decode the code address space into some location in external data address space, so that the code memory can be written to. This is often useful for field-upgradable systems. This layout with shared code and data memory is often called a "von Neumann" architecture. Even with this layout, though, it is not necessarily the case that code address 0 is the same physical location as external data address 0. The designer might choose to locate the start of the program memory at a high location in external data space.
ORG 0 is ROM reset location In some simulators its not necessary to write org,
ljmp is to jump over the IVT vector table where the isrs of varoius interrupts are mentioned.
For the control to go to 'main', we can write 'ljmp main' instead of mentioning the address where the program starts.
In assembly program, there is no 'main' as such. It can be used label to point where the actual program starts, Suppose, IVT ends at 0030, then code could be
org 0030h main: mov ... ...
Am not sure about 8000h, In case of using isrs, we use ljmp, else not necessary. On reset, all interrupts are disabled, and enabled if needed using IE. Eg. Timer 0 isr is at 000B. to use that, it is accessed as 'org 000B' followed by ... other stmts i should have mentioned whether in simulator or actual 8051. That doesnt mean you can use such unparliamentarian language, excuse me, In cases like generating a square wave, we use timer, count till end , reload value, again count till end number, reload,... it goes on in a loop, the last stmt in the loop is ret but while checking your program on a simulator, if end stmt is not used, it generates an error, Else, end stmt ignores all further stmts after that,
"ORG 0 is ROM reset location"
See Drew's post - it is not necessarily ROM!
"In some simulators its not necessary to write org"
It has nothing to do with simulators - it is an Assembler directive!
"ljmp is to jump over the IVT"
Not necessarily
"For the control to go to 'main', we can write 'ljmp main' instead of mentioning the address where the program starts."
Assuming that a valid definition of 'main' already exists, and is the address where the program starts.
"In assembly program, there is no 'main' as such."
This is meaningless - if you write your assembly program with a 'main', then it has a 'main'; if you don't, then it doesn't!
This is meaningless
Andy, I posted things to the same effect (all wrong) about this individuals previous post, And his nect post has no reference, just more idiocy. This makes me doubt going in detail will have ANY effect.
I suggest we restrict all responses to hem raj to just the ictaliziced pharse
was just giving a try seems like i got the words all mixed up, Assembler for simulator... sorry for that
In assembly program, there is no 'main' as such."
"This is meaningless - if you write your assembly program with a 'main', then it has a 'main'; if you don't, then it doesn't!" that is same i meant, to write 'main', we write it as a label,
ok tell me why do we use ljmp? is it not to bypass the IVT? did i use 'jump over',
ok resigned,