Author Topic: How to rename reserved words in the NASM?  (Read 6344 times)

Offline MIchael

  • Jr. Member
  • *
  • Posts: 10
How to rename reserved words in the NASM?
« on: May 27, 2018, 08:32:01 AM »
Is it possible to change the names of instructions or directives with the help of directives or other means of the NASM compiler? For example:
Code: [Select]
%iredefine mov        NASM@move
%iredefine %iredefine PRE@redefine
PRE@redefine push     NASM@push
PRE@redefine syscall  NASM@syscall

section .text
    global _start

    _start:
        NASM@move  rax, 0x4142434445464748
        NASM@push  rax
        NASM@move  rdx, 0x8
        NASM@move  rsi, rsp
        NASM@move  rax, 0x1
        NASM@move  rdi, 0x1
        NASM@syscall

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How to rename reserved words in the NASM?
« Reply #1 on: May 27, 2018, 07:04:43 PM »
Code: [Select]
bits 64

%define NASM@move mov
%define NASM@push push
%define NASM@syscall syscall

section .text
    global _start

    _start:
        NASM@move  rax, 0x4142434445464748
        NASM@push  rax
        NASM@move  rdx, 0x8
        NASM@move  rsi, rsp
        NASM@move  rax, 0x1
        NASM@move  rdi, 0x1
        NASM@syscall

All these people that you mention
Yes, I know them, they're quite lame
I had to rearrange their faces
And give them all another name
- Bob Dylan

Why you would want to do such an insane thing is none of my business.

Best,
Frank


Offline MIchael

  • Jr. Member
  • *
  • Posts: 10
Re: How to rename reserved words in the NASM?
« Reply #2 on: May 27, 2018, 09:23:17 PM »
Nice try! But according to my logic I have to get a compilation error "Label or instruction expected" if I write this after last line of my code:
Code: [Select]
mov ax, 0Because MOV instruction will no longer exist.
« Last Edit: May 27, 2018, 09:58:03 PM by MIchael »

Offline MIchael

  • Jr. Member
  • *
  • Posts: 10
Re: How to rename reserved words in the NASM?
« Reply #3 on: May 29, 2018, 05:59:56 AM »
Heey! Can anybody answer my question?

Please...

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How to rename reserved words in the NASM?
« Reply #4 on: May 29, 2018, 07:18:52 AM »
Ummm, no?

Seriously, and without meaning any insult, I question if you don't want "mov" to exist, whether Nasm is what you're looking for.

If you got into the sourcecode - x86/insns.dat - and made changes there - you might be able to create a tool that does what you want... instead of what Nasm does...

Best,
Frank


Offline MIchael

  • Jr. Member
  • *
  • Posts: 10
Re: How to rename reserved words in the NASM?
« Reply #5 on: May 29, 2018, 07:54:56 AM »
As I understand, it is impossible. I would not want to change the core of NASM to implement my plan. I want the code that I write could be compiled using the official release without any problems. So, so far, I refuse my idea
« Last Edit: May 29, 2018, 08:34:17 AM by MIchael »

Offline sal55

  • Jr. Member
  • *
  • Posts: 18
Re: How to rename reserved words in the NASM?
« Reply #6 on: September 22, 2018, 08:32:37 PM »
Ummm, no?

Seriously, and without meaning any insult, I question if you don't want "mov" to exist, whether Nasm is what you're looking for.
A year ago I wanted something similar. I don't know about the OP's reasons (and this is an old thread) but when you machine-generate ASM code from another language, then it happens that some identifiers used in the original language can clash with reserved words in Nasm.

Sometimes you can 'decorate' such names to avoid a clash, but sometimes also the names have to be just as they are in order to link with those names exported from elsewhere. (One I had problems with as 'abs' IIRC.)

Quote
If you got into the sourcecode - x86/insns.dat - and made changes there - you might be able to create a tool that does what you want... instead of what Nasm does...

That won't help unless you rename all opcodes and register names to have unlikely prefixes or suffixes, otherwise there is still a risk of a clash. And then the same assembler build won't work for conventional code.

Some assemblers are aware of such problems and will provide workarounds (I'm using such an alternative now). But I'm just pointing out the OP's requirement isn't that crazy.