I am using BloodshedDev-CPP GNU. Assembly codes are written in this format :

int Variable=45; /*a random value*/
__asm(mov %ax,_Degisken);

The crap compiler uses 'AT&T Assembly Syntax'. The problem is I don't know that AT&T stuff and I want to call some interrupts in my program.
In the normal assambly language, interrupts are called with "int" keyword. But what about AT&T?

Dani AI

Generated

A few focused notes that clarify what is happening and how to fix it (responding to and following up on comments from , , and ).

GCC/MinGW (the toolchain used by Dev‑C++) normally feeds the assembler (gas) AT&T‑style templates: registers are written with a leading %, immediates with $, and operand order is source then destination. The int instruction still exists under AT&T — immediates must be written like int $3 (breakpoint) or int $0x80 for the classic Linux syscall example. (ftp.gnu.org)

About calling interrupts: software/BIOS interrupts (e.g. int 0x10) are real‑mode services. On modern systems (Windows, Linux) user programs run in protected or long mode, so those BIOS interrupts will not do what you expect; use the OS API or a kernel/driver if you need privileged services, or run real‑mode/VM86 code only in appropriate contexts. (wiki.osdev.org)

The “symbol label is already defined” error comes from emitting the same global label name into the assembler output more than once (basic asm strings are copied verbatim into the .s file). Fixes that work reliably:

  • Use gas local numeric labels (e.g. 1: and branch to 1b for the previous 1:) so the assembler can reuse the same small-number labels safely.
  • Prefer extended asm with input/output operands so the compiler supplies registers/addresses ("r"(ptr)) and you avoid naming symbols yourself.
  • Or generate unique labels (or assembler-local names like ones beginning with the assembler local prefix) if you must emit named labels. (chromium.googlesource.com)

If you prefer Intel syntax for readability, the compiler can emit Intel‑style assembly (the -masm=intel dialect), but remember that only the textual dialect changes — it does not change OS/privilege rules or the need to use proper asm operands and clobbers. Also avoid writing asm that jumps into or out of other asm blocks; use extended asm or full assembler functions for complex code. (gcc.gnu.org)

Small example pattern (showing numeric local label usage inside an asm string):

__asm__ volatile(
  "1:\n\t"
  "  dec %ecx\n\t"
  "  jnz 1b\n\t"
);

For : using numeric local labels (1: / 1b) or switching to extended asm for passing the buffer pointer will remove the duplicate‑label error.

Recommended Answers

All 5 Replies

>The crap compiler uses 'AT&T Assembly Syntax'.
Just because it uses an ASM syntax that you don't know doesn't mean that the compiler is crap. In fact, GNU GCC is a very good compiler that many experts recommend. Good first impression. :rolleyes:

>In the normal assambly language
There is no "normal" assembly language. Every architecture uses a different base assembly language, and every compiler that supports inline assembly uses its own variant.

>But what about AT&T?
Hmm, I don't know about everyone else, but I'm disinclined to help you after reading your derogatory and ignorant comments toward something you don't understand.

-masm=intel in the compiler options

I set this "-masm=intel" and then tried to compile this:

void flipIt(void* buffer)
{
    void* b = buffer;// Ukazatel na buffer
    __asm__ // ASM kód
    (
        "mov ecx, 256*256 \n\t"
        "mov ebx, b \n\t"
        "label: \n\t"
        "mov al, [ebx+0] \n\t"
        "mov ah, [ebx+2] \n\t"
        "mov [ebx+2], al \n\t"
        "mov [ebx+0], ah \n\t"
        "add ebx, 3 \n\t"
        "dec ecx \n\t"
        "jnz label \n\t"
    );
}

<< moderator edit: added [code][/code] tags >>

The errors were:

Assembler messages:
Error: symbol `label' is already defined
Error: symbol `label' is already defined

I don't know what to do.
Thanks for help

typek

set "-masm=intel" and compile this:

void flipIt(void* buffer)
{
    static void* b asm("b")  = buffer;// Ukazatel na buffer
    asm(// ASM kód
        "mov ecx, 256*256;"
        "mov ebx, b;"
        "label:;"
        "mov al, [ebx+0];"
        "mov ah, [ebx+2];"
        "mov [ebx+2], al;"
        "mov [ebx+0], ah;"
        "add ebx, 3;"
        "dec ecx;"
        "jnz label;"
    );
}

AT&T does tend to suck. It hurts my eyes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.