V
V
Vladimir Kuts2020-12-08 20:26:23
assembler
Vladimir Kuts, 2020-12-08 20:26:23

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:
5fcfb5692858a573859218.png
(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);
}

the only problem is that in gcc the format of assembler inserts is different, and not so convenient...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2020-12-08
@jcmvbkbc

the only problem is that in gcc the format of assembler inserts is different

Understand , then you will use it with pleasure:
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);
}

4
4144, 2020-12-19
@4144

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;"
  };

To use variables, use the substitutions from jcmvbkbc 's answer or preprocessor macros.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question