Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Well, generally, I would NOT do that... Although here this does not seem to be the issue, XOR does not modify the carry flag while CJNE does... Also, the software might make use of the implicit zero accumulator later on... And the few bytes' spare in program memory does not justify it...IanP said:I would replace XOR+JZ, XOR+JNZ by CJNE (not essential) ..
Wow, a lot of experience you have IanP, don't you... Now I understand, thanks... Of course it does not need to be at 0300h (it would be a pain to keep it there), just the real address of it should be loaded to dptr prior using movc for table lookup.IanP said:The tables look like Months ... and Leap Years
It is a common misconception that the 8051 zeroes RAM at reset. Please read the '51 "bibles" and datasheets - it does NOT clear or set anything except specified SFR locations. This misconception comes from a common practice of C-compilers which by default do clear the whole RAM as a first thing afer reset.IanP said:In 8051 after reset [...] all RAM cells are cleared ..
Absolutely no need to do this. The '48 stack is exactly 16 bytes deep and range from RAM locations 08 to 23. This is the same as in the '51, by default the SP is 7 but it increments prior save so the stack grows from 08 up (they indeed considered '48 to '51 migration issues at Intel, no wonder...). The caveat would be that at overflow in '48 the stack wraps around while at '51 grows above 24, which is the register bank where I switch (as in '48 the second bank is exactly at 24) ... But that would be a perverse (ab)use of stack, wouldn't it? I don't expect it will happen here.IanP said:As in the end of the code you switch from one register bank to another instead of clearing RAM (address X0007) load SP with something like 40h .. 50h ..
No need to clear anything implicitly, nevertheless the program clears it anyway... the following is the original startup code:IanP said:In the case of this program there are limited number of cells used as flags/data bytes, so in my oppinion there is no need of clearing the whole memory area ..
reset: mov a,#0ffh
outl p1,a
clr c
mov r0,#7fh
clr a
X0007: mov @r0,a
djnz r0,X0007
As I mentioned, the 08-23 area IS safe as it is the original position of the stack in '48.IanP said:As far as the SP is concerned, unless someone knows the code all the way through, I would advice to shift the SP to an unused region and have this issue solved for ever ..