SE250:lab-2:apra102

From Marks Wiki
Jump to navigation Jump to search

Task 1

All pointers are same size for both Linux and windows. I used the provided code to get the size of the pointer; the size of pointer did not no matter what variable we are using remained as 4bytes.



Task 2

By using the local variables, x and y I got address and differences as following in Windows


Address of x(&x) as: &x=0x22ccc0,

Address of y(&y) as:&y=0x22ccbc,

Difference between x any as: diff= -1.

Difference between (long)&x and (long)&y as: -4.


In Linux:

Address of x(&x) as: &x=0xff93372c,

Address of y(&y) as: &y=0xff933728,

Difference between x and y as: diff=1.



I got entirely different answers for both windows and Linux. Which i really did not understand at all?


Task 3

Inserting array of 4 characters now we get the addresses of x, y and diff as:


Size of the array is 4,

The address of array is: arr=0012FF04,

The address of &array+4 is: &arr+4=0012FF08,

The address arr[4] is: arr[4]=0012FF08.


changing the size of array from 0 to 10 As the size of the array is same even there is change in the size of the array.

Declaring x and y as 0.


The address of x when x is 0 is: 0012FF3c,

The address of y when y is 0 is: 0012FF30.



After changing the array size from 4 to 10 and setting the values of x and y as 0 the addresses of x and y changed. By observing the values clearly they are almost near.



Task 4

Declaring both x and y as global variables.


Address of x(&x) as: &x=00417594,

Address of y(&y) as:&y=00417584,

Difference between x and y as: diff= 4.

Difference between (long)&x and (long)&y as: 16


Size of the array is 4,
The address of array is: arr =0012FF1C,
The address of &array+4 is: &arr+4 =0012FF20,
The address arr[4] is: arr[4] =0012FF020.


The address of x when x is 0 is: 00417160,

The address of y when y is 0 is: 00417164.



I am quite confused with the answer which i got here is completely different from the answers which i got before. Not a little but it is completely for example 00417160 is when x is 0 and when it is a global variable and 0012FF3c is the address of x when x is 0 and when it is a local variable. Have no idea why they are so different. So if we change the local variable to a global variable entire memory will change.

Task 5

By using the given code i got the values of p1 and p2 as


p1 = 0x2f,

p2 = 0x6116a06a.

Task 6

I got so wired answers which i can't even compare between these two machines.

For windows i got



sp = 0x22cc228(^po@)

sp X'd = 0x22cc228(XXXXXXX)

sp = 0x22cc28(^po@)

sp X'd = 0x22cc28(XXXXXXX)

sp = 0x402000(tuvwxyz)

sp X'd = 0x402000(XXXXXXX)

sp = 0xda0la0cs

sp X'd = 0xda0la0cs(XXXXXXX)


In Linux


sp = 0xff9336b4<pi>

sp = 0xff9336b4<XXXXXXX>

sp = 0xff9336b4<abcdefg>

sp = 0xff9336b4<XXXXXXX>

sp = 0x402000(tuvwxyz)

sp = 0x402000(XXXXXXX)

sp = 0xda0la0cs

sp = 0xda0la0cs(XXXXXXX)


I have no idea how this is happening.

Task 7

&my_struct = CCCCCCCC

offsets:

my_char: 0
my_short: -2 
 
my_int: -4

my_long: -8

my_float: -12

my_double: -16


It shows a difference of 2bytes i the beginning and later it shows 4bytes difference which is a bit curious to know about.

In Linux: Is showed the thing as the above except the &my_struct value


&my_struct = 0xff933728

Task 8

&my_union = CCCCCCCC

offsets:

my_char: 0

my_short: 0 

my_int: 0

my_long: 0

my_float: 0

my_double: 0
 

which is also same for both as well. It is interesting.

Task 9

I understand from the code initially it allocates 10 as the space for sp1, later when it says free space the malloc function just removes the space used by sp1 that means sp1 is no more in the malloc space. That what I understand and that makes sense to me.




Task 10

The address of local string is:

In windows

local_str = 0x22cc40


In Linux

local_str = 0x0000888.


These two are different.

Conclusion

The Difficult part I found in today's lab is while doing Task 6. Which worked, but that doesn’t make any sense to me.