Last active
January 2, 2016 16:19
-
-
Save icecoobe/8328893 to your computer and use it in GitHub Desktop.
Demo of CPU instruction "neg"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <conio.h> | |
short negtest(short a); | |
int main(int argc, char* argv[]) | |
{ | |
short a = 0; | |
printf("a = %d, result = %d\n", a, negtest(a)); | |
a = 1; | |
printf("a = %d, result = %d\n", a, negtest(a)); | |
getch(); | |
return 0; | |
} | |
//--------------------------------------------------------------------------- | |
short negtest(short a) | |
{ | |
short b = 0; | |
__asm | |
{ | |
mov ax, a | |
neg ax | |
sbb ax, ax | |
mov b, ax | |
} | |
return b; // this is optional, caller can get the returned value via register "ax" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment