I just wanted to write some ASM code and include it in a C/C++ code, not through inline-mode, but creating a different ASM module. I've found out that a CodeBlocks project allows ASM sources, so I've followed these steps, actually with some slight changes, like the building command:
gcc -c myasmfile.s -o ./obj/Debug/myasmfile.o
And everything seems to work, but labels.
Here is an example:
.text
.intel_syntax noprefix
.globl mytest
mytest:
push rbp
mov rbp, rsp
mov rcx, 0
.mylabel:
inc rcx
cmp rcx, 10
jne .mylabel
mov rax, rcx
leave
ret
When I try to run and debug the function, this is what I get:
It's like it recognizes mylabel
as a new function, cutting all the code after it. I can't explain myself why it's showing the same code twice, but it happens even without labels, so I don't think it's related to them (anyway, why does it happen?).
Then I've read this discussion, and I've tried all possible solutions listed there, but no success. Here is what I've tried:
using suffix
f
andb
for forward and backward respectively.using
%=
for local labelstried even without
.
in the label declaration
Why do labels work in inline-assembly, while they do not in my case?
EDIT Thanks to @fuz, now my code is working. By the way, inside the debug window the function is copied twice, despite the memory addresses are the same.