calling-convention

When do we create base pointer in a function - before or after local variables?

给你一囗甜甜゛ 提交于 2021-02-18 19:03:16
问题 I am reading the Programming From Ground Up book. I see two different examples of how the base pointer %ebp is created from the current stack position %esp . In one case, it is done before the local variables. _start: # INITIALIZE PROGRAM subl $ST_SIZE_RESERVE, %esp # Allocate space for pointers on the # stack (file descriptors in this # case) movl %esp, %ebp The _start however is not like other functions, it is the entry point of the program. In another case it is done after. power: pushl

When do we create base pointer in a function - before or after local variables?

扶醉桌前 提交于 2021-02-18 19:00:53
问题 I am reading the Programming From Ground Up book. I see two different examples of how the base pointer %ebp is created from the current stack position %esp . In one case, it is done before the local variables. _start: # INITIALIZE PROGRAM subl $ST_SIZE_RESERVE, %esp # Allocate space for pointers on the # stack (file descriptors in this # case) movl %esp, %ebp The _start however is not like other functions, it is the entry point of the program. In another case it is done after. power: pushl

When do we create base pointer in a function - before or after local variables?

守給你的承諾、 提交于 2021-02-18 19:00:17
问题 I am reading the Programming From Ground Up book. I see two different examples of how the base pointer %ebp is created from the current stack position %esp . In one case, it is done before the local variables. _start: # INITIALIZE PROGRAM subl $ST_SIZE_RESERVE, %esp # Allocate space for pointers on the # stack (file descriptors in this # case) movl %esp, %ebp The _start however is not like other functions, it is the entry point of the program. In another case it is done after. power: pushl

Should %rsp be aligned to 16-byte boundary before calling a function in NASM?

社会主义新天地 提交于 2021-02-16 20:20:22
问题 I saw the following rules from NASM's document: The stack pointer %rsp must be aligned to a 16-byte boundary before making a call. Fine, but the process of making a call pushes the return address (8 bytes) on the stack, so when a function gets control, %rsp is not aligned. You have to make that extra space yourself, by pushing something or subtracting 8 from %rsp. And I have a snippet of NASM assembly code as below: The %rsp should be at the boundary of 8-bytes before I call the function "inc

ABI Register Names for RISC-V Calling Convention

落爺英雄遲暮 提交于 2021-02-08 12:19:40
问题 I'm confused about the RISC-V ABI Register Names. For example, Table 18.2 in the "RISC-V Instruction Set Manual, Volume I: User-Level ISA, Version 2.0" at page 85 specifies that the stack pointer sp is register x14 . However, the instruction addi sp,zero,0 is compiled to 0x00000113 by riscv64-unknown-elf-as ( -m32 does not make a difference). In binary: 000000000000 00000 000 00010 0010011 ^imm ^rs1 ^f3 ^rd ^opcode So here sp seems to be x2 . Then I googled a bit and found the RISC-V Linux

Passing parameters and return values for a subroutine in assembly

為{幸葍}努か 提交于 2021-02-07 12:19:31
问题 I am working with ARM assembly, where I have to write one subroutine for which I am following the ARM calling convention(this will have to be integrated with some separate higher level implementation somewhere else ) for passing parameters and return values. Now here is something I am not sure in general when working with assembly. So from the convention if I understand well the arguments are passed in order starting from registers r0 - r4 and then for other arguments stacks are used. Return

Why is tailcall optimization not performed for types of class MEMORY?

 ̄綄美尐妖づ 提交于 2021-02-07 05:20:43
问题 I'm trying to understand the implication of System V AMD64 - ABI for returning by value from a function. For the following data type struct Vec3{ double x, y, z; }; the type Vec3 is of class MEMORY and thus the following is specified by the ABI concerning "Returning of Values": If the type has class MEMORY, then the caller provides space for the return value and passes the address of this storage in %rdi as if it were the first argument to the function. In effect, this address becomes a

Why is tailcall optimization not performed for types of class MEMORY?

南笙酒味 提交于 2021-02-07 05:20:24
问题 I'm trying to understand the implication of System V AMD64 - ABI for returning by value from a function. For the following data type struct Vec3{ double x, y, z; }; the type Vec3 is of class MEMORY and thus the following is specified by the ABI concerning "Returning of Values": If the type has class MEMORY, then the caller provides space for the return value and passes the address of this storage in %rdi as if it were the first argument to the function. In effect, this address becomes a

What does “cdecl” stand for?

匆匆过客 提交于 2021-02-05 20:17:39
问题 Yes, I know that "cdecl" is the name of a prominent calling convention, so please don't explain calling conventions to me. What I'm asking is what the abbreviation (?) "cdecl" actually stands for. I think it's a poor naming choice, because at first sight it reminds one of "C declarator" (a rather unique syntactic aspect of C). In fact, there is a program called cdecl whose sole purpose is to decipher C declarators. But the C declarator syntax has absolutely nothing to do with calling

What does it mean that “registers are preserved across function calls”?

自闭症网瘾萝莉.ら 提交于 2021-02-05 09:03:38
问题 From this question, What registers are preserved through a linux x86-64 function call, it says that the following registers are saved across function calls: r12, r13, r14, r15, rbx, rsp, rbp So, I went ahead and did a test with the following: .globl _start _start: mov $5, %r12 mov $5, %r13 mov $5, %r14 mov $5, %r15 call get_array_size mov $60, %eax syscall get_array_size: mov $0, %r12 mov $0, %r13 mov $0, %r14 mov $0, %r15 ret And, I was thinking that after the call get_array_size that my