The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: etairi on December 31, 2017, 12:40:06 AM

Title: Converting Linux assembly to MASM for Windows
Post by: etairi on December 31, 2017, 12:40:06 AM
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?
Title: Re: Converting Linux assembly to MASM for Windows
Post by: jj2007 on December 31, 2017, 12:55:10 AM
reg_p1 equ <rdi>  ; string, variant 1
reg_p1 equ rdi  ; string, variant 2
somenumericvar = 123  ; number

m1_0=0edcd718a828384f8h
etc
Title: Re: Converting Linux assembly to MASM for Windows
Post by: Gunther on December 31, 2017, 01:07:11 AM
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 (https://www.techonthenet.com/c_language/constants/create_define.php) is a detailed description of the #define directive. I hope that this will help you.

Gunther
Title: Re: Converting Linux assembly to MASM for Windows
Post by: 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. 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`?
Title: Re: Converting Linux assembly to MASM for Windows
Post by: jj2007 on December 31, 2017, 04:09:56 AM
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.
Title: Re: Converting Linux assembly to MASM for Windows
Post by: etairi on December 31, 2017, 05:14:50 AM
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:
Title: Re: Converting Linux assembly to MASM for Windows
Post by: Gunther on December 31, 2017, 08:08:31 AM
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
Title: Re: Converting Linux assembly to MASM for Windows
Post by: hutch-- on January 08, 2018, 10:52:45 AM
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.
Title: Re: Converting Linux assembly to MASM for Windows
Post by: Gunther on January 08, 2018, 09:00:47 PM
Hi etairi,

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

Gunther
Title: Re: Converting Linux assembly to MASM for Windows
Post by: cyrus on January 31, 2024, 10:14:44 AM
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?
Title: Re: Converting Linux assembly to MASM for Windows
Post by: NoCforMe on February 01, 2024, 01:04:17 PM
There's no way that's valid assembly-language code.
But I think you already know all this ...
Title: Re: Converting Linux assembly to MASM for Windows
Post by: mabdelouahab on February 01, 2024, 06:31:31 PM
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 (https://docs.adacore.com/live/wave/binutils-stable/pdf/ld/ld.pdf)