x86-64

NASM x86_64 assembly in 32-bit mode: Why does this instruction produce RIP-Relative Addressing code?

孤街浪徒 提交于 2020-07-29 06:59:12
问题 [bits 32] global _start section .data str_hello db "HelloWorld", 0xa str_hello_length db $-str_hello section .text _start: mov ebx, 1 ; stdout file descriptor mov ecx, str_hello ; pointer to string of characters that will be displayed mov edx, [str_hello_length] ; count outputs Relative addressing mov eax, 4 ; sys_write int 0x80 ; linux kernel system call mov ebx, 0 ; exit status zero mov eax, 1 ; sys_exit int 0x80 ; linux kernel system call The fundamental thing here is that I need to have

Why does GCC allocate more space than necessary on the stack, beyond what's needed for alignment?

浪尽此生 提交于 2020-07-25 06:16:08
问题 I'm reading a textbook which shows assembly code based on C code: C code: void echo() { char buf[8]; otherFunction(buf); } assembly code: echo: subq $24, %rsp //Allocate 24 bytes on stack, but why allocate 24 instead of 8 bytes? movq %rsp, %rdi //Compute buf as %rsp call otherFunction I don't understand why stack pointer %rsp is decremented by 24 bytes. I only assign 8 bytes' buffer as char buf[8]; , and there no callee saved registers to push on stack, shouldn't the instruction be subq $8,

Why does GCC allocate more space than necessary on the stack, beyond what's needed for alignment?

我们两清 提交于 2020-07-25 06:15:39
问题 I'm reading a textbook which shows assembly code based on C code: C code: void echo() { char buf[8]; otherFunction(buf); } assembly code: echo: subq $24, %rsp //Allocate 24 bytes on stack, but why allocate 24 instead of 8 bytes? movq %rsp, %rdi //Compute buf as %rsp call otherFunction I don't understand why stack pointer %rsp is decremented by 24 bytes. I only assign 8 bytes' buffer as char buf[8]; , and there no callee saved registers to push on stack, shouldn't the instruction be subq $8,

Assembly: why some x86 opcodes are invalid in x64?

北战南征 提交于 2020-07-20 10:14:05
问题 My question arises from a simple curiosity: Why in x64 some of the opcodes are invalid (06, 07 for example), whereas in x86 are used for fairly basic instructions (06 and 07 being push and pop)? I though that those simplest instructions would do nicely in both architectures. Why they disabled some of those simple instructions in x64? Why wouldn't they work? Why they disabled some opcodes, creating holes in opcode list, when they could instead assign them to x64 versions of instructions?

x86-64 canonical address?

放肆的年华 提交于 2020-07-15 07:08:08
问题 During reading of an Intel manual book I came across the following: On processors that support Intel 64 architecture, the IA32_SYSENTER_ESP field and the IA32_SYSENTER_EIP field must each contain a canonical address. What is a 'canonical address'? 回答1: I suggest that you download the full software developer's manual. The documentation is available in separate volumes, but that link gives you all seven volumes in a single massive PDF, which makes it easier to search for things. The answer is

x86-64 canonical address?

隐身守侯 提交于 2020-07-15 07:08:07
问题 During reading of an Intel manual book I came across the following: On processors that support Intel 64 architecture, the IA32_SYSENTER_ESP field and the IA32_SYSENTER_EIP field must each contain a canonical address. What is a 'canonical address'? 回答1: I suggest that you download the full software developer's manual. The documentation is available in separate volumes, but that link gives you all seven volumes in a single massive PDF, which makes it easier to search for things. The answer is

What is -fverbose-asm trying to say in assembly?

笑着哭i 提交于 2020-07-10 05:14:34
问题 I have compiled this function: void print_ints(int len, ...){ va_list args; va_start(args, len); for(int i =0; i<len ; i++) { int val = va_arg(args,int); printf("i:%i\tval:%i\n",i,val); } va_end(args); } into this assembly: print_ints: pushq %rbp # movq %rsp, %rbp #, subq $224, %rsp #, movl %edi, -212(%rbp) # len, len movq %rsi, -168(%rbp) #, movq %rdx, -160(%rbp) #, movq %rcx, -152(%rbp) #, movq %r8, -144(%rbp) #, movq %r9, -136(%rbp) #, testb %al, %al # je .L7 #, movaps %xmm0, -128(%rbp) #,

What is -fverbose-asm trying to say in assembly?

柔情痞子 提交于 2020-07-10 05:14:11
问题 I have compiled this function: void print_ints(int len, ...){ va_list args; va_start(args, len); for(int i =0; i<len ; i++) { int val = va_arg(args,int); printf("i:%i\tval:%i\n",i,val); } va_end(args); } into this assembly: print_ints: pushq %rbp # movq %rsp, %rbp #, subq $224, %rsp #, movl %edi, -212(%rbp) # len, len movq %rsi, -168(%rbp) #, movq %rdx, -160(%rbp) #, movq %rcx, -152(%rbp) #, movq %r8, -144(%rbp) #, movq %r9, -136(%rbp) #, testb %al, %al # je .L7 #, movaps %xmm0, -128(%rbp) #,

relocation R_X86_64_8 against undefined symbol `ELF' can not be used when making a PIE object

冷暖自知 提交于 2020-07-09 11:55:27
问题 Having this in gas: .text .globl main main: xor %eax, %eax lea str(%rip), %rdi call printf call exit str: .byte 0x7F, "ELF", 1,1,1,0 I thought the .byte directive could be concatenate as in nasm db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident source : http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html 回答1: In GAS syntax, "ELF" is a symbol reference to the symbol name ELF , not a multi-char string. In the context of .byte directive, it's only looking for a number, not a possible string. And

relocation R_X86_64_8 against undefined symbol `ELF' can not be used when making a PIE object

假装没事ソ 提交于 2020-07-09 11:55:09
问题 Having this in gas: .text .globl main main: xor %eax, %eax lea str(%rip), %rdi call printf call exit str: .byte 0x7F, "ELF", 1,1,1,0 I thought the .byte directive could be concatenate as in nasm db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident source : http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html 回答1: In GAS syntax, "ELF" is a symbol reference to the symbol name ELF , not a multi-char string. In the context of .byte directive, it's only looking for a number, not a possible string. And