Home | Reviews | GUIpedia | Forum | Fun500


HorvatMLinking NASM with QB
Can anyone explain how I can use NASM code with QB? I've looked at this resource http://www.network54.com/Forum/632471/message/1239697530/No,+but+yes but it doesn't explain how QB passes parameters to procedures in libraries. Is it the same as with CALL ABSOLUTE? Examples would be appreciated.
2011-02-158:50 AM

DickRe:Linking NASM with QB
my gui links nasm with qb
2011-02-1511:31 AM

ToddRe:Linking NASM with QB
You 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-1510:42 PM

HorvatMRe:Linking NASM with QB
my 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-163:48 PM

DickRe:Linking NASM with QB
From 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" ;example: 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 ;get it mov si,[bp+6] ;first parameter in this case mov ax,[si] ;modify it add ax,1 ;put it back mov [si],ax pop bp 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
2011-04-223:42 AM

HorvatMRe:Linking NASM with QB
perhaps a good tutorial and reference on mixing asm with QB would make a nice addition to the tutorials section

I'm writing one now.
2011-04-228:58 AM

DickRe:Linking NASM with QB
Very 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. http://www.stanislavs.org/helppc/lds.html http://www.stanislavs.org/helppc/les.html 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.
2011-04-2312:38 AM

HorvatMRe:Linking NASM with QB
I've added some examples.
2011-04-238:32 AM

BASIC Programming Help


2021 Brandon Cornell


Fatal error: Uncaught Error: Call to a member function close() on null in /homepages/11/d157582457/htdocs/mblog/footer.php:20 Stack trace: #0 /homepages/11/d157582457/htdocs/mblog/forum.php(88): include() #1 {main} thrown in /homepages/11/d157582457/htdocs/mblog/footer.php on line 20