0

how to write this ASM code in C?

loc_536FB0:
mov cl, [eax]
cmp cl, ' '
jb short loc_536FBC
cmp cl, ','
jnz short loc_536FBF

loc_536FBC:
mov byte ptr [eax], ' '

loc_536FBF
mov cl, [eax+1]
inc eax
test cl, cl
jnz short loc_536FB0

I have figured out that it is a for loop counting to 23 then exiting.

user1365830
  • 171
  • 1
  • 11

1 Answers1

4
char *str; // = value of eax
int i = 0;
while (str[i]) {
    if (str[i] < ' ' || str[i] == ',')
        str[i] = ' ';
    i++;
}

It traverses a c-string and replaces all characters below ' ' and commas ',' with a space ' '. See an ASCII table: characters "below" space are all the controll characters. The function probably wants to erase them to get a "clean" string. The string is passed via a pointer in eax.

I don't know what this would have to do with 23, but maybe this is what you got for some specific input while debugging.

typ1232
  • 5,535
  • 6
  • 35
  • 51
  • Small nitpick: given the assembly code in the question it would be more accurately transcribed as a `do { } while();`, since the NULL terminator check is the last thing performed during each iteration. – Michael May 25 '13 at 20:50