- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个非常简单的C ++程序,以了解“内联”的工作原理:
inline int square(int x) {
return x*x;
}
int main() {
int y = square(1234);
return y;
}
_Z6squarei: # @_Z6squarei
pushq %rbp
movq %rsp, %rbp
movl %edi, -4(%rbp)
movl -4(%rbp), %edi
imull -4(%rbp), %edi
movl %edi, %eax
popq %rbp
retq
.Lfunc_end0:
main: # @main
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $1234, %edi # imm = 0x4D2
movl $0, -4(%rbp)
callq _Z6squarei
movl %eax, -8(%rbp)
movl -8(%rbp), %eax
addq $16, %rsp
popq %rbp
retq
.Lfunc_end1:
main: # @main
.cfi_startproc
pushq %rbp
.Lcfi0:
.cfi_def_cfa_offset 16
.Lcfi1:
.cfi_offset %rbp, -16
movq %rsp, %rbp
.Lcfi2:
.cfi_def_cfa_register %rbp
subq $16, %rsp
movl $1234, %edi # imm = 0x4D2
movl $0, -4(%rbp)
callq _Z6squarei
movl %eax, -8(%rbp)
movl -8(%rbp), %eax
addq $16, %rsp
popq %rbp
retq
.Lfunc_end0:
_Z6squarei: # @_Z6squarei
pushq %rbp
movq %rsp, %rbp
movl %edi, -4(%rbp)
movl -4(%rbp), %edi
imull -4(%rbp), %edi
movl %edi, %eax
popq %rbp
retq
.Lfunc_end1:
最佳答案
unsigned int fun0 ( unsigned int );
static unsigned int fun1 ( unsigned int x )
{
return(x+1);
}
unsigned int fun2 ( unsigned int x )
{
return(x+2);
}
inline unsigned int fun3 ( unsigned int x )
{
return(x+3);
}
unsigned int hello ( unsigned int x )
{
unsigned int y;
y=fun0(x);
y=fun1(y);
y=fun2(y);
y=fun3(y);
return(y);
}
Disassembly of section .text:
00000000 <fun2>:
0: e2800002 add r0, r0, #2
4: e12fff1e bx lr
00000008 <hello>:
8: e92d4010 push {r4, lr}
c: ebfffffe bl 0 <fun0>
10: e8bd4010 pop {r4, lr}
14: e2800006 add r0, r0, #6
18: e12fff1e
unsigned int fun2 ( unsigned int x )
{
return(x+2);
}
unsigned int hello ( unsigned int x )
{
return(fun2(x));
}
00000000 <fun2>:
0: e2800002 add r0, r0, #2
4: e12fff1e bx lr
00000008 <hello>:
8: e2800002 add r0, r0, #2
c: e12fff1e bx lr
0000000000000000 <_Z4fun2j>:
0: 8d 47 02 lea 0x2(%rdi),%eax
3: c3 retq
4: 66 90 xchg %ax,%ax
6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
d: 00 00 00
0000000000000010 <_Z5helloj>:
10: 48 83 ec 08 sub $0x8,%rsp
14: e8 00 00 00 00 callq 19 <_Z5helloj+0x9>
19: 48 83 c4 08 add $0x8,%rsp
1d: 83 c0 06 add $0x6,%eax
20: c3 retq
00000000 <fun1>:
0: e52db004 push {r11} ; (str r11, [sp, #-4]!)
4: e28db000 add r11, sp, #0
8: e24dd00c sub sp, sp, #12
c: e50b0008 str r0, [r11, #-8]
10: e51b3008 ldr r3, [r11, #-8]
14: e2833001 add r3, r3, #1
18: e1a00003 mov r0, r3
1c: e28bd000 add sp, r11, #0
20: e49db004 pop {r11} ; (ldr r11, [sp], #4)
24: e12fff1e bx lr
00000028 <fun2>:
28: e52db004 push {r11} ; (str r11, [sp, #-4]!)
2c: e28db000 add r11, sp, #0
30: e24dd00c sub sp, sp, #12
34: e50b0008 str r0, [r11, #-8]
38: e51b3008 ldr r3, [r11, #-8]
3c: e2833002 add r3, r3, #2
40: e1a00003 mov r0, r3
44: e28bd000 add sp, r11, #0
48: e49db004 pop {r11} ; (ldr r11, [sp], #4)
4c: e12fff1e bx lr
00000050 <hello>:
50: e92d4800 push {r11, lr}
54: e28db004 add r11, sp, #4
58: e24dd010 sub sp, sp, #16
5c: e50b0010 str r0, [r11, #-16]
60: e51b0010 ldr r0, [r11, #-16]
64: ebfffffe bl 0 <fun0>
68: e50b0008 str r0, [r11, #-8]
6c: e51b0008 ldr r0, [r11, #-8]
70: ebffffe2 bl 0 <fun1>
74: e50b0008 str r0, [r11, #-8]
78: e51b0008 ldr r0, [r11, #-8]
7c: ebfffffe bl 28 <fun2>
80: e50b0008 str r0, [r11, #-8]
84: e51b0008 ldr r0, [r11, #-8]
88: ebfffffe bl 0 <fun3>
8c: e50b0008 str r0, [r11, #-8]
90: e51b3008 ldr r3, [r11, #-8]
94: e1a00003 mov r0, r3
98: e24bd004 sub sp, r11, #4
9c: e8bd4800 pop {r11, lr}
a0: e12fff1e bx lr
unsigned int fun0 ( unsigned int x )
{
return(x+7);
}
unsigned int fun0 ( unsigned int );
inline unsigned int fun3 ( unsigned int x )
{
return(x+3);
}
unsigned int hello ( unsigned int x )
{
unsigned int y;
y=fun0(x);
y=fun3(y);
return(y);
}
0000000000000000 <hello>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 83 ec 10 sub $0x10,%rsp
8: 89 7d fc mov %edi,-0x4(%rbp)
b: e8 00 00 00 00 callq 10 <hello+0x10>
10: 89 45 f8 mov %eax,-0x8(%rbp)
13: 89 c7 mov %eax,%edi
15: e8 00 00 00 00 callq 1a <hello+0x1a>
1a: 89 45 f8 mov %eax,-0x8(%rbp)
1d: 48 83 c4 10 add $0x10,%rsp
21: 5d pop %rbp
22: c3 retq
0000000000000000 <fun0>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 8d 47 07 lea 0x7(%rdi),%eax
7: 5d pop %rbp
8: c3 retq
9: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
0000000000000010 <hello>:
10: 55 push %rbp
11: 48 89 e5 mov %rsp,%rbp
14: 83 c7 07 add $0x7,%edi
17: e8 00 00 00 00 callq 1c <hello+0xc>
1c: 5d pop %rbp
1d: c3 retq
0000000000000000 <fun0>:
0: 8d 47 07 lea 0x7(%rdi),%eax
3: c3 retq
0000000000000000 <hello>:
0: 50 push %rax
1: e8 00 00 00 00 callq 6 <hello+0x6>
6: 83 c0 03 add $0x3,%eax
9: 59 pop %rcx
a: c3 retq
0000000000000000 <fun0>:
0: 8d 47 07 lea 0x7(%rdi),%eax
3: c3 retq
0000000000000010 <hello>:
10: 8d 47 0a lea 0xa(%rdi),%eax
13: c3 retq
关于c++ - 为什么内联以这种方式内联更改汇编代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48751426/
我试图在图形模式下打印一个字符。通常当我打印我正在做的一个字符时: mov ah,14 ; ah=14 mov al,'x' int 10h ; print the character 这
我试图通过更改其中的一个字节来修改存储在内存中的字符串。我为此使用了 movb,但由于某种原因,给定内存位置的字节没有改变。 在 gdb 调试器上: 14 movb %al, (%r10) # nex
我一直在阅读一些汇编代码,并且开始发现调用指令实际上是与程序计数器相关的。 但是,每当我使用 Visual Studio 或 Windbg 进行调试时,它总是显示 call 0xFFFFFF ...这
我最近一直在使用 Visual C++ 中的内联汇编,我想知道是否可以直接向堆栈上的局部变量添加值,例如: push 5 add [esp], 7 这样做可以吗?我问这个问题是因为我在执行此操作时随机
我有下一个代码: mov al, -5 add al, 132 add al, 1 据我检查,溢出标志和进位标志将在第一个操作中设置,而在第二个操作中,仅设置溢出。 但我不明白为什么: 在无符号数中,
在 64 位 x86 汇编 nasm 中,如何将单个字节从寄存器移动到 .data 节中定义的内存位置? 我知道这有效 global _main section .data quotient db 0
我的汇编代码有问题。我想打印存储在寄存器 cx 中的数字,但是当我尝试打印它时,它打印的是 ascii 字符而不是 ascii 数字,所以我决定编写一个程序将 ascii char 转换为 ascii
为什么第 1B 行的跳转指令(例如)变成了 EBBD? 我知道“jmp”= EB但是BD是怎么计算的呢? 最佳答案 短跳转使用一个带符号的偏移量添加到 JMP 之后的指令地址。 例如,第一个 JMP
以下两者有什么区别: mov eax, [eax+4] 和 add eax, 4 mov eax, [eax] 如果不是,那么汇编器是否会选择哪个来进行某种优化? 最佳答案 这
看《The Shellcoder's Handbook》中的一些汇编和反汇编代码,发现一条指令的序列操作数是不一样的。 例如,在 assembly 上: mov ebx,0 并且,在反汇编时: mov
我有这个非常简单的汇编代码: start: add ax, 100 ; if ax overflow add to bx 1 jmp start 但我不知道如何检测 ax 寄存器溢出,有人可以帮
在 64 位 x86 汇编 nasm 中,如何将单个字节从寄存器移动到 .data 节中定义的内存位置? 我知道这有效 global _main section .data quotient db 0
我的汇编代码有问题。我想打印存储在寄存器 cx 中的数字,但是当我尝试打印它时,它打印的是 ascii 字符而不是 ascii 数字,所以我决定编写一个程序将 ascii char 转换为 ascii
我正在学习一些关于操作系统开发的教程,我发现了一篇关于多重引导 header 。这些是您必须定义的一些“神奇”值才能使用GRUB2。这些是命令: # Declare constants used f
为什么第 1B 行的跳转指令(例如)变成了 EBBD? 我知道“jmp”= EB但是BD是怎么计算的呢? 最佳答案 短跳转使用一个带符号的偏移量添加到 JMP 之后的指令地址。 例如,第一个 JMP
我正在尝试从内存中复制一些单词并使用汇编将其保存到另一个内存地址。我正在尝试为其编写代码,但我不确定其中的某些部分。我将简要描述我想要做什么。 源地址、目标地址和要复制的字数是函数的输入参数。 最佳答
当我们想要像这样创建一个初始化变量时: name db 'zara ali' 我们创建了一个字节大小变量,但我们在其中存储了一个字符串 这怎么可能?? 当我们使用这条指令时: MOV ecx, nam
我还是汇编的新手,我还不知道汇编中的许多命令代码。我想在 16 位寄存器中进行除法。我想打印它的内容。我知道我需要将寄存器的内容转换为 ASCII 进行打印,但同样,我的问题是除法。请帮我。 比如cx
使用有什么区别: c.eq.s $1, $2 bc1t L2 并使用: beq $1, $2, L2 如果他们做同样的事情,为什么有两种分支方式?如果它们不同,那么它们各自的好处是什么
源代码: int main() { int i; for(i=0, i : push rbp 2. 0x000055555555463b :
我是一名优秀的程序员,十分优秀!