I have the following disassembly:mov BL, [EAX]inc EAXmov [EDX], BLinc EDXI could see this being the result of:uint8_t foo = bar;++bar;uint8_t tmp = foo;++foo;But this assumes C99. Is there some other C construct that could produce the code above?
What C construct could generate this assembly sequence?
disassembly;x86;static analysis;c
If you just want the answer without the explanation, scroll to the bottom of this post.The [register] notation stands for take the value stored in register and interpret it as an address. If the addressed entity size is ambiguous, it can be clarified using DWORD PTR [register] for DWORD-sized pointers (and similarly for other pointer sizes).mov BL, [EAX]This line treats the value in the EAX register as a pointer to a single byte (the size of BL), reads a byte from that address and stores it in BL. inc EAXThis line increments the value of EAX, effectively advancing to the next byte.mov [EDX], BLThis line treats the value in the EDX register as a pointer to a single byte (again, the size of the other operand tells us this), and writes a byte that is stored in BL to that address.inc EDXThis line increments the value of EDX, advancing to the next byte.With all this information, we can see that this sequence basically copies a byte from one address to another. Most likely it is used in a loop such as string copy or memory copy. If there's a line similar to test BL, BL afterwards to determine if the copied byte was NULL, it's most likely a string copy; if there's a length/address check instead - it's probably a memory/buffer copy that works on a specified amount of bytes.In C parlance, this can be represented as:char t; // BLchar *src; // EAXchar *dst; // EDX// initialize src and dst heret = *src;++src;*dst = t;++dst;Or, as K&R put it ever so tersely:*dst++ = *src++;