Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top