1
#include <stdio.h>



int x = 0, y = 0, z = 0;

void cv_2_1_1() {
    scanf("%d %d", &x, &y);
    asm(".intel_syntax noprefix \n"
        "mov eax, x \n"
        "mov ecx, y \n"
        "add eax, ecx \n"
        "mov z, eax \n"
        ".att_syntax \n");

    printf("%d\n\n", z);
}

void cv_2_1_2() {
    scanf("%d", &x);
    asm(".intel_syntax noprefix \n"
        "mov eax, x \n"
        "shl eax, 1 \n"
        "mov z,eax \n"
        ".att_syntax \n");
    printf("%d", z);
}


void cv_2_1_3() {
    scanf("%d", x);

    asm(".intel_syntax noprefix \n"
        "mov eax, x \n"
        "cmp ecx, 9 \n"
        "jnle gamma \n"
        "add eax, -7 \n"
        "gamma:\n"
        "add eax, 55 \n"
        "mov z, eax \n"
        ".att_syntax \n");
    printf("%d - %c", z, z);
}


int main() {
    printf("Zadajte 2 hodnoty: \n");
    cv_2_1_1();
    printf("Zadajte hodnotu: \n");
    cv_2_1_2();
    printf("Zadajte hodnotu: \n");
    cv_2_1_3();
    return 0;
}

So this is the code ive been trying to use, my friend uses the same platform to write down the code and it runs for him just fine. Does anyone know what the problem might be or what is causing the issue ? I tried the same code in Codeblocks and it gave me an undefined reference to x undefined reference to y undefined reference to z error messages. Thanks in advance.

  • Your problem is you tried to compile as 64 bit. – Jester Mar 23 '22 at 16:29
  • @Jester: And that this is super-broken, stepping on registers and modifying global vars without telling the compiler about it. It will happen to work in a debug build in a non-PIE executable (and/or 32-bit mode), but this is *not* how you use inline asm. https://stackoverflow.com/tags/inline-assembly/info. It also hard-codes asm symbol names for C vars, so platforms where `int x` uses `_x:` in asm will get undefined reference instead of a relocation error. – Peter Cordes Mar 23 '22 at 19:38

0 Answers0