Skip to content

Instantly share code, notes, and snippets.

@icecoobe
Last active January 2, 2016 16:19
Show Gist options
  • Save icecoobe/8328893 to your computer and use it in GitHub Desktop.
Save icecoobe/8328893 to your computer and use it in GitHub Desktop.
Demo of CPU instruction "neg"
#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