Author Topic: Problems building NASM using SASM  (Read 11625 times)

Offline magnusbbc

  • Jr. Member
  • *
  • Posts: 3
Problems building NASM using SASM
« on: June 10, 2016, 07:52:39 PM »
Hi everyone,

I'm new at the forum and at assembler programming.

I have been using Dr Paul Carter's book (link) to help me learn assembly. To write, build, and debug NASM I have been using the SASM IDE. However when I built the following code:

Code: [Select]
%include "asm_io.inc"

segment .data

prompt1 db    "Enter a number: ", 0       ; don't forget nul terminator
prompt2 db    "Enter another number: ", 0
outmsg1 db    "You entered ", 0
outmsg2 db    " and ", 0
outmsg3 db    ", the sum of these is ", 0



segment .bss

input1  resd 1
input2  resd 1

 


segment .text
        global  _main
_main:
        enter   0,0               ; setup routine
        pusha

        mov     eax, prompt1      ; print out prompt
        call    print_string

        call    read_int          ; read integer
        mov     [input1], eax     ; store into input1

        mov     eax, prompt2      ; print out prompt
        call    print_string

        call    read_int          ; read integer
        mov     [input2], eax     ; store into input2

        mov     eax, [input1]     ; eax = dword at input1
        add     eax, [input2]     ; eax += dword at input2
        mov     ebx, eax          ; ebx = eax
        dump_regs 1               ; dump out register values
        dump_mem 2, outmsg1, 1    ; dump out memory
;
; next print out result message as series of steps
;
        mov     eax, outmsg1
        call    print_string      ; print out first message
        mov     eax, [input1]     
        call    print_int         ; print out input1
        mov     eax, outmsg2
        call    print_string      ; print out second message
        mov     eax, [input2]
        call    print_int         ; print out input2
        mov     eax, outmsg3
        call    print_string      ; print out third message
        mov     eax, ebx
        call    print_int         ; print out sum (ebx)
        call    print_nl          ; print new-line

        popa
        mov     eax, 0            ; return back to C
        leave                     
        ret

I get this error:

Code: [Select]
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0xb): undefined reference to `print_string'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x10): undefined reference to `read_int'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x1f): undefined reference to `print_string'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x24): undefined reference to `read_int'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x3d): undefined reference to `sub_dump_regs'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x4b): undefined reference to `sub_dump_mem'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x55): undefined reference to `print_string'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x5f): undefined reference to `print_int'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x69): undefined reference to `print_string'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x73): undefined reference to `print_int'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x7d): undefined reference to `print_string'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x84): undefined reference to `print_int'
C:\Users\Chris\AppData\Local\Temp\SASM\program.o:C:\Users\Chris\Ap:(.text+0x89): undefined reference to `print_nl'

From reading the previous post on this issue (Link) I am of understanding that I have to somehow link the asm_io.obj , however I don't know how to do that - I think I have to change some settings within the settings window:



any help is greatly appreciated.

Thanks in advance.


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problems building NASM using SASM
« Reply #1 on: June 11, 2016, 02:02:34 AM »
Hi magnusbbc,

Welcome to the forum!

The way Dr. Carter's stuff is "supposed" to be linked involves "driver.c" - a stub of C code which simply calls "asm_main", and your code will include:
Code: [Select]
global asm_main
asm_main:
However, your "first.asm" starts with:
Code: [Select]
global _main
_main:
I think this will work, simply bypassing "driver.c" - but it won't match exactly what it says in the book. Change it to "asm_main" and add "driver.c" to the "linker options" if you care.

As a one-time job, you will need to assemble "asm_io.asm" to "asm_io.obj":
Code: [Select]
nasm -f win32 -d COFF_TYPE asm_io.asm
then add "asm_io.obj" to the "linker options". Add "driver.c" too, if you're going to do it that way.

I see "$MACROS.OBJ$". I'm not sure what that refers to. You may want to remove it, if SASM complains about not being able to find it. May not hurt to leave it there.

Try something like:
Code: [Select]
linker options: $PROGRAM.OBJ$ asm_io.obj -o $PROGRAM% -g -m32
or perhaps:
Code: [Select]
linker options: driver.c $PROGRAM.OBJ$ asm_io.obj -o $PROGRAM% -g -m32
and see if that clears up the errors. You're on the right track, I think. I'm not actually familiar with SASM, but I think I see what it does...

Best,
Frank


Offline magnusbbc

  • Jr. Member
  • *
  • Posts: 3
Re: Problems building NASM using SASM
« Reply #2 on: June 11, 2016, 06:50:22 PM »
Thanks a lot for the help Frank

When I try to remove

Code: [Select]
linker options: $PROGRAM.OBJ$ $MACRO.OBJ$ -g -o $PROGRAM$ -m32
I get the following error:

Code: [Select]
[20:46:03] Warning! Errors have occurred in the build:
gcc.exe: error: : No such file or directory
gcc.exe: fatal error: no input files
compilation terminated.

I tried both appending and substituting
Code: [Select]
$PROGRAM.OBJ$ asm_io.obj -o $PROGRAM% -g -m32
to the linker options, however in both cases sasm returns the following error:

Code: [Select]
[20:47:25] Warning! Errors have occurred in the build:
gcc.exe: error: asm_io.obj: No such file or directory

I have tried placing the asm_io.obj file in both the gcc.exe directory, aswell as the asm_io.inc directory.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problems building NASM using SASM
« Reply #3 on: June 11, 2016, 07:16:06 PM »
I should have mentioned that "asm_io.obj" (it is called ".obj", not ".o", right?) needs to be where SASM can find it - same directory as "first.asm" should work(?). I really don't know how SASM arranges things...

Courage!
Frank


Offline magnusbbc

  • Jr. Member
  • *
  • Posts: 3
Re: Problems building NASM using SASM
« Reply #4 on: June 12, 2016, 08:00:31 PM »
Thanks a lot for the help frank, i tried placing "asm_io.obj" in the "first.asm" directory, unfortunatly I still receive the same error. Would you happen to know of a different NASM IDE that would make it easier to link?


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problems building NASM using SASM
« Reply #5 on: June 13, 2016, 01:54:03 AM »
I usually work from the command line. Gotta type all that crap in once, but then just hit "up-arrow" to repeat it. I've used Jeff Owens' "asmide". It has a great built-in help system covering the system calls, but it's for Linux and won't do you any good. You could try using the full path: "C:\Program Files\pcasm\asm_io.obj" or whatever it is. You may need to do the same with "driver.c" if you're using it. It may help to use the "short name" (which is the "true name") "Progra~1" instead of the name with the space in it. A program is liable to interpret that as two options, "C:\Program" and "Files\..." - and not find either of them. Once you find the "trick" to this it will probably seem obvious. Something you'd have to go through with any IDE.

Best,
Frank