TransWikia.com

Arrays assembly

Reverse Engineering Asked by Ramesses II on February 25, 2021

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*

One Answer

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

Answered by blabb on February 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP