I have a problem, that i cant figure out:
In assembly language, write a function that receives a pointer to an array of integers and the size of this array, and changes the array by reversing its elements without copying the array to stack. Use the dedicated instructions and registers to work with arrays (esi, edi; lodsb, stosb, cld, std).
Example: 1 2 3 4 5 -> 5 4 3 2 1
Anyone have any suggestions?
Reversing an array with
lodsbandstosbrequirescldandstdfor every element (because one of the pointers needs to increment and the other needs to decrement), or alternatively, you can just forgetcldandstdand just cancel the incorrect increment (or decrement) of the other pointer by subtracting 2 (or adding 2) to it after each element.Anyway, using
lodsbandstosbin this case makes things unnecessarily complicated in my opinion. I’d use something like this: