Author Topic: Alink problem  (Read 3587 times)

nobody

  • Guest
Alink problem
« on: September 06, 2008, 10:39:19 PM »
Code: [Select]
; assemble: nasm -f obj hwmb.asm
; link: alink -oPE hwmb .obj win32.lib

extern MessageBoxA

segment .data USE32

title1 db 'A Windows Program', 0
string1 db 'Look, Ma! A Windows program!', 0

segment .text USE32

..start:
push dword 0Eh ; OK button
push dword title1
push dword string1
push dword 0
call MessageBoxA

ret

I am learning assembly and so I wanted to see if I could get this working...which once I got through the error....

colon was required after start,

I tried to use alink to link it, but everytime I do it displays:

loading file helloworld.obj
error opening file .obj

I tried looking for different erros alink would have on google to help me fix this but with no luck,
could someone help me?  Thanks

nobody

  • Guest
Re: Alink problem
« Reply #1 on: September 07, 2008, 04:16:43 PM »
Hi,
On the link line you enter the filename as "hwmb.obj"  yet ALINK throws an error on the name "helloworld". Is it possible that you are entering a longname which ALINK doesn't recognize ?

If you're committed to using ALINK then the following answer won't help.But if you want to use GOLINK the following code will work.

GOLINK can be found at :

http://www.jorgon.freeserve.co.uk/

These are the assemble/link commands for NASM/GOLINK

;=============================
nasm -f win32 tester.asm -o tester.obj

golink.exe  /entry:start tester.obj user32.dll
;=============================

The INCLUDE paths are, of course, valid only on my machine. You'll need to change them for your work.

Notice that the second INCLUDE is REMMed out because it requires a file (NASM32.INC) which will enable the INVOKE command. NASM32.INC is a file which comes with the NASM32 package from AsmCommunity.com.
I'm sure SourceForge has a similar macro file here I've just never had to use it.

http://www.asmcommunity.net/projects/nasmx/

;==============================
%include '\nasm32\inc\win32\windows.inc'
;;;%include '\nasm32\inc\nasm32.inc'

extern MessageBoxA

;======== DATA

.data
title1 db 'A Windows Program', 0
string1 db 'Look, Ma! A Windows program!', 0

;==========CODE

.code
start:

;========== YOUR WAY

push MB_OK
    push title1
    push string1
    push 0
    call MessageBoxA


;======= A DIFFERENT WAY
;INVOKE requires a macro file similar to NASM32.INC to work.

;    invoke MessageBoxA,0,string1,title1,MB_OK
    ret

;
;hth
;mcamember
;

nobody

  • Guest
Re: Alink problem
« Reply #2 on: September 09, 2008, 12:01:16 PM »
You are assembling your code using
the omf object format (-fobj), no the coff object format (-fwin32), so you have
some errors in your code and you don't
need to use win32.lib when you link
you object file:

Try:

; assemble: nasm -f obj hwmb.asm
; link: alink -oPE hwmb.obj

import MessageBox     user32.dll MessageBoxA ; <--
extern MessageBox ; <--

segment .data USE32  

title1 db 'A Windows Program', 0
string1 db 'Look, Ma! A Windows program!', 0  

segment .text USE32  

..start:
push dword 0Eh ; OK button
push dword title1
push dword string1
push dword 0
call [MessageBox] ; <--

ret

;-----

If you want to use the coff object format, try:

; assemble: nasm -fwin32  hwmb.asm ; <--
; link: alink -oPE hwmb.obj win32.lib -entry start -o hwmb.exe ; <--

%define MessageBox MessageBoxA
extern MessageBox

section .data

title1 db 'A Windows Program', 0
string1 db 'Look, Ma! A Windows program!', 0

section .text ; <--
global start

start:  ; <--
push dword 0Eh ; OK button
push dword title1
push dword string1
push dword 0
call MessageBox ; <--

ret

nobody

  • Guest
Re: Alink problem
« Reply #3 on: September 14, 2008, 09:08:42 AM »
Other ideas: VALX linker, FASM (no need for a linker)