News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Converting Linux assembly to MASM for Windows

Started by etairi, December 31, 2017, 12:40:06 AM

Previous topic - Next topic

etairi

I'm quite new to MASM, and don't know the syntax very well. What is the proper way to define constants. For example, under my Linux assembly, I have something like this:

#define reg_p1  rdi
#define reg_p2  rsi

#define m1_0 0xedcd718a828384f8
#define m1_1 0x733b35bfd4427a14
#define m1_2 0xf88229cf94d7cf38
#define m1_3 0x63c56c990c7c2ad6
#define m1_4 0xb858a87e8f4222c7
#define m1_5 0x254c9c6b525eaf5


How would I convert this to MASM?

jj2007

reg_p1 equ <rdi>  ; string, variant 1
reg_p1 equ rdi  ; string, variant 2
somenumericvar = 123  ; number

m1_0=0edcd718a828384f8h
etc

Gunther

Hi etairi,

first of all: Welcome to the forum and have a lot of fun.

jj2007 has already answered your question. The code snippet that you showed is pure C. Here is a detailed description of the #define directive. I hope that this will help you.

Gunther
You have to know the facts before you can distort them.

etairi

@Gunther glad to be here. I know that `#define` is a C directive, but under Linux you can use it inside assembly to define constants, and it works just fine. It's my bad that I showed just the top of my file which contains the define directive. Other parts are pure assembly.

Thank you  @jj2007.

One question, is there any significant difference between `equ` and `textequ`?

jj2007

Quote from: etairi on December 31, 2017, 03:23:37 AMOne question, is there any significant difference between `equ` and `textequ`?

Good question ::)

The manual says something like "textequ behaves as if you had typed exactly that string", but that is a Micros**t manual, as clear as the London fog in the sixties. Empirically speaking, I find 7 occurrences of textequ in my MB source, and 640 of equ. If I had more time, I would start an enquiry in what happens when I replace those 7 with a simple equ.

etairi

Quote from: jj2007 on December 31, 2017, 04:09:56 AM

The manual says something like "textequ behaves as if you had typed exactly that string", but that is a Micros**t manual, as clear as the London fog in the sixties. Empirically speaking, I find 7 occurrences of textequ in my MB source, and 640 of equ. If I had more time, I would start an enquiry in what happens when I replace those 7 with a simple equ.

I see, thanks! :icon14:

Gunther

Hi etairi,

Quote from: etairi on December 31, 2017, 03:23:37 AM
@Gunther glad to be here. I know that `#define` is a C directive, but under Linux you can use it inside assembly to define constants, and it works just fine.
Yes, that's clear. This has to do with the fact that GAS (the GNU assembler) is the backend of the GNU toolchain.

Gunther
You have to know the facts before you can distort them.

hutch--

Hi etairi,

If you are having problems with converting GAS to MASM I would be inclined to use the Intel manuals to identify the GAS instruction names as some of them are slightly different to the menmonic names that MASM uses. I don't know what the reference material is for GAS but it should exist somewhere and this would make the conversion a lot easier.

Gunther

Hi etairi,

by converting vom AT&T to Intel and vice versa, objdump from the binutils package could be your good friend.

Gunther
You have to know the facts before you can distort them.

cyrus

I was wondering how one would convert this block here. I am using a perl script that converts an assembly .s file from openssl to gas, nasm or masm depending on your choice and it convert this block to this block:

.section ".note.gnu.property", "a"
.p2align 3
.long 1f - 0f
.long 4f - 1f
.long 5
0:
# "GNU" encoded with .byte, since .asciz isn't supported
# on Solaris.
.byte 0x47
.byte 0x4e
.byte 0x55
.byte 0
1:
.p2align 3
.long 0xc0000002
.long 3f - 2f
2:
.long 3
3:
.p2align 3
4:

to MASM:

.text$ ENDS
".note.gnu.property" SEGMENT

DD 1f - 0f
DD 4f - 1f
DD 5
0::


DB 047h
DB 04eh
DB 055h
DB 0
1::

DD 0c0000002h
DD 3f - 2f
2::
DD 3
3::

4::

".note.gnu.property" ENDS

it won't compile unless i remove it but was wondering if there was an error with how it is producing it?

NoCforMe

There's no way that's valid assembly-language code.
  • Starts with an ENDS???
  • Segments are so 16-bit DOS ... nobody uses those anymore
  • Double colons? WTF???
  • ".note.gnu.property"   SEGMENT??? Improper use of a quoted string
But I think you already know all this ...
Assembly language programming should be fun. That's why I do it.

mabdelouahab

the .note.gnu.property section is a special section that is used to store additional information about an executable file (or shared libraries) in linux، and "a" = readonly,  you do not need to translate or convert it

See:LD