扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
调用方式 |
参数在堆栈里的次序 |
操作方式 |
_cdecl |
第一个参数在低位地址 |
调用者 |
_stdcall |
第一个参数在低位地址 |
被调用者 |
_fastcall |
编译器指定 |
被调用者 |
_pascal |
第一个参数在高位地址 |
被调用者 |
文件名:arch/i386/kernel/entry.S(说明:前面的数字表示行号)
359 ALIGN
360 common_interrupt:
361 SAVE_ALL
362 movl %esp,%eax
363 call do_IRQ
364 jmp ret_from_intr
|
文件名:arch/i386/kernel/irq.c
48 fastcall unsigned int do_IRQ(struct pt_regs *regs)
49 {
50 /* high bits used in ret_from_ code */
//取得中断向量号
51 int irq = regs->orig_eax & 0xff;
52 #ifdef CONFIG_4KSTACKS
53 union irq_ctx *curctx, *irqctx;
54 u32 *isp;
55 #endif
……
107 } |
文件名:arch/i386/kernel/entry.S |
文件名:include/asm-i386/ptrace.h |
84 #define SAVE_ALL \
85 cld; \
86 pushl %es; \
87 pushl %ds; \
88 pushl %eax; \
89 pushl %ebp; \
90 pushl %edi; \
91 pushl %esi; \
92 pushl %edx; \
93 pushl %ecx; \
94 pushl %ebx; \
95 movl $(__USER_DS), %edx; \
96 movl %edx, %ds; \
97 movl %edx, %es; |
26 struct pt_regs {
27 long ebx;
28 long ecx;
29 long edx;
30 long esi;
31 long edi;
32 long ebp;
33 long eax;
34 int xds;
35 int xes;
36 long orig_eax;
37 long eip;
38 int xcs;
39 long eflags;
40 long esp;
41 int xss;
42 }; |
48 fastcall unsigned int do_IRQ(struct pt_regs *regs)
49 {
……
73 #ifdef CONFIG_4KSTACKS
……
92 asm volatile(
93 " xchgl %%ebx,%%esp \n"
94 " call __do_IRQ \n"
95 " movl %%ebx,%%esp \n"
96 : "=a" (arg1), "=d" (arg2), "=b" (ebx)
97 : "0" (irq), "1" (regs), "2" (isp)
98 : "memory", "cc", "ecx"
99 );
……
101 #endif |
#include<stdio.h>
low_to_up(char in);
void main()
{
printf("%c\n",low_to_up('d'));
}
low_to_up(char in)
{
char ch;
if(in>='a' && in<='z')
ch=in-'a'+'A';
else
return(ch);
} |
1: #include<stdio.h>
2: low_to_up(char in);
3:
4: void main()
5: {
00401020 push ebp
00401021 mov ebp,esp
00401023 sub esp,40h
00401026 push ebx
00401027 push esi
00401028 push edi
00401029 lea edi,[ebp-40h]
0040102C mov ecx,10h
00401031 mov eax,0CCCCCCCCh
00401036 rep stos dword ptr [edi]
6: printf("%c\n",low_to_up('d'));
00401038 push #64h d的ASC码 (1处)
0040103A call @ILT+5(low_to_up) (0040100a)
0040103F add esp,4
00401042 push eax # (5处)
00401043 push offset string "%c\n" (0042001c)
00401048 call printf (004010e0)
0040104D add esp,8
7: }
00401050 pop edi
00401051 pop esi
00401052 pop ebx
00401053 add esp,40h
00401056 cmp ebp,esp
00401058 call __chkesp (00401160)
0040105D mov esp,ebp
0040105F pop ebp
00401060 ret
8:
9: low_to_up(char in)
10: {
00401080 push ebp
00401081 mov ebp,esp
00401083 sub esp,44h 00401086 push ebx
00401087 push esi
00401088 push edi
00401089 lea edi,[ebp-44h]
0040108C mov ecx,11h
00401091 mov eax,0CCCCCCCCh
00401096 rep stos dword ptr [edi]
11: char ch;
12: if(in>='a' && in<='z')
00401098 movsx eax,byte ptr [ebp+8] # (2处)
0040109C cmp eax,61h
0040109F jl low_to_up+36h (004010b6)
004010A1 movsx ecx,byte ptr [ebp+8]
004010A5 cmp ecx,7Ah
004010A8 jg low_to_up+36h (004010b6)
13: ch=in-'a'+'A'; 004010AA movsx edx,byte ptr [ebp+8] # (3处) 004010AE sub edx,20h
004010B1 mov byte ptr [ebp-4],dl
14: else
004010B4 jmp low_to_up+3Ah (004010ba)
15: return(ch); 004010B6 movsx eax,byte ptr [ebp-4] 16: }
004010BA pop edi # 恢复寄存器的值,做返回处理 (7处)
004010BB pop esi
004010BC pop ebx
004010BD mov esp,ebp
004010BF pop ebp
004010C0 ret |
.file "csdn.c"
.text
.type low_to_up, @function
low_to_up:
pushl %ebp
movl %esp, %ebp
subl $8, %esp movl 8(%ebp), %eax # (2处)
movb %al, -1(%ebp)
cmpb $96, -1(%ebp)
jle .L2
cmpb $122, -1(%ebp)
jg .L2
movzbl -1(%ebp), %eax
subb $32, %al
movb %al, -2(%ebp) # (3处)
jmp .L3
.L2:
movsbl -2(%ebp),%eax
movl %eax, -8(%ebp) # (5处)
jmp .L1
.L3:
.L1:
movl -8(%ebp), %eax # (4处) leave ret
.size low_to_up, .-low_to_up
.section .rodata
.LC0:
.string "%c\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $100, (%esp) #将d的值压入到栈中,然后调用low_to_up()函数 (1处)
call low_to_up
movl %eax, 4(%esp) # (6处)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.5 (Debian 1:3.3.5-13)" |
low_to_up:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl 8(%ebp), %eax
movb %al, -1(%ebp)
cmpb $96, -1(%ebp)
jle .L2
cmpb $122, -1(%ebp)
jg .L2
movzbl -1(%ebp), %eax
subb $32, %al
movb %al, -2(%ebp)
jmp .L3
.L2:
movsbl -2(%ebp),%eax
movl %eax, -8(%ebp)
jmp .L1
.L3:
movsbl -2(%ebp),%eax
movl %eax, -8(%ebp)
.L1:
movl -8(%ebp), %eax
leave
ret |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者