-1

I would like to know if there is a quick way to convert this code into Assembly from IA32 please!

void function1(char trs[], int let[26]) {
    int i;
    int ind;

    int x = trs[i];

    for(i=0; trs[i]!='\0'; i++) {
        if (x>='a' && x<='z')
            ind = x - 'a';  
            let[ind]++;

        if (x>='A' && x<='Z')
            ind=x - 'A';

        let[ind]++;   
    }
}
myaut
  • 11,174
  • 2
  • 30
  • 62
  • 8
    Use a C compiler! It's what they do! – unwind Apr 28 '15 at 11:17
  • 1
    It is certainly possible, but I doubt it will be quick unless you know IA32 assembly very well. Also, I doubt many people will be able to hand-optimize it better than a compiler would, if that's what you want. If it's for school-work then you should do it yourself, and come back here with your attempt if you have problems with it. – Some programmer dude Apr 28 '15 at 11:17
  • 2
    Also note you are missing some curly braces. This is not python where indentation matters;) – Jester Apr 28 '15 at 11:20
  • 3
    gcc -S Look here: http://stackoverflow.com/questions/16241771/how-can-i-view-assembly-code-produced-for-c-functions or http://stackoverflow.com/questions/1354899/how-can-i-see-the-assembly-code-that-is-generated-by-a-gcc-any-flavor-compiler – moritzschaefer Apr 28 '15 at 11:20
  • 1
    That code doesn't make sense. You're assigning `x` to `trs[i]` outside of the loop, before `i` is even assigned a value. `x` is never modified in the loop, so whatever you do in that loop will be done to the same array element at each iteration. No idea what you think your code is going to do, but it's almost certain that what you've written won't do what you expect. – Jim Mischel Apr 28 '15 at 15:43
  • okay thank you! I'm new at this C/Assembly thing so sorry for all the mistakes ahah – Francisco Oliveira Apr 28 '15 at 18:35

1 Answers1

2

Assuming you're using gcc, you can just use gcc -S main.c -o main.s.
This outputs assembly code (GAS flavour) far faster than any human can :)

But seriously, if you wanted to convert this by hand, I would recommend converting your code into plain English, and then into Assembly.

Levi
  • 1,921
  • 1
  • 14
  • 18