Announcement

Collapse
No announcement yet.

help with calling API's in assembly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help with calling API's in assembly

    could somebody show me a simple demo of how to invoke/call an API using inline assembly?
    like, instead of
    Code:
    Declare Function MessageBoxA etc ..
    FUNCTION PBMAIN() AS LONG
     Call MessageBoxA "Hello"
    END FUNCTION
    would somebody show me how to use nothing but inline assembly to invoke the MessageBoxA API ? i can already use that API directly with PB, but id love to know how to do it with PB's inline asm!

    many thanks in advance for helping an asm newbie try and get more revs out of his now-standalone apps



    ------------------
    -

  • #2
    I believe it's INVOKE..

    What you can do is find the link to lcc compiler, from there you'll asm sites with this info.

    ------------------
    [email protected]
    hellobasic

    Comment


    • #3
      Wayne,

      The problem is that the calling of an API in assembler does not do it any
      better, smaller or faster. In MASM a MessageBox call is as follows,
      Code:
        invoke MessageBox,hWnd,ADDR MsgText,ADDR TitleTxt,MB_OK
        
        manually it looks like this,
        
            push MB_OK
            push offset TitleText
            push offset MsgText
            push hWnd
            call MessageBox
        
        Do the same call in PowerBASIC,
        
        MessageBox hWnd,"Hi Folks","Greetings",%MB_OK
      and it is the same assembler so you do not pick up any advantage by doing so.

      You pick up the simple advantages by using bits of the non critical code
      like "! inc var", "! add var, 5", "! sub var 2". They are small, fast and
      less typing.

      It is supposed to politically and aerodynamically incorrect to use GOTO in
      modern structured code so use the real thing "! jmp label" and you can
      mess up "nice" well behaved code to make it go faster.

      Loops are good value in assembler as well, get the swing of a few basics
      and the overhead is minimal and the speed is very good. there are a
      couple of tricks with loops that help as they get the instruction count
      down which usually means higher speed.

      If you have to increment an ADDRESS in a loop, calculate the number of
      iterations by adding the count to the address and comparing to the result
      to exit. If it is a fixed count loop, put the count in ECX and decrement
      down to zero. at the end of the loop use JZ or JNZ and you save the
      comparison to test for exit.

      Something to keep in mind is what registers are to be preserved. If you
      are using a mixed ASM/API/BASIC function or sub, you can use EAX, ECX and
      EDX freely but remember that other called functions can do the same so
      that if you are storing a value in one of these registers, push them onto
      the stack before the function call and pop them back off after the
      function call.

      Remember to use "#REGISTER NONE" with inline asm code in the function/sub
      as inline asm conflicts with the automatic compiler optimisation that
      uses register variables and you can end up with some strange unpredictable
      results if you forget to use it.

      Regards & keep up the good work.

      [email protected]

      [This message has been edited by Steve Hutchesson (edited October 14, 2000).]
      hutch at movsd dot com
      The MASM Forum

      www.masm32.com

      Comment


      • #4
        Steve, Edwin, excellent - thanks guys! Makes a lot more sense now
        asm is so far out of my league its not funny, but just being able to get a grip on the basics and actually use PB's inline assembly is fantastic
        Mr Zale has added a huge new dimension to my programming, and I never thought i'd be dabbling in assembly _ever_ - until I got PB. the party starts here !




        ------------------
        -

        Comment

        Working...
        X