INMC News |
February/March 1980 · Issue 6 |
Page 8 of 38 |
---|
LD HL, address to jump to PUSH HL LD HL, value of HL RET
The second method is the simplest, but often the value of HL is already on the stack, making the first method the most commonly used.
Now suppose that you in fact wanted to call the routine, not to jump to it as above. In this case the return address can be pushed onto the stack in advance. For example:
LD HL, value of HL PUSH HL LD HL, return address EX (SP), HL PUSH HL LD HL, address of routine EX (SP), HL RET
This will call the routine and then return to the specified address. The original value of HL has been preserved and passed to the routine.
If the subroutine decides to, it can change its own return address, again using:
EX (SP), HL
However, this is bad programming practice because it destroys the structure of CALLs.
It is bad practice to set the stack pointer except at the start of the program where it can be useful for re-initialisation. It is very bad practice to ever use the instruction DEC SP because this implies that you have data stored on the stack at an address less than the current stack pointer (I’ve used DEC SP to ‘throw away’ unnecessary data on the stack, I don’t see anything wrong with that; Ed.). NAS-SYS 1 used this instruction, and is, I’m afraid, noninterruptable. By noninterruptable I mean that an interrupt at the wrong moment will crash the program. In fact close examination of the Nasbug monitors shows that the storing and restoration of registers is noninterruptable so they are no better. Will something be done to correct this small defect? Maybe!!
Do you know the correct name for a ‘crash’, meaning the loss of control by a program resulting in unpredictable changes to memory locations and usually requiring the reset button to be pressed? The correct name for a ‘crash’ caused by bad code is a ‘program fault’. It sounds more impressive but it its just as annoying!
A number of people have sent in details of how to put ZEAP into EPROMs and copy it dowm to its correct location. Others have worked out how to put extra features into ZEAP, such as paginated output.
(continued on page 24)
Page 8 of 38 |
---|