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

Next revision
Previous revision
calling_20basic_20from_20assembler_20code [2018/03/31 13:19] – external edit 127.0.0.1calling_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:\\ \\ +</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.1522502346.txt.gz · Last modified: 2024/01/05 00:18 (external edit)