Author Topic: masm to nasm  (Read 11890 times)

Offline jdubya

  • Jr. Member
  • *
  • Posts: 7
masm to nasm
« on: December 07, 2013, 03:52:41 AM »
Can anyone tell me how to convert this line of masm code to nasm?

mov array[ESI*Type array], '0'


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: masm to nasm
« Reply #1 on: December 07, 2013, 04:30:40 AM »
You may need to show us how "array" is defined. Nasm wants the entire memory reference inside the square brackets, so...
Code: [Select]
mov [array + esi * ?], '0'
We will also need to specify a size. The character " '0' " looks like a byte to me. However, that would make "Type array" 1, and they probably wouldn't have mentioned it(?). Could be 2, 4, or 8 also. I would guess either:
Code: [Select]
mov byte [array + esi], '0'
or possibly:
Code: [Select]
mov dword [array + esi * 4], '0'
... there are other possibilities...

When I was doing a lot of Masm to Nasm conversion, I used to ask myself, "What does the code need to do here to make sense?" If you can't figure it out from that, show us more of the code..

Best,
Frank


Offline jdubya

  • Jr. Member
  • *
  • Posts: 7
Re: masm to nasm
« Reply #2 on: December 07, 2013, 05:25:52 AM »
You may need to show us how "array" is defined. Nasm wants the entire memory reference inside the square brackets, so...
Code: [Select]
mov [array + esi * ?], '0'
We will also need to specify a size. The character " '0' " looks like a byte to me. However, that would make "Type array" 1, and they probably wouldn't have mentioned it(?). Could be 2, 4, or 8 also. I would guess either:
Code: [Select]
mov byte [array + esi], '0'
or possibly:
Code: [Select]
mov dword [array + esi * 4], '0'
... there are other possibilities...

When I was doing a lot of Masm to Nasm conversion, I used to ask myself, "What does the code need to do here to make sense?" If you can't figure it out from that, show us more of the code..

Best,
Frank
It was defined like this:

array  byte '0','1','2',0
array1 byte '3','4','5',0
array2 byte '6','7','8',0

I changed it to this:

         array         dd '0','1','2',0
         array1        dd '3','4','5',0
         array2        dd '6','7','8',0

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: masm to nasm
« Reply #3 on: December 07, 2013, 06:22:06 AM »
Well... that's a different thing. If you want to not change the meaning...
Code: [Select]
section .data
array db '0', '1', '2', 0
array1 db '3', '4', '5', 0
array2 db '6', '7', '8', 0
;
; and then...
section .text
;
mov byte [array + esi], '0'
;

I don't know why the "* Type array" was in the original Masm code - I don't think it does anything. Of course, I could still be confused about what the Masm code is trying to do. Does it work as expected?

Best,
Frank