Hardware Reference
In-Depth Information
4.8.1 Calling D-Bug12 Functions from Assembly Language
Calling the functions from assembly language is a simple matter of pushing the parameters
onto the stack in the proper order and loading the first or only function parameter into accumula-
tor D. The function can then be called with a jsr instruction. The code following the jsr instruction
should remove any parameters pushed onto the stack. If a single parameter was pushed onto the
stack, a simple pulx or puly instruction is one of the most efficient ways to remove the parameter
from the stack. If two or more parameters are pushed onto the stack, the leas instruction is the
most efficient way to remove the parameters. Any of the CPU registers that were saved on the
stack before the function parameters should be restored with a corresponding pull instruction.
For example, the WriteEEByte() function has two parameters: The first parameter is the address of
the memory location to which the data is to be written; the second is the data itself. An example of
the instruction sequence to call this function to write the value #$55 into EEPROM is as follows:
WriteEEByte
equ
$EEA6
.
.
ldd
#$55
; write $55 to EEPROM
pshd
ldd
#EEAddress
; EEPROM address to write data
jsr
[WriteEEByte,pcr]
; call the routine
leas
2,sp
; remove the parameter from stack
beq
EEWError
; 0 return value means error
.
.
The addressing mode used in the jsr instruction of this example is a form of indexed indirect
addressing that uses the program counter as an index register. The PCR mnemonic used in place of
an index register name stands for program counter relative addressing. In reality, the HCS12 does
not support PCR. Instead, the PCR mnemonic is used to instruct the assembler to calculate an
offset to the address specified by the label WriteEEByte. The offset is calculated by subtracting the
value of the PC at the address of the first object code byte of the next instruction (in this example,
leas 2,sp) from the address supplied in the indexed offset field (WriteEEByte). When the jsr instruction
is executed, the opposite occurs. The HCS12 adds the value of the PC at the first object code byte of
the next instruction to the offset embedded in the instruction object code. The indirect addressing,
indicated by the square brackets, specifies that the address calculated as the sum of the index regis-
ter (in this case the PC) and the 16-bit offset contains a pointer to the destination of the jsr.
The MiniIDE software supports this syntax. However, if you are using an assembler that
does not support program-counter-relative-indexed addressing, the following two-instruction
sequence can be used:
ldx WriteEEByte ; load the address of WriteEEByte()
jsr 0,x ; call the subroutine
If the name of a library function is preceded by the keyword far , then it is located in the
expanded memory and must be called by using the call instruction. Other library functions can
be called by executing the jsr instruction.
4.8.2 Descriptions of Callable Functions
For each of the callable functions, the prototype declaration and the pointer address (where
the starting address of the function is stored) are listed.
void far main (void);
Pointer address:
$EE80
 
Search WWH ::




Custom Search