Chapter 6: Assembly Language Programming Overview
27
TI
-
89 / TI
-
92 Plus Developer Guide
Not for Distribution
Beta Version January 26, 2001
Arguments are passed to OS-resident routines on the hardware stack. Use the C
declaration of an OS routine to determine the type and order of arguments
required by the routine. Arguments are pushed onto the hardware stack in
right-to-left order described by the routine’s C prototype declaration.
For example, the program would call
memcmp
to compare two byte arrays. The
C prototype for
memcmp
is:
int memcmp(const void *s1, const void *s2, size_t count);
The Assembly language call is:
; if (memcmp(ID, myid, sizeof(myid)) == 0)
move.l #5,-(sp) ; push size of myid
pea myid(a6) ; push address of myid
pea id(a6) ; push address of ID
move.l memcmp(a2),a0 ; get address of memcmp
jsr (a0) ; call memcmp
add.w #12,sp ; pop arguments from stack
tst.w d0 ; test result from memcmp
bne notTheSame ; not equal --->
When you look at OS routine C prototypes, keep in mind the size and range of C
data types. In particular, note that int is two bytes in the AMS.
Type Size (bytes) Range
char 1
L
128 . . . 127
unsigned char 1 0 . . . 255
short 2
L
32768 . . . 32767
unsigned short 2 0 . . . 65535
int 2
L
32768 . . . 32767
unsigned int 2 0 . . . 65535
long 4
L
2147483648 . . . 2147483647
unsigned long 4 0 . . . 4294967295
pointer 4 0 . . . 0xFFFFFFFF
Table 6.1: AMS C Data Types
6.5. Subroutine Linkage
Use
link
to allocate space from the hardware stack for local variables. Use
unlk
to free stack space before returning from the subroutine. Use the
movem.l
instruction to save and restore registers.
Example: subroutine linkage for subroutine mySubr with eight bytes of local
variables and two parameters.