Answer the question
In order to leave comments, you need to log in
Debugging small assembler pieces of code?
Let's say I parse a certain program in the IDA disassembler.
I became interested in a certain piece of code:
(The picture is given for illustration)
I want to copy it, paste my values into registers, specify my data areas, and so on - in general, drive a small piece of code out of the context of the program. Where is it more convenient to do this in order to minimize the writing of the boilerplate?
Like in this code:
int main() {
int a = 1;
int b = 3;
int c;
__asm {
mov eax, a
mov ebx, b
add eax, ebx
mov c , eax
}
printf("a + b = %x + %x = %x\n", a, b, c);
}
Answer the question
In order to leave comments, you need to log in
the only problem is that in gcc the format of assembler inserts is different
int main() {
int a = 1;
int b = 3;
int c;
asm (
"mov %[a], %[c]\n\t"
"add %[b], %[c]\n\t"
: [c] "=mr" (c)
: [a] "mr" (a), [b] "mr" (b));
printf("a + b = %x + %x = %x\n", a, b, c);
}
to use the familiar assembler code syntax, use the ".intel_syntax;" command inside the asm block.
asm {
".intel_syntax;"
"mov eax, 10;"
"mov ebx, 20;"
"add eax, ebx;"
"mov edx, eax;"
".att_syntax;"
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question