Results 1 to 14 of 14

Thread: Inline assembly

  1. #1
    Guest

    Post

    For some reason the assembly i learned wont work as inline in Visual C++. Could someone post a link to a tutorial or an example or a reason why it wont work. Thanks.

  2. #2
    Guest
    Anyone?

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Could you post your assembly code so we can see what isn't working.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Hmm...don't use the inline keyword...
    Code:
    long myfunc(long in) {
        __asm {
            mov eax, in
        }
    }
    That just returns the supplied value.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Guest
    This line would create an error...

    Code:
    _asm    mov    hAppInstance, hInstance

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try:
    Code:
    push ebx
    mov ebx, hInstance
    mov hAppInstance, ebx
    pop ebx
    There probably isn't a direct path from memory->memory like that (I don't know).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Guest
    That worked, so apparently everything i learned in ASM for Windows, is crap. So as an example for me could someone turn this piece of code into ASM for me? Thanks.

    Code:
    while(GetMessage(&Msg, NULL, 0, 0))
    {			
    	if(doit == 1)
    	{					
    		GetCursorPos(&Mouse2);				
    		if(Mouse2.x != Mouse.x || Mouse2.y != Mouse.y)
    		{
    			GetCursorPos(&Mouse);
    			Window = WindowFromPoint(Mouse);
    			Window = ChildWindowFromPoint(Window, Mouse);
    			Hdc = GetWindowDC(Window);
    												
    			Colors = GetPixel(Hdc, Mouse.x, Mouse.y);
    
    			Red = GetRValue(Colors);
    			Green = GetGValue(Colors);
    			Blue = GetBValue(Colors);
    
    			SetDlgItemInt(hMainDialog, ID_EDIT_RED, Red, FALSE);
    			SetDlgItemInt(hMainDialog, ID_EDIT_GREEN, Green, FALSE);
    			SetDlgItemInt(hMainDialog, ID_EDIT_BLUE, Blue, FALSE);	
    			SetDlgItemInt(hMainDialog, ID_EDIT_HEX, Colors, FALSE);
    		}			
    	}
    
    	TranslateMessage(&Msg);
    	DispatchMessage(&Msg);
    }

  8. #8
    Guest
    If i made an ass out of myself by asking all that, then could someone do a paragraph on calling an API function. In MASM i learned to do it this way...

    VC++
    Code:
    Colors = GetPixel(Hdc, Mouse.x, Mouse.y);
    MASM
    Code:
    call   GetPixel, Hdc, Mouse.x, Mouse.y
    mov    Colors, eax
    Or something like that. But when i do that in VC++, i get errors everytime. So could ya just explain how to call API. Thanks.

  9. #9
    Guest
    Anyone? Just a paragraph or two on how to call an API?

  10. #10
    Guest
    Is that to much to ask?

  11. #11
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    I'm not really sure, but I think you have to push the parameters in reverse order:

    Code:
    push   Mouse.y
    push   Mouse.x
    push   Hdc 
    call   GetPixel
    mov    Colors, eax
    I hope this works,

    Me.
    Courgettes.

  12. #12
    Guest
    I looked around some tutorials for TASM, just to see if i could find an answer. Well thats what i found, and for some reason that wont work either. I think VC++ has its own way of doing ASM. But thanks for trying though. And i know im whining in this thread, but because the code is in the message loop, its really slow. So i want to replace the whole message loop so it will go faster. But thanks though...

    Anyone else?

  13. #13
    Guest
    Hey parksie, any suggestions?

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Red face (slurs words)

    Not really...

    VC++ uses normal ASM. The thing about MASM (or possibly TASM), is that it uses different non-standard syntax to make it easier to call functions, rather than V(ery)'s utterly correct method of pushing them onto the stack. By the way, that's what __stdcall means - doing that. The other conventions have different methods, but that is the easiest to implement in nearly all cases.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width