calling_20basic_20from_20assembler_20code
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
calling_20basic_20from_20assembler_20code [2018/03/31 13:19] – external edit 127.0.0.1 | calling_20basic_20from_20assembler_20code [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Calling BASIC from assembler code===== | =====Calling BASIC from assembler code===== | ||
- | //by Richard Russell, November 2008//\\ \\ You can't actually **call** BASIC from assembler code, but you can achieve an equivalent capability quite easily. What it involves is returning from the assembler code to BASIC, executing a BASIC procedure, and then re-entering the assembler code at the right place.\\ \\ The first step in achieving this is to modify the way your assembler code is executed. Instead of a simple CALL statement:\\ \\ | + | //by Richard Russell, November 2008//\\ \\ You can't actually **call** BASIC from assembler code, but you can achieve an equivalent capability quite easily. What it involves is returning from the assembler code to BASIC, executing a BASIC procedure, and then re-entering the assembler code at the right place.\\ \\ The first step in achieving this is to modify the way your assembler code is executed. Instead of a simple CALL statement: |
+ | |||
+ | <code bb4w> | ||
CALL code_start | CALL code_start | ||
- | Instead use the following code:\\ \\ | + | </ |
+ | |||
+ | Instead use the following code: | ||
+ | |||
+ | <code bb4w> | ||
B% = USR(code_start) | B% = USR(code_start) | ||
WHILE B% | WHILE B% | ||
Line 9: | Line 15: | ||
B% = USR(P%) | B% = USR(P%) | ||
ENDWHILE | ENDWHILE | ||
- | If you prefer to call your assembler code with SYS then use code similar to the following:\\ \\ | + | </ |
+ | |||
+ | If you prefer to call your assembler code with SYS then use code similar to the following: | ||
+ | |||
+ | <code bb4w> | ||
SYS code_start, parameters TO B% | SYS code_start, parameters TO B% | ||
WHILE B% | WHILE B% | ||
Line 15: | Line 25: | ||
B% = USR(P%) | B% = USR(P%) | ||
ENDWHILE | ENDWHILE | ||
- | It is also necessary to adapt the assembler code entry point itself, as follows:\\ \\ | + | </ |
+ | |||
+ | It is also necessary to adapt the assembler code entry point itself, as follows: | ||
+ | |||
+ | <code bb4w> | ||
DIM mystack% 255, myesp% 3, gap% 2047, mycode% 1000, L% -1 | DIM mystack% 255, myesp% 3, gap% 2047, mycode% 1000, L% -1 | ||
FOR pass% = 8 TO 10 STEP 2 | FOR pass% = 8 TO 10 STEP 2 | ||
Line 27: | Line 41: | ||
xchg esp, | xchg esp, | ||
; rest of assembler code continues here | ; rest of assembler code continues here | ||
+ | </ | ||
+ | |||
Here a //dual stack// arrangement is established, | Here a //dual stack// arrangement is established, | ||
mov eax, | mov eax, |
calling_20basic_20from_20assembler_20code.1522502346.txt.gz · Last modified: 2024/01/05 00:18 (external edit)