Home | Reviews | GUIpedia | Forum | Fun500
|Dick||Re:Linking NASM with QBmy gui links nasm with qb||2011-02-15||11:31 AM|
|Todd||Re:Linking NASM with QBYou make a declaration in a BI (BASIC Include) file for the library you want to use and then write your code. QB will compile the code and link it with the code in your library. In ASM, parameters aren't passed through CALL ABSOLUTE. When the machine code notices a branch/procedure call, it loads the parameters onto a stack and calls the function. It then loads the BP (base pointer) to the address of the parameter stack and the library code can pop one parameter at a time off the stack to use as necessary.
See the NASM manual: http://www.nasm.us/doc/nasmdoc8.html||2011-02-15||10:42 PM|
|HorvatM||Re:Linking NASM with QBmy gui links nasm with qb
I wonder why I didn't think of that before.
When the machine code notices a branch/procedure call, it loads the parameters onto a stack and calls the function.
I understand that. But, how do you return a value to QB, you know, like a FUNCTION? I know that QB gets the returned value from the stack, but where precisely on the stack? Do you simply pop all your parameters (increase SP) and put the returned value (or a pointer to it?) on the top?||2011-02-16||3:48 PM|
|Dick||Re:Linking NASM with QBFrom the nasm manual: "by saving the value of SP in BP so as to be able to use BP as a base pointer to find its parameters on the stack. However, the caller was probably doing this too, so part of the calling convention states that BP must be preserved by any C [QBasic] function"
push bp ;saves bp
mov bp,sp ;save value of sp in bp to find parameters
;this next line loads the pointer of the variable that was
;passed, retrieves it's actual value and puts it in AX, then
;performs addition instruction and puts the result back into
;the variable, sort of like FUNCTION but it's not
mov si,[bp+6] ;first parameter in this case
;put it back
retf 2 ;2 bytes passed (1 integer)
you can also pass BYVAL and with SEG, which some of my asm programs in the code section do and you can look into them to find out how they work.
perhaps a good tutorial and reference on mixing asm with QB would make a nice addition to the tutorials section
|HorvatM||Re:Linking NASM with QBperhaps a good tutorial and reference on mixing asm with QB would make a nice addition to the tutorials section
I'm writing one now.
|Dick||Re:Linking NASM with QBVery good tutorial, well done. One thing is that there is a difference in strings and memory between QB 4.5 and QB 7.1. I think QB 4.5 limits strings to a 64kb near pointer space while QB 7.1 uses far pointers for strings or something like that. And there are some different compiler options in them that may change the way things are accessed from assembly. I don't use QB 7.1 and I don't like it. Other than that, I am very happy that you took the time to make this type of reference available. I think one thing to add would be a few examples of mixing nasm and QB, accessing strings, and stuff because examples are helpful and allow a start for the programmer to work from. As far as passing things with SEG, you can use LES and LDS instructions to nicely load those far pointers, though you can load ES,DS,SI,DI seperately.
Anyways, well done and if you have any ideas on some good examples to work from, feel free to email me and I will do my best to make them if needed.
|HorvatM||Re:Linking NASM with QBI've added some examples.||2011-04-23||8:32 AM|
BASIC Programming Help
2021 Brandon Cornell