1

I'm reversing my C array's programs where I'm storing numbers in arrays like this...

int marks[5];
marks[0] = 1;
marks[1] = 3;
marks[2] = 2;
marks[3] = 7;
marks[4] = 9;

so the compiler showing me the disassembly...

enter image description here

Actually, my question is why it is storing like this? by using imul first before storing 1 then before storing 7, and using shl for storing 3, 2, and 9. Can anyone please help? Fell free to edit it*

4
  • i think you have already been asked to post text not images – blabb Feb 15 at 7:35
  • Actually, in visual studio 2017 I can't copy the assembly code as there's no option there so that's why I've use an image to present my point. – Ramesses II Feb 15 at 10:03
  • 1
    @RamessesII unless you have some strange VS, you can for sure copy assembly from there. – Paweł Łukasik Feb 15 at 14:43
  • 1
    Lack of copy and paste (if true, which is unlikely) is not an excuse for posting an image of text. You can re-type it in a code block. It's not that much. – nobody Feb 15 at 15:51
3

those are pointer arithmetics marks is an <<<;ADDRESS;>>>>> assume 0x10000000
it points to an integer whose size is 4 in 32 bit machine so the next integer will be at 0x10000004 , and the next will be at 0x10000008 and so on

&marks[0] = 0x10000000
&marks[1] = 0x10000004
&marks[2] = 0x10000008,c,10,14,18,.....nn

each of the 4 in the disassembly is sizeof(int) == 4
they are multiplied by 0 , 2^0 , 2^1,3 and 2^2 to result in 0,1,2,3,4 as indexes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.