更新时间:2021-11-11 08:48:30
发生了什么事对你来说,当C程序被编译成汇编语言,你的toupper函数会弄成这个样子,也许是:
What happened for you is that when the C program was compiled into assembly language, your toUpper function ended up like this, perhaps:
_toUpper:
LFB4:
pushq %rbp
LCFI3:
movq %rsp, %rbp
LCFI4:
movb %dil, -4(%rbp)
cmpb $96, -4(%rbp)
jle L8
cmpb $122, -4(%rbp)
jg L8
movzbl -4(%rbp), %eax
subl $32, %eax
movb %al, -4(%rbp)
L8:
leave
ret
32的减法是在%eax寄存器进行。而在x86调用约定,就是在返回值预计将注册!所以...你真的很幸运。
The subtraction of 32 was carried out in the %eax register. And in the x86 calling convention, that is the register in which the return value is expected to be! So... you got lucky.
但请注意警告。他们是有原因的!