0

I'm trying to translate to x86 assembly to help me get a better understanding of the concept on coding in x86 assembly and I'm feeling stuck on how to even start on this code.

int temp = 0;
int acc = 0;

for(int i = 0; i < 20; i++)
{
    temp = temp + i;
    if (temp > 5)
    {
           acc = acc * temp;
    }
}
printf(“Answer is %d\n", acc);
Patch
  • 9
  • 2

1 Answers1

2

If you use an IDE like Visual Studio, you can target an x86 platform and view assembly using the Disassembly window.

Keep in mind that flags will change the generated assembly, so I would make sure to adjust optimizations accordingly.

Jav Solo
  • 576
  • 1
  • 6
  • 15
  • 2
    Usually you want some optimization if you're going to read the asm for a small simple loop. For something larger and complex, it can turn into a big mess, but for small stuff optimization mostly removes noise, especially if you only enable `gcc -Og` minimal optimization. It helps to write a function that takes args, otherwise constant-propagation will compute more stuff at compile time. e.g. https://godbolt.org/z/r6ofzP – Peter Cordes Dec 04 '20 at 19:13
  • Thanks for the feedback, I edited my answer accordingly. – Jav Solo Dec 04 '20 at 20:02