Home > database >  Can someone explain me the output values for the below assembly code
Can someone explain me the output values for the below assembly code

Time:12-29

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 Addi in x86
  • The intention seem to be to increment esi by 2
  • add command affects CF, and rcr presumably expects CF from 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.

  • Related