assembly

How do I negate a 64-bit integer stored in a 32-bit register pair?

允我心安 提交于 2021-01-29 03:14:56
问题 I've stored a 64-bit integer in the EDX:EAX register pair . How can I correctly negate the number? For example: 123456789123 → -123456789123 . 回答1: Ask a compiler for ideas: compile int64_t neg(int64_t a) { return -a; } in 32-bit mode. Of course, different ways of asking the compiler will have the starting value in memory, in the compiler's choice of registers, or already in EDX:EAX. See all three ways on the Godbolt compiler explorer, with asm output from gcc, clang, and MSVC (aka CL). There

Assembly: JA and JB work incorrectly

若如初见. 提交于 2021-01-29 02:45:27
问题 Since my main OS is linux and have project on visual studio, I decided to use online compilers to achieve it. I found this which was suggested by many. So here is my code: #include <iostream> using namespace std; int main(void) { float a = 1; float b = 20.2; float res = 0; float res1 = 0; _asm { FLD a FCOM b JA midi JMP modi midi: FST res JMP OUT modi: FST res1 JMP OUT } OUT: cout << "res = " << res << endl; cout << "res1 = " << res1 << endl; return 0; } My goal is simple, if a is greater

How do I use labels in address calculations

你离开我真会死。 提交于 2021-01-29 02:05:37
问题 I have the following snippet of inline assembly: procedure Foo; asm //..... @partialloop: shr rdx,1 //every instruction is 4 bytes lea r11,[rip + (7*4)+(@partial-@offset)] @offset: sub r11,rdx xor r8,r8 jmp r11 //do a partial loop @loop64: mov [rcx],rax @partial: mov [rcx+08H],rax //.... end; The compiler does not accept this syntax: E2105 Inline assembler syntax error Create use of offset , ptr or @@ does not help. What syntax do I need to use to make this compile? 回答1: Label addresses are

Factorial function in x86 NASM assembly goes wrong

会有一股神秘感。 提交于 2021-01-29 01:54:26
问题 I'm learning assembly language using x86 NASM. I wanted to write a simple recursive factorial function to which I am passing one parameter using EAX register. After that, I want to print my result on the screen but nothing happens. After sitting and staring on my computer I don't have any clue what is wrong with my code. Can you guys help newbie with this problem? I know that the prologue and epilogue of factorial funtion is not required due I'm not using stack but for me code is more

Problems with non-atomic access example on GNU website

99封情书 提交于 2021-01-29 01:34:36
问题 On the website of GNU there is a simple example available which is supposed to demonstrate the problems appearing with non-atomic access. The example contains a small mistake, they have forgotten #include <unistd.h> : #include <signal.h> #include <stdio.h> #include <unistd.h> struct two_words { int a, b; } memory; static struct two_words zeros = { 0, 0 }, ones = { 1, 1 }; void handler(int signum) { printf ("%d,%d\n", memory.a, memory.b); alarm (1); } int main (void) { signal (SIGALRM, handler

Problems with non-atomic access example on GNU website

偶尔善良 提交于 2021-01-29 01:32:31
问题 On the website of GNU there is a simple example available which is supposed to demonstrate the problems appearing with non-atomic access. The example contains a small mistake, they have forgotten #include <unistd.h> : #include <signal.h> #include <stdio.h> #include <unistd.h> struct two_words { int a, b; } memory; static struct two_words zeros = { 0, 0 }, ones = { 1, 1 }; void handler(int signum) { printf ("%d,%d\n", memory.a, memory.b); alarm (1); } int main (void) { signal (SIGALRM, handler

Problems with non-atomic access example on GNU website

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 01:31:43
问题 On the website of GNU there is a simple example available which is supposed to demonstrate the problems appearing with non-atomic access. The example contains a small mistake, they have forgotten #include <unistd.h> : #include <signal.h> #include <stdio.h> #include <unistd.h> struct two_words { int a, b; } memory; static struct two_words zeros = { 0, 0 }, ones = { 1, 1 }; void handler(int signum) { printf ("%d,%d\n", memory.a, memory.b); alarm (1); } int main (void) { signal (SIGALRM, handler

Is it possible to output a string to the console in C without including the standard library?

半腔热情 提交于 2021-01-28 21:46:56
问题 I'm trying to get better understanding of how assembly and machine code works. So I'm compiling this simple snipet with gcc : #include <stdio.h> int main(){ printf("Hello World!"); return 0; } But this includes the default library. I would like to output hello world without using printf but by inlining some assembly in the C file, and adding -nostdlib and -nodefaultlibs options to gcc. How can I do that ? I'm using Windows 10 and mingw-w64 with Intel core i7 6700 HQ (laptop processor). Can I

Is it possible to output a string to the console in C without including the standard library?

时光怂恿深爱的人放手 提交于 2021-01-28 21:16:41
问题 I'm trying to get better understanding of how assembly and machine code works. So I'm compiling this simple snipet with gcc : #include <stdio.h> int main(){ printf("Hello World!"); return 0; } But this includes the default library. I would like to output hello world without using printf but by inlining some assembly in the C file, and adding -nostdlib and -nodefaultlibs options to gcc. How can I do that ? I'm using Windows 10 and mingw-w64 with Intel core i7 6700 HQ (laptop processor). Can I

Counting Characters in a String in armV7

风流意气都作罢 提交于 2021-01-28 19:44:23
问题 My program is supposed to ask for a single line of user input and then print out the number of characters in the string. As of now it is telling me there are 104 characters when I input hello followed by a segmentation fault. Here is my code: userInput: .asciz "\nEnter a string: " TemptRet: .word 10 inputBuffer: .skip 11 countMessage: .STRING "There are %d characters in: \"%s\".\n" .text .global main main: LDR R0, =courseStr BL puts countString: LDR R0, =userInput BL printf LDR R0, =TemptRet