| ??? 12/05/02 17:11 Read: times |
#33848 - RE: little help! assembly |
I would suggest you find an introductory book that talks about assembly language programming.
From, looking at the previous posts I can see that the issue of the 0xFF in a port to make it an input is not explained very well. The posts do not give you a consistent answer. To use a port for input the input lines need to be set to logical 1's in the output register for the port. If you do input only it is only necessary to set the 1's bits in the output register one time. If you wake up from reset these output register bits are preset to the 1's for you. (Note that I almost always re-initialize them in my code anyway). The processor always wakes up with the bank select bits for the register set picked for bank 0. If you do not intend to use other register banks it is not necessary actually force the select to 0 out of reset. However it cannot hurt to re-do it in your program should you desire...it only takes a couple of intructions. Stopping a program on an 8051 is done three ways. There is the simplest which is to create an endless loop. The there is also the STOP and the IDLE modes which are invoked by setting one or the other of the low two bits of the PCON register. Calling a subroutine from inside another subroutine is totally possible. The processor has a stack that keeps track of where to return to at the end of each subroutine. You can nest subroutines multiple levels, 3, 4, 5 or more. There are some things to keep in mind though. As a new programmer please note that there is a limited amount of stack space and this will limit how far you can nest subroutines. Secondly a subroutine shares the processor registers with the code that called the subroutine. This means that if the subroutine wants to use a register that was in use by the caller then it is normally necessary for the subroutine to save the register value at the start of the subroutine and then restore it before the RET instruction. There are two instructions designed specifically for this called PUSH and POP. These also use stack space so keep in mind that your nesting level is also regulated by how many PUSHs that you do. I also want to point out that you need to be careful when subroutines call each other. If you had a code structure where SUB1 calls SUB2 which in turn calls SUB3, it can be dangerous for SUB3 to call SUB1. Unless there is special control code inside the subroutines this type of programming can lead to a wild loop of SUB1->SUB2->SUB3->SUB1->SUB2......etc etc. This will very quickly overrun the limited stack and make your program crash. I hope this helps Michael Karas |



