#define max(a,b) ({ \ typeof (a) _a = (a); \ typeof (b) _b = (b); \ _a > _b ? _a:_b; \ })#include "stdio.h"int main(void){ register int a asm("eax") = 2; int b = 3; register int c = 4; printf("%d,%d",a,max(a,c)); return 0;}
In the above example, A, B, and C can store variables in registers rather than stacks? The answer is a and B. However, the advantage of a is that registers can be specified, while C can only be placed in registers.
Objdump-D.
00000000004005ac <main>:
4005ac: 55 push % RBP
4005ad: 48 89 E5 mov % RSP, % RBP
4005b0: 53 push % RBx
4005b1: 48 83 EC 18 sub $0x18, % RSP
4005b5: B8 02 00 00 00 mov $0x2, % eax //
4005ba: C7 45 E4 03 00 00 00 movl $0x3,-0x1c (% RBP) // B
4005c1: BB 04 00 00 00 mov $0x4, % EBX // C
4005c6: 89 45 E8 mov % eax,-0x18 (% RBP)
4005c9: 89 5d EC mov % EBX,-0x14 (% RBP)
4005cc: 8B 55 E8 mov-0x18 (% RBP), % edX
4005cf: 3B 55 ec cmp-0x14 (% RBP), % edX
4005d2: 7E 05
Add a typeof example to enrich the code. typeof is a method for obtaining the variable type during compilation,