x86-64

harmonic series with x86-64 assembly

大兔子大兔子 提交于 2019-12-02 16:29:00
问题 Trying to compute a harmonic series. Right now I'm entering the number I want the addition to go up to. When I enter a small number like 1.2, the program just stops, doesn't crash, it seems to be doing calculations. BUt it never finishes the program here is my code denominator: xor r14,r14 ;zero out r14 register add r14, 2 ;start counter at 2 fld1 ;load 1 into st0 fxch st2 denomLoop: fld1 mov [divisor], r14 ;put 1 into st0 fidiv dword [divisor] ;divide st0 by r14 inc r14 ;increment r14 fst

Impossible constraint with cmpxchg16b in extended assembly

ⅰ亾dé卋堺 提交于 2019-12-02 14:07:57
I am trying to write inline assembly with my C code to perform compare and swap operation. My code is: typedef struct node { int data; struct node * next; struct node * backlink; int flag; int mark; } node_lf; typedef struct searchfrom { node_lf * current; node_lf * next; } return_sf; typedef struct csArg { node_lf * node; int mark; int flag; } cs_arg; typedef struct return_tryFlag { node_lf * node; int result; } return_tf; static inline node_lf cs(node_lf * address, cs_arg *old_val, cs_arg *new_val) { node_lf value = *address; __asm__ __volatile__("lock; cmpxchg16b %0; setz %1;" :"=m"(*

How to build x86 and/or x64 on Windows from command line with CMAKE?

左心房为你撑大大i 提交于 2019-12-02 14:03:05
One way to get cmake to build x86 on Windows with Visual Studio is like so: Start Visual Studio Command prompt for x86 Run cmake: cmake -G "NMake Makefiles" \path_to_source\ nmake One way to get cmake to build x64 on Windows with Visual Studio is like so: Start Visual Studio Command prompt for x64 Run cmake: cmake -G "NMake Makefiles" \path_to_source\ nmake Using Cmake, how do I compile either or both architectures? (like how Visual Studio does it from in the IDE) This cannot be done with CMake. You have to generate two separate build folders. One for the x86 NMake build and one for the x64

X86-64 NASM calling extern c functions

我是研究僧i 提交于 2019-12-02 13:59:11
Im very new to assembly but know a bit of c. Im playing around with extern function calls like extern _printf str db "Hello", 0 push str call _printf but cant find any tutorials using extern functions except scanf and printf. For example strcmp? How can i call strcmp in my case? Micrified Here is my answer. It is specific to x86-64 though. Please know that when pushing arguments to a function, you usually place the first 6 in registers rdi , rsi , rdx , rcx , r8 , and r9 . The rest get pushed to the stack. The specification for this is called the System V ABI (Note that Windows uses a

Why is x86 ugly? Why is it considered inferior when compared to others? [closed]

拥有回忆 提交于 2019-12-02 13:50:24
Recently I've been reading some SO archives and encountered statements against the x86 architecture. Why do we need different CPU architecture for server & mini/mainframe & mixed-core? says " PC architecture is a mess, any OS developer would tell you that. " Is learning Assembly Language worth the effort? ( archived ) says " Realize that the x86 architecture is horrible at best " Any easy way to learn x86 assembler? says " Most colleges teach assembly on something like MIPS because it's much simpler to understand, x86 assembly is really ugly " and many more comments like "Compared to most

Intel 64 bits, strange RSP behavior

北城余情 提交于 2019-12-02 13:35:38
I came accross a problem with debugging a 64 bit binary in Windows using IDA. Normally, after a push RSP value should be deducted by 8. But occasionally, from IDA I saw that RSP was only deducted by 2, and then 8 for the next Push. The codes involved are push rax push rbx push rsi push rdi I'm quite new to x64 environment, thus could anyone explain this behavior ? You're probably getting mixed up by hexadecimal. Counting by 8 goes 0 8 10 18 20 28 30 Are you looking at that and thinking 10 - 8 == 2 ? Because it's 0x10 - 0x8 == 0x8 . 来源: https://stackoverflow.com/questions/35958737/intel-64-bits

Trying to implement strlen in x86 GAS

巧了我就是萌 提交于 2019-12-02 12:34:38
问题 so I am very new (extremely new) to assembly programming and am trying to write a function that can calculate the length of a string. I feel I have some issue with clearing out values in registers, or with the incrementation of the pointer, because the value that is getting returned is always "4571 + length" for me. Basically, if I have string length 0, I get 4571 as the return value. If I have string length 6, I get 4577 as the return value, etc. Here's my code, any help will be appreciated:

Write to port 0cf8h fails with segfault

天大地大妈咪最大 提交于 2019-12-02 11:58:23
问题 I have an AMD processor of e2-2000 model. THis is family 0fh. According to family 0fh BKDG I have this code to read device and vendor ID: ReadPCIConfiguration: movq $0x80000100, %rax movq $0x0cf8, %rdx outl %eax, %dx # sigsegv caught here movq $0x0cfc, %rdx inl %dx, %eax ret As far as I know the algorithm to read/write PCI configuration is as follows: write target bus number, device number function number and offset or register number to configuration address port perform 1-, 2- or 4-byte r/w

printf float in nasm assembly 64-bit

家住魔仙堡 提交于 2019-12-02 10:57:32
问题 I want to print a float value with printf global main extern printf section .data string: db `%f\n`, 0 section .bss rs: resq 1 [...] movq xmm0, [rs] mov rdi, string mov rax, 0 call printf rs contains the floating value 1.6 (gdb) x/fg &rs 0x600ad8 <rs>: 1.6000000000000001 but the program prints [username@localhost folder]$ ./programname 0.000000 who can I get the program to print 1.6? what am I doing wrong? 回答1: I suspect the problem has something to do with your code setting rax to 0 whereas