0

I have following assembly file mov.s

 .text
    .macro test_3
     and $3,%eax
    .endm

    movz:
    movzb   %al,%ax
     movzb   (%eax),%ax
     movzb   %al,%eax
        movzb   (%eax),%eax
    .ifdef test_3
        movzb33 %al,%rax
        movzb   (%rax),%rax
.endif

command as -o dump.o movz

In this code I want to test ifdef in assembly language so I have defined macro test_3.

According to my understanding it should print message Error: no such instruction: 'movzb33 %al,%rax' when I use assembler but it is not going inside ifdef so what is the problem?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Akshay
  • 159
  • 1
  • 9
  • Read the documentation of your particular assembler (is it [nasm](http://www.nasm.us/) or [gas](https://sourceware.org/binutils/docs-2.28/as/index.html)?). `.ifdef` is a directive, not an instruction. Look into the generated object file (e.g. with `readelf` or `objdump` on Linux) – Basile Starynkevitch Sep 18 '17 at 06:07
  • i know this thing – Akshay Sep 18 '17 at 06:10
  • Bu did you carefully read the documentation (perhaps several times)? – Basile Starynkevitch Sep 18 '17 at 06:11
  • 1
    use -a option to get listing – vollitwr Sep 18 '17 at 06:22
  • yes @Basile Starynkevitch I have to use symbol insted of macro thanks – Akshay Sep 18 '17 at 06:27
  • 1
    @Sathiya: your edit had a mistake: you left out `as` from the code-formatting. It's the name of the assembler command. Thanks for making edits to help improve questions, but just wanted to point out what you missed so you can learn from the mistake. – Peter Cordes Sep 18 '17 at 08:00

1 Answers1

1

.ifdef checks if a symbol is defined, it does not test macros. In GNU AS and many other assemblers macros can only be used where an instruction is permitted.

Timothy Baldwin
  • 3,551
  • 1
  • 14
  • 23
  • 1
    Also, if you *want* C preprocessor functionality, use CPP macros. `gcc -c foo.S` will run it through CPP first, so you can use `#include` and `#ifdef`. – Peter Cordes Sep 24 '17 at 14:36