Author Topic: Converting Linux assembly to MASM for Windows  (Read 162 times)

etairi

  • Regular Member
  • *
  • Posts: 10
Converting Linux assembly to MASM for Windows
« 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:

Code: [Select]
#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

  • Member
  • *****
  • Posts: 7884
  • Assembler is fun ;-)
    • MasmBasic
Re: Converting Linux assembly to MASM for Windows
« Reply #1 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

Gunther

  • Member
  • *****
  • Posts: 3584
  • Forgive your enemies, but never forget their names
Re: Converting Linux assembly to MASM for Windows
« Reply #2 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 is a detailed description of the #define directive. I hope that this will help you.

Gunther
Get your facts first, and then you can distort them.

etairi

  • Regular Member
  • *
  • Posts: 10
Re: Converting Linux assembly to MASM for Windows
« Reply #3 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`?

jj2007

  • Member
  • *****
  • Posts: 7884
  • Assembler is fun ;-)
    • MasmBasic
Re: Converting Linux assembly to MASM for Windows
« Reply #4 on: December 31, 2017, 04:09:56 AM »
One 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

  • Regular Member
  • *
  • Posts: 10
Re: Converting Linux assembly to MASM for Windows
« Reply #5 on: December 31, 2017, 05:14:50 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

  • Member
  • *****
  • Posts: 3584
  • Forgive your enemies, but never forget their names
Re: Converting Linux assembly to MASM for Windows
« Reply #6 on: December 31, 2017, 08:08:31 AM »
Hi 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.
Yes, that's clear. This has to do with the fact that GAS (the GNU assembler) is the backend of the GNU toolchain.

Gunther
Get your facts first, and then you can distort them.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5039
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Converting Linux assembly to MASM for Windows
« Reply #7 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Gunther

  • Member
  • *****
  • Posts: 3584
  • Forgive your enemies, but never forget their names
Re: Converting Linux assembly to MASM for Windows
« Reply #8 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
Get your facts first, and then you can distort them.