Chapter
11
I
Technical Information
Poking
a
Subroutine into Memory
You can code short subroutines in machine language and use the
POKE
statement
to
put the code into memory.
To
do
so,
follow
these steps:
1.
Code the machine language instructions
for
your subroutine.
2.
Put the assembly instruction code
for
each byte
of
the ma-
chine language code into DATA statements, preceded by the
&H
symbols
to
denote that they are hexadecimal values.
Execute
a
loop that reads the DATA statements and POKES
them into an area
of
memory.
3.
For example, the instruction code
for
the statement
PUSH
BP
is
55.
The DATA statement
for
that instruction is
DATA
&H55
After the loop is complete, the subroutine is in memory. Whether
you are using the
USR
function
or
the CALL statement
to
call
the subroutine, you must set the value
of
the subroutine entry
point as the location specified in the first POKE statement.
CALL
Statement
When the CALL statement is executed, the following occurs:
1.
For each parameter in the parameter list, the two-byte offset
of
the parameter’s location within the data segment
(DS)
is
pushed onto the stack. If the parameter is a string variable,
the offset points to the
string descriptor.
See the section
“Ac-
cessing String Parameters” in this appendix.
The BASIC return address code segment (CS) and offset (IP)
are pushed onto the stack.
Control is transferred
to
the subroutine by an
8086
long call
to
the segment address given in the last DEF SEG state-
ment and the offset given in
uariabk.
2.
3.
353