by axod · 16y ago · 0 comments
I don't really do much C, but here's x86:
// esi -> asciiz string
// cl = character to remove
// NB cl=0 won't work well ;)
mov edi, esi
cld
loop1:
lodsb // Load the byte from [esi] into al
cmp al, cl
je loop1 // Skip this byte
stosb
or al, al
jnz loop1
Did I miss the "gotcha"s?edit: condensed code a bit
What am I missing?
Also, eww. It decrements or increments dependent upon a flag. Not nice.
99% of the time the flag is clear... unless it isn't.
So for a seasoned assembly programmer that cld is idiomatic, axod probably typed the instruction reflexively because he knows he can't rely on the state of the direction flag, even if it has nothing to do with the problem per-se.
Does it even really require much thinking? I'm not trying to be arrogant here, but it seems like a good definition of "trivial".
My sentiment exactly.
And by the way, you do have a bug in that code.
> If you don't find any egregious bugs, I hereby claim it really is trivial.
Still, it may be a nice exercise.