当前位置:网站首页>Stack growth direction and memory growth direction

Stack growth direction and memory growth direction

2022-06-21 17:25:00 Soy sauce;

1. The growth direction of the stack

Stack growth from high to low

2. Memory growth direction

Small end alignment  : The low byte is placed at the low address , The high byte is placed at the high address ( many )

Big end alignment  : Put the high byte in the low address , Put the low byte in the high address ( The server )

Sample code :

//1. The growth direction of the stack

void test01(){

int a = 10;

int b = 20;

int c = 30;

int d = 40;

printf("a = %d\n", &a);

printf("b = %d\n", &b);

printf("c = %d\n", &c);

printf("d = %d\n", &d);

//a The address of is greater than b The address of , Therefore, the growth direction is downward

}

//2. Memory growth direction ( The small end model )

void test02(){

// High byte -> Status byte

int num = 0xaabbccdd;

unsigned char* p = #

// The first byte from the first address

printf("%x\n",*p);

printf("%x\n", *(p + 1));

printf("%x\n", *(p + 2));

printf("%x\n", *(p + 3));

}

原网站

版权声明
本文为[Soy sauce;]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211413401526.html