beautypg.com

Maxq610 user’s guide – Maxim Integrated MAXQ610 User Manual

Page 202

background image

15-9

MAXQ610 User’s Guide

15.5 ROM Example 2: Calling A Utility ROM Function Indirectly

The second example shows the indirect addressing method (lookup table) for calling utility functions . We use the
same function (UROM_MoveDP1Inc) to read our static string, but this time we must figure out the address we want
dynamically . Note the inserted code where we before had a direct call to the function . Also note that the function index
of moveDP1inc is 7 .
Text:
DB “Hello World!”,0

; Define a string in code space.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Function:

PrintText

;; Description:

Prints the string stored at the “Text” label.

;; Returns:

N/A

;; Destroys:

ACC, DP[1], DP[0], and GR.

;; Notes:

This function assumes that DP[0] is set to word mode,

;;

DP[1] is in byte mode, and the device has 16-bit

;;

accumulators.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintText:
move DP[1], #Text

; Point to the string to display.

move ACC, DP[1]

; “Text” is a word address and we need a

sla

; byte address, so shift left 1 bit.

or #08000h

; Code space is mapped to 8000h when running

move DP[1], ACC

; from the ROM, so the address must be masked.

PrintText_Loop:
;
; Fetch the byte from code space.
;
move DP[0], #0800Dh

; This is where the address of the table is stored.

move ACC, @DP[0]

; Get the location of the function table.

add #7

; Add the index to the moveDP1inc function.

move DP[0], ACC

; Point to where the address of moveDP1 is stored.

move ACC, @DP[0]

; Retrieve the address of the function.

call ACC

; Execute the function.

move ACC, GR
jump Z, PrintText_Done ; Reached the null terminator.
call PrintChar

; Call a routine to output the char in ACC

jump PrintText_Loop

; Process the next byte.

PrintText_Done:
ret