flat assembler
Message board for the users of flat assembler.

Index > Heap > Linking NASM with Delphi

Author
Thread Post new topic Reply to topic
Nameless



Joined: 30 Apr 2010
Posts: 95
Nameless
im trying to link NASM .obj files, i tried everything there is but no hope, it wont call any imported API (access violation) :S
here is my code

Code:
//Delphi;
program test;

uses Windows;
 
{$LINK test_asm.obj}

function start: Integer; external;

begin
 start;
end.
    


Code:
extern MessageBoxA
;import MessageBoxA, user32.dll

section _data USE32
 txt: db "this is a test", 0

section _bss USE32
 s: resb 5

section _text USE32
global start
start:
 pusha
 push 0
 push txt
 push txt
 push 0
 call [MessageBoxA]
 popa
 mov   eax, 5
 ret
    


it works ok when using "mov eax, 4", the result is displayed, but when using api, no


[/code]
Post 12 Sep 2010, 16:00
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Nameless,

It works when you've replaced mov eax, 5 with mov eax, 4 in your start function? I.e. it displays message box (and fails to do so when mov eax, 5 is in place)?
Post 12 Sep 2010, 16:11
View user's profile Send private message Reply with quote
Nameless



Joined: 30 Apr 2010
Posts: 95
Nameless
no, when removed the messagebox totally it works
mov eax, x got nothing to do with the error at all
Post 12 Sep 2010, 16:21
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Nameless,

I'll try to install Delphi 7 and check it out, as a tribute to my Turbo Pascal programming days. Wink

Meanwhile, you may try to use [__imp__MessageBoxA@16] or [__imp__MessageBoxA] instead of [MessageBoxA].
Post 12 Sep 2010, 17:07
View user's profile Send private message Reply with quote
Nameless



Joined: 30 Apr 2010
Posts: 95
Nameless
i tried it everywhere, both of them
none worked Sad
Post 12 Sep 2010, 17:20
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Nameless,

I've got it. Use call MessageBoxA (i.e. without square brackets), it will run fine. Probably if you've attached .Exe, the solution came naturally.
Post 12 Sep 2010, 17:39
View user's profile Send private message Reply with quote
Nameless



Joined: 30 Apr 2010
Posts: 95
Nameless
that was too easy Smile, is there a reason for that? since it works as an exe with the square brackets!

thank you xD
Post 12 Sep 2010, 20:50
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Nameless,

How it worked with square brackets? GPF?
Code:
; This is a part of your code
        call    [MessageBoxA]
; This code comes from import library/unit/whatever
MessageBoxA:
        jmp     [__imp__MessageBoxA]
; This dword is patched by loader with actual User32!MessageBoxA address
; It is a part of import address table
__imp__MessageBoxA rd 1    
call [MessageBoxA] transfers control to address YYXX25FF (FF 25 is opcode for indirect near jump, XX YY are two lower bytes of address of pointer to actual User32!MessageBoxA, __imp__MessageBoxA). Unneeded extra level of indirection. call MessageBoxA works as expected.
Post 13 Sep 2010, 05:43
View user's profile Send private message Reply with quote
Nameless



Joined: 30 Apr 2010
Posts: 95
Nameless
im making progress here Very Happy, i understood it after reading it 12 times only !
im getting gooooooooood Very Happy

all thanks to you, i owe u alot Smile
Post 13 Sep 2010, 11:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.