Can someone explain to me the output values for the below assembly code. Like how can I arrive at the solution?
Arr Byte 5D, 2E, 97, 4B, A5 , 7E , 84 , 9A , 61 , 8B
mov ecx, 5
mov esi, offset Arr
LI: rcr array[esi], 1
Addi esi,esi, 2
Loop LI
CodePudding user response:
Let's replace Addi esi,esi, 2 with lea esi, [esi 2] because:
- There's no
Addiin x86 - The intention seem to be to increment
esiby 2 addcommand affectsCF, andrcrpresumably expectsCFfrom the previous iteration
No idea if there's some assembler to accept Addi.
The whole loop then runs in even-indexed elements of Arr (assume indexing is zero-based)
RCR rotates bits right through CF (Carry Flag). that is out of eight bits of each element each shifted towards less significance, the least significant bit is put into CF and the most significant bit is extracted from CF.
Knowing that, you can compute the new values of Arr element, except the 0th element: you don't know the initial value of CF.
