Jump to content

Recommended Posts

Posted

After trying few assemblers i have decided to use SASM .

Trying to assemble this code in SASM is giving me errors .

 

section .text

	    global _start       ;must be declared for using gcc

	_start:                     ;tell linker entry point

	    mov edx, len    ;message length

	    mov ecx, msg    ;message to write

	    mov ebx, 1      ;file descriptor (stdout)

	    mov eax, 4      ;system call number (sys_write)

	    int 0x80        ;call kernel

	    mov eax, 1      ;system call number (sys_exit)

	    int 0x80        ;call kernel

	 

	section .data

	 

	msg db  'Hello, world!',0xa ;our dear string

	len equ $ - msg         ;length of our dear string

 

%include "io64.inc"

      section .data
hello   db "Hello World!",0xa
len equ $-hello

    section .text
    global  CMAIN

CMAIN:
    mov eax, 4
    mov ebx, 1
    mov ecx, hello
    mov edx, len
    int 80h

    mov eax, 1 ; exit(0)
    mov ebx, 0
    int 80h 

sasmerror2.png

somepathissues1.png


 

 

Quote

Linker additional configurations:

Sometimes it is necessary to use the ld linker instead of gcc (for example, to compile the program with start entry point).

In Windows, it is needed to replace the end of the path to the linker from "MinGW/bin/gcc.exe" to "MinGW/mingw32/bin/ld.exe" (or "MinGW64/bin/gcc.exe" to "MinGW64/x86_64-w64-mingw32/bin/ld.exe" for 64-bit mode).

I cant get this to work properly due to some settings issue .

Posted (edited)

From what I see "unrecognized emulation mode: 32" is error that you have.

Googling for error phrase is always good idea for a start. It will show you whether other users in the past had similar problems as you encountered, and how they fixed it.

https://www.google.com/search?q=ld.exe+unrecognised+emulation+mode+windows

Try hints from f.e. below links for a start:

https://forum.nasm.us/index.php?topic=1921.0

https://stackoverflow.com/questions/663811/why-do-i-get-the-unrecognised-emulation-mode-32-error-in-eclipse

Edited by Sensei
Posted

Thanks for the reply Sensei

I have few more questions .

What does these options means x86 , x64 . Is it an option to choose between 32 bit vs 64 bit ?

I think the error is somewhere here in the .

Assembler path

or

Linker path

wrongq1.png

wrongq2.png

Posted (edited)
1 hour ago, bimbo36 said:

What does these options means x86 , x64 . Is it an option to choose between 32 bit vs 64 bit ?

Yes, compilation to different platform.

1 hour ago, bimbo36 said:

I think the error is somewhere here in the .

Assembler path

or

Linker path

I don't think so. Rather in "Assembly options" or "Linking options"

You can run cmd.exe from Start, then go to these folders (mentioned in settings window that you showed in screen-shot) and run from command-line gcc/nasm/ld manually.

Show list of options using /?

Read manual of nasm/ld what options are available.

And experiment..

Edited by Sensei
Posted

Thanks for the reply .

I solved it

The issue was in the code itself . Not with the Assembler path or Linker path .

I edited a little code from this .

%include "io64.inc"

      section .data
hello   db "Hello World!",0xa
len equ $-hello

    section .text
    global  CMAIN

CMAIN:
    mov eax, 4
    mov ebx, 1
    mov ecx, hello
    mov edx, len
    int 80h

    mov eax, 1 ; exit(0)
    mov ebx, 0
    int 80h 

 

to this .

 

%include "io.inc"

      section .data
hello   db "Hello World!",0xa
len equ $-hello

    section .text
    global  CMAIN

CMAIN:
    mov eax, 4
    mov ebx, 1
    mov ecx, hello
    mov edx, len
    int 80h

    mov eax, 1 ; exit(0)
    mov ebx, 0
    int 80h 

wrongq1.png

solved.png

And it works .

 

Posted

If anyone is looking for more examples , these are all working examples .I thought i would share it here .

Linux ASM example

section    .text
   global _start    ;must be declared for linker (gcc)
    
_start:             ;tell linker entry point
   mov    edx,len  ;message length
   mov    ecx,msg  ;message to write
   mov    ebx,1    ;file descriptor (stdout)
   mov    eax,4    ;system call number (sys_write)
   int    0x80     ;call kernel
    
   mov    edx,9    ;message length
   mov    ecx,s2   ;message to write
   mov    ebx,1    ;file descriptor (stdout)
   mov    eax,4    ;system call number (sys_write)
   int    0x80     ;call kernel
    
   mov    eax,1    ;system call number (sys_exit)
   int    0x80     ;call kernel
    
section    .data
msg db 'Displaying 9 stars',0xa ;a message
len equ $ - msg  ;length of message
s2 times 9 db '*'

Hello world windows

%include "io.inc"

section .data
    msg db 'Hello, world!', 0

section .text
    global CMAIN
CMAIN:
    mov ebp, esp
    PRINT_STRING msg
    NEWLINE
    xor eax, eax
    ret

Hello world 2 ; windows

%include "io.inc"

section .text
global CMAIN
CMAIN:
    mov ebp, esp; for correct debugging
  ; ----------------------------------------------------------------------------
; hello.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits.  It uses only plain Win32 system calls from kernel32.dll, so it
; is very instructive to study since it does not make use of a C library.
; Because system calls from kernel32.dll are used, you need to link with
; an import library.  You also have to specify the starting address yourself.
;
; Assembler: NASM
; OS: Any Win32-based OS
; Other libraries: Use gcc's import library libkernel32.a
; Assemble with "nasm -fwin32 hello.asm"
; Link with "ld -e go hello.obj -lkernel32"
; ----------------------------------------------------------------------------

        global  go
        extern  _ExitProcess@4
        extern  _GetStdHandle@4
        extern  _WriteConsoleA@20
        extern  _ReadConsoleA@20

        section .data
msg:    db      'Hello, World', 10
handle:         dd      0
read_handle dd 0
written:        db      0

        section .text
go:
        ; handle = GetStdHandle(-11)
        push    dword -11
        call    _GetStdHandle@4
        mov     [handle], eax

        push -10  ; stdin
        call _GetStdHandle@4
        mov [read_handle], eax

        ; WriteConsole(handle, &msg[0], 13, &written, 0)
        push    dword 0
        push    written
        push    dword 13
        push    msg
        push    dword [handle]
        call    _WriteConsoleA@20

        push eax
        mov eax, esp ; buffer for char?
        push 0
        push written ; reuse this?
        push 1 ; characters to read?
        push eax
        push dword [read_handle]
        call  _ReadConsoleA@20
        pop eax ; character read in al?

        ; ExitProcess(0)
        push    dword 0
        call    _ExitProcess@4
    xor eax, eax
    ret

 

Posted

No i just got it from different places .

The last two works in SASM , which is why posted here

I like that IDE

I am collecting examples and i want everything to work inside SASM IDE .

I have only started learning Assembly like a week ago .But i am going to stick with it for the rest of my life

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.