assembly

need help understanding the movzbl call in this function

我只是一个虾纸丫 提交于 2020-12-01 07:40:36
问题 So I'm trying to write some C code by looking at the assembly here: pushl %ebp movl %esp, %ebp movl 12(%ebp), %eax addl 8(%ebp), %eax movzbl (%eax), %eax movsbl %al,%eax popl %ebp ret I see that I have two variables, and they are being added together, then I'm getting lost when looking when the function starts calling movzbl and movesbl. What's going on here? 回答1: A corresponding C function would be something like char fn(char * string, int index) { return string[index]; } Specifically, the

need help understanding the movzbl call in this function

随声附和 提交于 2020-12-01 07:35:25
问题 So I'm trying to write some C code by looking at the assembly here: pushl %ebp movl %esp, %ebp movl 12(%ebp), %eax addl 8(%ebp), %eax movzbl (%eax), %eax movsbl %al,%eax popl %ebp ret I see that I have two variables, and they are being added together, then I'm getting lost when looking when the function starts calling movzbl and movesbl. What's going on here? 回答1: A corresponding C function would be something like char fn(char * string, int index) { return string[index]; } Specifically, the

need help understanding the movzbl call in this function

倾然丶 夕夏残阳落幕 提交于 2020-12-01 07:33:00
问题 So I'm trying to write some C code by looking at the assembly here: pushl %ebp movl %esp, %ebp movl 12(%ebp), %eax addl 8(%ebp), %eax movzbl (%eax), %eax movsbl %al,%eax popl %ebp ret I see that I have two variables, and they are being added together, then I'm getting lost when looking when the function starts calling movzbl and movesbl. What's going on here? 回答1: A corresponding C function would be something like char fn(char * string, int index) { return string[index]; } Specifically, the

Function parameters transferred in registers on 64bit OS?

送分小仙女□ 提交于 2020-11-30 12:24:04
问题 I am reading one of Agner Fog's manuals and as an advantage for 64 bit Operating Systems (over 32 bit) he says: Function parameters are transferred in registers rather than on the stack. This makes function calls more efficient. Is he saying the stack is not used for passing function parameters (64bit OS) at all??? 回答1: Yes, that's what he's saying, but it's not quite accurate. The stack may be used, but only if your function has a lot of parameters (or you write code that forces a spill). If

Function parameters transferred in registers on 64bit OS?

☆樱花仙子☆ 提交于 2020-11-30 12:21:14
问题 I am reading one of Agner Fog's manuals and as an advantage for 64 bit Operating Systems (over 32 bit) he says: Function parameters are transferred in registers rather than on the stack. This makes function calls more efficient. Is he saying the stack is not used for passing function parameters (64bit OS) at all??? 回答1: Yes, that's what he's saying, but it's not quite accurate. The stack may be used, but only if your function has a lot of parameters (or you write code that forces a spill). If

Function parameters transferred in registers on 64bit OS?

梦想与她 提交于 2020-11-30 12:21:10
问题 I am reading one of Agner Fog's manuals and as an advantage for 64 bit Operating Systems (over 32 bit) he says: Function parameters are transferred in registers rather than on the stack. This makes function calls more efficient. Is he saying the stack is not used for passing function parameters (64bit OS) at all??? 回答1: Yes, that's what he's saying, but it's not quite accurate. The stack may be used, but only if your function has a lot of parameters (or you write code that forces a spill). If

Function parameters transferred in registers on 64bit OS?

ⅰ亾dé卋堺 提交于 2020-11-30 12:19:21
问题 I am reading one of Agner Fog's manuals and as an advantage for 64 bit Operating Systems (over 32 bit) he says: Function parameters are transferred in registers rather than on the stack. This makes function calls more efficient. Is he saying the stack is not used for passing function parameters (64bit OS) at all??? 回答1: Yes, that's what he's saying, but it's not quite accurate. The stack may be used, but only if your function has a lot of parameters (or you write code that forces a spill). If

What is the purpose of the Parity Flag on a CPU?

一个人想着一个人 提交于 2020-11-30 08:28:31
问题 Some CPUs (notably x86 CPUs) feature a parity flag on their status register. This flag indicates whether the number of bits of the result of an operation is odd or even. What actual practical purpose does the parity flag serve in a programming context? Side note: I'm presuming it's intended to be used in conjunction with a parity bit in order to perform basic error checking, but such a task seems to uncommon to warrant an entire CPU flag. 回答1: Back in the "old days" when performance was

Syscall/sysenter on LLVM

我与影子孤独终老i 提交于 2020-11-30 08:23:12
问题 How do I write the LLVM bitcode required to emit an architecture-specific system call instruction? More specifically, clang supports inline assembly, and clearly supports emitting system calls (otherwise libc and vdso could not be compiled). How does the translation work for this, and how can I tickle it to reproduce this behavior? I understand LLVM itself may not understand the calling interface and register schedule used by various architectures in a sufficiently high-level manner to be

What is the purpose of the Parity Flag on a CPU?

有些话、适合烂在心里 提交于 2020-11-30 08:23:12
问题 Some CPUs (notably x86 CPUs) feature a parity flag on their status register. This flag indicates whether the number of bits of the result of an operation is odd or even. What actual practical purpose does the parity flag serve in a programming context? Side note: I'm presuming it's intended to be used in conjunction with a parity bit in order to perform basic error checking, but such a task seems to uncommon to warrant an entire CPU flag. 回答1: Back in the "old days" when performance was