I wrote a code in ASM to calculate the reverse number. For example: input: 123, the result should be 321. The ebx register should have the result, but it aways shows 0. Also, I have an exception "Privileged instruction". I attached an image with the exception. Here is the code: 
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int main() {
int nb;
cout << "nb=";
cin >> nb;
_asm {
mov eax, nb;
mov ebx, 0;
mov ecx, 10;
_check_while:
cmp eax, 0;
je _outside_while;
mov edx, 0;
div ecx;
xchg eax, ebx;
mul ecx;
add eax, edx;
xchg eax, ebx;
jmp _check_while;
_outside_while:
mov nb, ebx;
}
cout << "Result is" << " " << nb;
return 0;
}
div ecxcan't #DE fault with ECX=10, and none of your instructions modify ECX. (And that wouldn't be a #GP(0) privileged instruction problem anyway.)mul ecxoverwritesedx. You might want to useimul eax, ecx.mulso I think you could simplify by removing thexchgs and doimul ebx, ecx. Oh wait, you are reading EDX aftermul? Probably you were expecting it to still hold the remainder fromdiv. But actually it will be zero for small inputs where the high half of the 32x32 => 64-bit wideningmul ecxis zero.