x86-64

Porting from 32 to 64-bit by just changing all the register names from eXX to rXX makes factorial return 0?

只谈情不闲聊 提交于 2019-12-13 02:58:16
问题 How fortunate it is for all of use learning the art of computer programming to have access to a community such as Stack Overflow! I have made the decision to take up the task of learning how to program computers and I am doing so by the knowledge of an e-book called 'Programming From the Ground Up', which teaches the reader how to create programs in the assembly language within the GNU/Linux environment. My progress in the book has come to the point of creating a program which computes the

Error creating ubuntu 16 container under arch

断了今生、忘了曾经 提交于 2019-12-13 02:49:35
问题 I am trying to install a Ubuntu container on Archlinux using LXC. I am following this guide:https://gist.github.com/manoj23/8a35849697945896cdaef77927c695a7 After I run this command: lxc-create --name=ubuntu-16 --template=ubuntu -- --release xenial --arch amd64 I get the following error: Bad template: ubuntu Error creating container ubuntu-16 Why is this happening? 回答1: It says in the error. Bad template. You can see that in the current version of lxc there is no ubuntu template. The gist is

Saving the XMM register before function call

倖福魔咒の 提交于 2019-12-13 01:35:06
问题 Is it required to save/push the any XMM registers to the stack before the assembly function call? Because am observing the crash issue in my code with release mode for 64-bit development(Using AVX2). In debug mode its working fine. I tried with saving the content of the XMM8 register and restoring it at end of function call then its working fine. Any idea or references? 回答1: Yes, on Microsoft Windows you are required to preserve the XMM6-XMM15 registers. See http://msdn.microsoft.com/en-us

Relocation error when compiling NASM code in 64-bit mode

岁酱吖の 提交于 2019-12-13 00:34:04
问题 I have written a simple assembly code which I am trying to compile in 64-bit mode. Here is the code: extern printf section .rodata readinfo db `%d\n`, 0 section .text global main main: mov rbp, rsp ; for correct debugging mov rax, 5 push rax push readinfo call printf add rsp, 8 xor rax, rax mov rsp, rbp ret And here are the instructions I give to nasm and gcc (as I have read on other posts, gcc automatically links the object file with the default c libraries): nasm -f elf64 -o test.o test.asm

mov & jmp to & jmp back vs call & ret

二次信任 提交于 2019-12-13 00:03:18
问题 I was going over some Assembly code and I saw this: mov r12, _read_loopr jmp _bzero _read_loopr: ... _bzero: inc r8 mov byte [r8+r15], 0x0 cmp r8, 0xff jle _bzero jmp r12 And I was wondering if there was any particular advantage to doing this (mov _read_loopr to a register jmp to the function and then jmp back) rather than the usual call _bzero and ret? 回答1: This just looks like braindead code, especially if the return-address label is always right after the jmp _bzero like you say in your

Assembly coding strdup. Malloc calling in shared library

自古美人都是妖i 提交于 2019-12-12 21:26:57
问题 I have a problem, I can't compile my strdup while calling malloc. When I don't call malloc, it compiles my shared library perfectly, so if someone could help me that would be great ! here is my code: BITS 64 DEFAULT REL global my_strdup:function extern malloc my_strdup: [...] call malloc I compile with this: $> nasm -f elf64 my_strdup.S $> gcc -shared -o libmy.so my_strdup.o /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: my_strdup.o: relocation R_X86_64_PC32

How to use INVLPG on x86-64 architecture?

别等时光非礼了梦想. 提交于 2019-12-12 19:16:11
问题 I'm trying to measure memory access timings and need to reduce the noise produced by TLB hits and misses In order to clear a specific page out of the TLB I tried to use the INVLPG instruction, following those two examples: http://wiki.osdev.org/Paging and http://wiki.osdev.org/Inline_Assembly/Examples I wrote the following code: static inline void __native_flush_tlb_single(unsigned long addr) { asm volatile("invlpg (%0)" ::"r" (addr) : "memory"); } But the resulting binary throws an SIGSEGV

why cannot define same local label in multiple functions?

无人久伴 提交于 2019-12-12 18:54:56
问题 Want to define same local label in multiple functions: .text .globl main func: push %rbp mov %rsp, %rbp .a: leave ret main: push %rbp mov %rsp, %rbp .a: leave ret Strangely get error: $ clang -c main.s main.s:13:1: error: invalid symbol redefinition .a: ^ When I was using yasm it allowed same local labels in multiple functions. Do you have any clues? 回答1: Unlike NASM, .label isn't local to the function (actually preceding non- . label) in gas syntax. .Llabel is a "local" symbol name, meaning

Why Assembly x86_64 syscall parameters are not in alphabetical order like i386

末鹿安然 提交于 2019-12-12 17:43:13
问题 There is that one question that troubles me. So ... Why in x86_32 the parameters are passed in registers that I feel are in alphabetically ( eax , ecx , edx , esi ) and ranked order ( esi , edi , ebp ) +---------+------+------+------+------+------+------+ | syscall | arg0 | arg1 | arg2 | arg3 | arg4 | arg5 | +---------+------+------+------+------+------+------+ | %eax | %ebx | %ecx | %edx | %esi | %edi | %ebp | +---------+------+------+------+------+------+------+ section .text global _start

Load the address of a symbol (nasm, 64-bit OS X)

寵の児 提交于 2019-12-12 17:25:21
问题 I have some assembly that needs to load a C symbol in OS X (x86-64). With x86, the way you do this is: mov rax, some_symbol_name However, with x86-64, this causes a link warning: ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from Test2.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie Note: I know what PIE is, and I don't want to disable it. Here are some of my other attempts to