0

I want to declare the following macro in my common.h file:

.macro HEX_NIBBLE reg
    //LOCAL letter, end
    cmp $10, \reg
    jae letter
    add $'0, \reg
    jmp end
letter:
    /* 0x37 == 'A' - 10 */
    add $0x37, \reg
end:
.endm

Whenever I call the above core at more than one place in my main.S code, I get the following errors :

$ as --32 -o main.o main.S -g
main.S: Assembler messages:
main.S:17: Error: symbol `letter' is already defined
main.S:17: Error: symbol `end' is already defined
main.S:17: Error: symbol `letter' is already defined
main.S:17: Error: symbol `end' is already defined
main.S:17: Error: symbol `letter' is already defined
main.S:17: Error: symbol `end' is already defined

I want to use only GNU assembler (GAS), no GCC. How can I avoid these errors? Is there any assembly directive for this situation?

main.S can be taken anything for this examples, say below code :

.include "common.h"
BEGIN
    HEX_NIBBLE %ax
    HEX_NIBBLE %ax
    HEX_NIBBLE %ax
    HEX_NIBBLE %ax
    hlt
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Naveen
  • 7,944
  • 12
  • 78
  • 165
  • 1
    Use [local labels](https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels-1) or [macro unique labels](https://sourceware.org/binutils/docs/as/Macro.html#index-number-of-macros-executed) – Jester Feb 16 '20 at 12:51
  • re: hex: you might be interested in [How to convert a binary integer number to a hex string?](//stackoverflow.com/q/53823756) – Peter Cordes Feb 16 '20 at 13:05

0 Answers0