strlen = 0x00f6That says that the strlen function is located at address 0x00f6. Since it is already there the only files you will need modify are:
Add the following line to sdk.asm:
.globl _strlenJust add it amongst the other lines that start with ".globl" near the top of the file.
Next add the following lines somewhere near the middle of the file:
_strlen: call pop1 .dw strlenFor instance you could insert them just before the "_strstr:" line.
Next you need to add the function to avsys.h. Add this line:
extern short strlen(unsigned char* s1);
Finally remake the library by typing avmake in the avsdk\lib directory. This compiles sdk.asm in to sdk.rel and creates a new crt.rel by appending the new sdk.rel to startup.rel. You can now call strlen from all your C programs that include avsys.h!
_funcname = funcname
_funcname: call pop1 .dw funcname
_funcname: call pop2 .dw funcname
So what is all this pop1 and pop2 stuff? Gerard explains as follows:
The Avocet compiler passes the first (16-bit) function argument in HL, and the second (16-bit) function argument in DE. The remaining arguments are stored on the stack. The Freeware c compiler pushes all the arguments on the stack, before calling a function. To accomodate for this, I wrote some 'stub code' to call the system functions. Here is how it works:And that's all there is to it.system call with no arguments: just call the function directly
system call with one argument: pop the first argument into HL and call the function system call with two or more arguments: pop the first argument into HL, the second one into DE and call the function.This is what the functions 'pop1' and 'pop2' do.
There seems to be a bit of overhead, but the system call functions are usually slow anyway. The total stubbing code costs about 100 bytes, so no bother here either. I compared assembler listings generated by the Avocet compiler and the freeware compiler. The freeware compiler does a pretty good job (if not better), especially on calling functions and integer math. It generates a bit more code for char datatype operations.
Return to Avigo Agora Main Page