Hacker News new | past | comments | ask | show | jobs | submit login

I’m curious what rep lodsb even does lol



Potentially read lots of stuff, without doing anything useful ;)

Sort of a self-deprecating name I chose. But it's also an interesting instruction, in that Intel had to actually write microcode specifically to support it in every x86 compatible chip going forward.

It loads CX bytes from memory at DS:SI into the accumulator. Overwriting whatever was there previously every time.

The only uses I can think of:

     - test memory speed
     - if CX is known to be 0 or 1, conditionally read one byte
     - trigger some I/O device where the value read isn't important


I think rep is expected to be combined with a condition. repne lodsb will read while not fetching 0, so a search for end of C string. Using the remaining cx or si value you can determine the length fetched until the condition failed.


LODS, STOS, MOVS, INS and OUTS are all unconditional (doesn't matter which version of the prefix you use, but officially REP should be the same opcode as REPE).

SCAS is the one that scans for e.g. a nul byte.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: