0
votes

i was thinking about some IA-32 ASM examples with char arrays.

I'm trying to understand the main difference between ESI/EDI and EBX, when you need to read an array. In my examples, signed or unsigned char arrays. It seems that when you don't need a destination (EDI), you can use both ESI and EBX to read an array.

My question comes from the "standard" definitions of those registers: ESI/EDI are for string operations, and EBX is for memory pointing. Ok, arrays are in memory, but: there is a real difference for using ESI or EBX in this case?

I know, it's a dumb question, but i can't find anything useful on the net.

2
These distinctions mattered for the 8086 processor. It is not 1979 anymore.Hans Passant

2 Answers

2
votes

Convenience and available registers are about it. There's a handful of instructions that require specific registers, and a few others that will make shorter instructions given a specific register (16-bit code using AX comes to mind). However, for standard addressing I can't think of any worthwhile differences imposed by the chip itself. You may choose one or the other simply due to which registers are free (or to avoid a save/restore operation).

1
votes

There are a small number of "string" instructions which use E/RSI and E/RDI as implicit source and destination pointers, and E/RCX as the counter for those. See CMPS, MOVS, STOS, INS and OUTS and the REP, REPE etc prefixes.

Although these are very ancient instructions, I believe they are still effective, performance-wise... the Intel documentation notes, in particular, that STOS is the quickest way to clear a block of memory.