Author Topic: forcing long immediate encoding  (Read 2716 times)

Offline Zdr

  • Jr. Member
  • *
  • Posts: 2
forcing long immediate encoding
« on: July 10, 2011, 01:15:38 PM »
Hello, I use nasm -f bin, but I need very specific encodings to compensate for unusual alignment constraints.

Using "dword" used to force nasm to generate what I want:

and     eax, dword 4        ; 25 04 00 00 00

But now even with "dword" it generates this:

83 e0 04

I understand that this change is a better default for most people, but is there still a way to force it to the long dword immediate encoding? I would prefer not to make my source code unreadable with dd's :-)

Thank you!

Offline Zdr

  • Jr. Member
  • *
  • Posts: 2
Re: forcing long immediate encoding
« Reply #1 on: July 10, 2011, 01:26:58 PM »
Hello, I use nasm -f bin, but I need very specific encodings to compensate for unusual alignment constraints.

Using "dword" used to force nasm to generate what I want:

and     eax, dword 4        ; 25 04 00 00 00

But now even with "dword" it generates this:

83 e0 04

I understand that this change is a better default for most people, but is there still a way to force it to the long dword immediate encoding? I would prefer not to make my source code unreadable with dd's :-)

Thank you!

Ah, I solved my own problem, you now need to add the `strict` qualifier, so 'and eax, strict dword 4' generated the encoding I want.

This works, although the documentation suggests I shouldnt have to use it unless I use optimization (I don't). Maybe that is a bug (either in documentation or nasm)?

Thanks!

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2446
  • Country: us
Re: forcing long immediate encoding
« Reply #2 on: July 10, 2011, 03:04:54 PM »
Yeah... perhaps a defect in the documentation. Optimization is "on" by default now. You can turn it off with "-O0" on the command line, if you want it off throughout the file. As you apparently know, "-O0" used to be the default. Not everyone is happy with the change, but as you say, it's probably a better default for most people. I agree that:

Code: [Select]
and eax, strict dword 4

is uglier than a bulldog's hind end, but it is rarely needed. In your case, "-O0" may be a better choice, for better "control" thoughout.

"You can't please everyone, but with enough command line options, you can give the impression that you're trying! " :)

Best,
Frank