News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

converting Fasm to Gas with .intel_syntax noprefix

Started by bobl, October 07, 2009, 09:23:12 PM

Previous topic - Next topic

bobl

Heres some Fasm code.

section ".text"
   mov ebx, label_1
section ".data"
   label_1 db "some_string", 0

Could someone please show me how you would convert this to "standard" intel syntax.
Thx in anticipation

nathanpc

#1
Welcome!
As i can see, this is Fasm syntax and this is not about Masm, then the correct place to post this is in the Fasm board.

Thanks!

nathan,

Admin handles problems like this if they arise, leave it to us.

dedndave

i am not so sure you really want intel syntax - lol
i have not seen the intel assembler in use since about 1985
for masm (more or less "the" standard), it would look like this...

        .code

        mov     ebx,label_1

        .data

label_1 db "some_string",0

sinsi


.code
  mov ebx,OFFSET label_1
.data
label_1 db "some_string", 0

FASM doesn't use OFFSET.

dave, your masm code in fasm would be "mov ebx,[label_1]"
Light travels faster than sound, that's why some people seem bright until you hear them.

qWord

my suggestionfor masm:    .data
    label_1 db "some_string", 0
    .code 
    mov ebx,OFFSET label_1


PS: masm doesn't support forward referencing

FPU in a trice: SmplMath
It's that simple!

dedndave

it will forward reference a label - but i did miss the offset - lol

GregL

bobl,

I fiddled around with as (Gas) for a short while. It would be something like this


.intel_syntax noprefix
.arch pentium
.global _start

.data

    label_1: .asciz "some_string"

.text

    mov ebx, OFFSET label_1

.end




Get the manual, it's included in the GNU binutils download and it's decent.  I could post some of the simple programs I wrote with it if you would like.



bobl

Nathan
I did ask on the Fasm forum ie http://board.flatassembler.net/topic.php?p=102970#102970
I think the Gas forum would've been a good place to go but couldn't see one last night.

Dedndave and Sinsi
Thx for the masm conversion and I only asked here cos I thought Microsoft and Intel were thick together and so masm would be more likely to follow intel syntax.

Greg
Thx for the conversion, the binutils documentation and offer of some sample programs.
I'd very much like to take you up on that offer if you don't mind as all the documentation I looked at last night didn't have intel syntax.

Overall I'm extremely impressed with your helpfulness on this forum so thanks very much indeed.
I use Powerbasic at every opportunity so you will be seeing me on this site more when I've finished this g++ program.

hutch--

bobl,

MASM is the main Intel notation assemblr and much of its lower level notation can be used with little change in the GNU "AS.EXE" assembler. GAS is in fact a very good tool once you get the swing of it and from memory it had a reasonable macro engine in it as well so with a little work you should be reasonably productive with it. Here is a seperate module I could find written in a version of GAS of about 2005.


/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */

   /*************************
    assemble this module only
    *************************/


    .intel_syntax noprefix
    .global szcopy

/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */

    .text

  .align 8
  szcopy:

    mov ecx, [esp+4]
    mov edx, [esp+8]

    push ebx
    xor ebx, ebx

  cpy:
  .rept 3
    mov al, [ecx+ebx]
    mov [edx+ebx], al
    add ebx, 0x01
    test al, al
    jz cpout
  .endr

    mov al, [ecx+ebx]
    mov [edx+ebx], al
    add ebx, 0x01
    test al, al
    jnz cpy

  cpout:

    pop ebx

    ret 8

/*«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/


This is the batch file I built it with back then.


@echo off

if exist module.exe del module.exe
if exist module.obj del module.obj

\gas\bin\as -o module.obj module.as
\gas\bin\ld -e_entry -subsystem windows -L\gas\lib -o module.exe module.obj szcopy.obj --library=masm32 --library=user32 --library=kernel32 --library=gdi32 --library=Comctl32 --library=comdlg32 --library=shell32 --library=oleaut32 --library=ole32 --library=msvcrt -s

dir module.*

pause
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bobl

Hutch
Re masm's similarity and gas' functionality, that's very reassuring.
Your intel syntax example is just what I need at the moment cos I couldn't find one on google last night.
Hopefully the binutils documentation Greg referred to might have a few.
Intel syntax seems more straight forward than AT&T hence my wish to stick with it if I can.
Thanks very much for your help

nathanpc

Hi bobl,
If you want to use C, you can do like this:
gcc -S hello.c
And gcc will convert your C source code in Gas source code.

Take a look at:
Hope I'm Helping,
Nathan Paulino Campos

bobl

Yes Nathan your post is very helpful i.e. that second link about using gcc -S is helpful re understanding how to call a gas function from g++.
I've been using the extern "C" command cos name-mangling in c++ is not consistent across different compilers.
gas looks similar to the other assemblers re this in that it seems only to require the function name in a global statement and as a label + ret.
Thanks for your help.

bobl

BTW I didn't get a manual with my binutils and looking at the sources it seems to come in a weird format but I found it here in nice html.
http://sourceware.org/binutils/docs-2.19/as/
It's certainly detailed but seems more of a reference for a seasoned asm man than a how-to for a beginner.
I'm sure it will be of use as a reference however once I get up to speed.


MichaelW

I posted a set of invoke macros for GAS, along two example apps, here:

http://www.masm32.com/board/index.php?topic=8689.0

Note that the macros require a relatively recent version of GAS (2.18.5+).

I recall seeing in a GAS source file recently a comment indicating that the Intel syntax was based on the MASM BNF Grammar that Microsoft included in the programmer's guide. This would explain why the basic syntax is so close to MASM (although the GAS macro system is very different than the MASM macro system and, by comparison, very weak).
eschew obfuscation

bobl

Thanks very much Michael. I've got 2.19.
Wow I nearly missed the examples link.
That's great!
I see there's some DOS ones in there too.
Thx
Shame about the macros being weak cos some of my higher level code is dependent upon them and this may well be the case with asm.