28
Chapter 6: Assembly Language Programming Overview
TI
-
89 / TI
-
92 Plus Developer Guide
Not for Distribution
Beta Version January 26, 2001
Its C prototype is:
short mySubr(short a, short b);
The Assembly language subroutine is:
;subroutine entry
mySubr:
link a6,#-8 ; allocate 8 bytes for local
; variables
movem.l d3-d4/a2,-(sp) ; save registers
.
.
.
move.w 8(a6),d0 ; get parameter
a
from caller
move.w d0,-8(a6) ; save in local variable storage
.
.
.
;subroutine exit
move.w -2(a6),d0 ; return function result in D0
movem.l (sp)+,d3-d4/a2 ; restore registers
unlk a6 ; free stack space
rts ; return from subroutine
Here is how stack memory looks in the above example after subroutine entry.
12 bytes 8 bytes 4 bytes 4 bytes 2 bytes 2 bytes
L
20(a6)
L
8(a6) 0(a6) 4(a6) 8(a6) 10(a6)
saved D3, D4, and A2 local variables saved A6 return
address
ab
Figure 6.1: Example of ASM Stack Memory
A6
A7