Guest User

Untitled

a guest
Apr 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define eflags16(x) \
  5. { \
  6. __asm__ __volatile__( "pushf;\n\t" \
  7. "movw (%%esp), %%ax;\n\t" \
  8. "popf;\n\t" \
  9. "movw %%ax, %1;\n" \
  10. : "=r"(x) \
  11. : \
  12. :"%ax" \
  13. ); \
  14. }
  15.  
  16. enum EFlagEnum
  17. {
  18. EFLAG_CARRY = 1,
  19. EFLAG_PARITY = 1<<2,
  20. EFLAG_ZERO = 1<<6,
  21. EFLAG_SIGN = 1<<7,
  22. EFLAG_OVERFLOW = 1<<11
  23. };
  24.  
  25. typedef unsigned short ui16;
  26. typedef unsigned int ui32;
  27.  
  28. int main(void)
  29. {
  30. ui32 a=0x3279FA1C, b,c;
  31. ui16 flags;
  32. b = rand();
  33. c = a + b;
  34.  
  35. eflags16(flags);
  36.  
  37. if(flags & EFLAG_CARRY)
  38. {
  39. printf("Carry set.\n");
  40. }
  41. if(flags & EFLAG_PARITY)
  42. {
  43. printf("Parity set.\n");
  44. }
  45. if(flags & EFLAG_ZERO)
  46. {
  47. printf("Zero set.\n");
  48. }
  49. if(flags & EFLAG_SIGN)
  50. {
  51. printf("Sign set.\n");
  52. }
  53. if(flags & EFLAG_OVERFLOW)
  54. {
  55. printf("Overflow set.\n");
  56. }
  57. return 0;
  58. }
Add Comment
Please, Sign In to add comment