x86-64

Linux default behavior against `.data` section

戏子无情 提交于 2020-12-23 09:31:49
问题 Story Case 1 I accidentally wrote my Assembly code in the .data section. I compiled it and executed it. The program ran normally under Linux 5.4.0-53-generic even though I didn't specify a flag like execstack . Case 2: After that, I executed the program under Linux 5.9.0-050900rc5-generic . The program got SIGSEGV . I inspected the virtual memory permission by reading /proc/$pid/maps . It turned out that the section is not executable. I think there is a configuration on Linux that manages

What is the “-4” for in assembler: movl $1, -4(%rbp) [duplicate]

我怕爱的太早我们不能终老 提交于 2020-12-15 07:06:37
问题 This question already has answers here : What does the bracket in `movl (%eax), %eax` mean? (3 answers) What does a hexadecimal number, with a register in parenthesis mean in Assembly? (1 answer) Closed 22 days ago . int x=1; int y=2; int z=3; turns into movl $1, -4(%rbp) movl $2, -8(%rbp) movl $3, -12(%rbp) What is the -4,-8,-12 for ? Why is it going by 4's? 4 bytes = 32 bits? 回答1: -4 / -8 / -12 bytes relative to the address held in rbp , which is the pointer to the top of the stack (which

How to get an argument from stack in x64 assembly?

旧城冷巷雨未停 提交于 2020-12-15 06:22:05
问题 I'm trying to write a procedure in x64 assembly. I'm calling it in a main program that is written in C++. I'm passing several parameters. I know that first 4 will be in specific registers and the rest of them (should be) on stack. What's more, I read that before taking 5th argument from the stack, I should substract 40 from RSP. And at the begining it worked. Later I needed to check the address of sth so I did it by: cout and &. But then, taking 5th argument from stack didn't work and I have

what's the purpose of using media registers that can hold 32 bytes [duplicate]

三世轮回 提交于 2020-12-13 04:55:33
问题 This question already has answers here : What is the difference between non-packed and packed instruction in the context of SIMD-operations? (2 answers) What is the benefit of SIMD on a superscalar out-of-order CPU? (1 answer) What are some rules of thumb for when SIMD would be faster? (SSE2, AVX) [closed] (1 answer) Why floating point registers are different than general purpose ones (1 answer) Is there any architecture that uses the same register space for scalar integer and floating point

Assembler output does not run on my Linux machine

我们两清 提交于 2020-12-13 04:54:00
问题 I followed up this page and compiled the following code ; assembly program that calls a C function on 64-bit Linux ; ; int main(void) { ; printf(fmt, 1, msg1); ; printf(fmt, 2, msg2); ; return 0; ; ; Assemble in 64-bit: nasm -f elf64 -o hp64.o -l hp64.lst hello-printf-64.asm ; ; Link: ld hp64.o -o hp64 -lc --dynamic-linker /lib/ld-2.7.so ; or maybe ld hp64.o -o hp64 -lc --dynamic-linker /lib/ld-linux-x86-64.so.2 ; (the "-lc" option is needed to resolve "printf") ;-----------------------------

Assembler output does not run on my Linux machine

霸气de小男生 提交于 2020-12-13 04:50:05
问题 I followed up this page and compiled the following code ; assembly program that calls a C function on 64-bit Linux ; ; int main(void) { ; printf(fmt, 1, msg1); ; printf(fmt, 2, msg2); ; return 0; ; ; Assemble in 64-bit: nasm -f elf64 -o hp64.o -l hp64.lst hello-printf-64.asm ; ; Link: ld hp64.o -o hp64 -lc --dynamic-linker /lib/ld-2.7.so ; or maybe ld hp64.o -o hp64 -lc --dynamic-linker /lib/ld-linux-x86-64.so.2 ; (the "-lc" option is needed to resolve "printf") ;-----------------------------

Calculating LCM in assembly x86

。_饼干妹妹 提交于 2020-12-12 05:35:11
问题 I have the following assembly code .global _start .section .text _start: movq a, %rax movq b, %rbx imul %rbx, %rax cmp %rbx, %rax je gcd_calculated ja l1 sub %rax, %rbx jmp _start l1: sub %rbx, %rax jmp _start gcd_calculated: div %rax movq %rax, (c) a,b are quads that I need to calculate their lcm and I need to assign the result to c I get wrong results with the above code and I can't spot why. generally, i'm relaying on the the lcm = (a*b)/gcd so I store a*b in %rax and then calculate the

Linux x86-64 Hello World and register usage for parameters

若如初见. 提交于 2020-12-06 04:14:39
问题 I found this page which has a Hello World example for x86-64 on Linux: http://blog.markloiseau.com/2012/05/64-bit-hello-world-in-linux-assembly-nasm/ ; 64-bit "Hello World!" in Linux NASM global _start ; global entry point export for ld section .text _start: ; sys_write(stdout, message, length) mov rax, 1 ; sys_write mov rdi, 1 ; stdout mov rsi, message ; message address mov rdx, length ; message string length syscall ; sys_exit(return_code) mov rax, 60 ; sys_exit mov rdi, 0 ; return 0

Linux x86-64 Hello World and register usage for parameters

落花浮王杯 提交于 2020-12-06 04:14:29
问题 I found this page which has a Hello World example for x86-64 on Linux: http://blog.markloiseau.com/2012/05/64-bit-hello-world-in-linux-assembly-nasm/ ; 64-bit "Hello World!" in Linux NASM global _start ; global entry point export for ld section .text _start: ; sys_write(stdout, message, length) mov rax, 1 ; sys_write mov rdi, 1 ; stdout mov rsi, message ; message address mov rdx, length ; message string length syscall ; sys_exit(return_code) mov rax, 60 ; sys_exit mov rdi, 0 ; return 0

How do I interpet this x86_64 assembly opcode?

我的未来我决定 提交于 2020-12-02 05:55:51
问题 Looking at some assembly code for x86_64 on my Mac, I see the following instruction: 48 c7 c0 01 00 00 00 movq $0x1,%rax But nowhere can I find a reference that breaks down the opcode. It seems like 48c7 is a move instruction, c0 defines the %rax register, etc. So, where can I find a reference that tells me all that? I am aware of http://ref.x86asm.net/, but looking at 48 opcodes, I don't see anything that resembles a move. 回答1: Actually, mov is 0xc7 there; 0x48 is, in this case, a long mode