User Tools

Site Tools


calling_20basic_20from_20assembler_20code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

calling_20basic_20from_20assembler_20code [2018/03/31 13:19]
127.0.0.1 external edit
calling_20basic_20from_20assembler_20code [2018/04/13 10:40]
richardrussell
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:\\ \\ +</​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:\\ \\ +</​code>​ 
 + 
 +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:\\ \\ +</​code>​ 
 + 
 +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,​[saved_esp]           xchg esp,​[saved_esp]
           ; rest of assembler code continues here           ; rest of assembler code continues here
 +</​code>​
 +
 Here a //dual stack// arrangement is established,​ where **mystack%** is a 256-byte memory area containing the second stack. Needless to say, you should increase (or decrease) the amount of memory allocated for the assembler code (here shown as 1000 bytes) as required.\\ \\  When you want to '​call'​ a BASIC procedure from assembler code, do so as follows:\\ \\  Here a //dual stack// arrangement is established,​ where **mystack%** is a 256-byte memory area containing the second stack. Needless to say, you should increase (or decrease) the amount of memory allocated for the assembler code (here shown as 1000 bytes) as required.\\ \\  When you want to '​call'​ a BASIC procedure from assembler code, do so as follows:\\ \\ 
           mov eax,​^PROCsomething           mov eax,​^PROCsomething
calling_20basic_20from_20assembler_20code.txt · Last modified: 2018/04/13 10:40 by richardrussell