Advertisement
Guest User

Untitled

a guest
Feb 13th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int char_get() {
  2.     int res;
  3.     volatile char c;
  4.     asm volatile(
  5.         "movl   %1, %%eax\n"
  6.         "movl   %3, %%ebx\n"
  7.         "movl   %2, %%ecx\n"
  8.         "movl   %4, %%edx\n"
  9.         "int $0x80"
  10.         "movl %%eax, %0"
  11.         : "=g"(res)
  12.         : "g"(__NR_read),
  13.         "g"(&c),
  14.         "g"(0),
  15.         "g"(1)
  16.         : "eax", "ebx", "ecx", "edx", "memory"
  17.     );
  18.     if (res <= 0) {
  19.         return -1;
  20.     }
  21.     if (c >= 'a' && c <= 'z') {
  22.         c = 'A' + c - 'a';
  23.     }
  24.     asm volatile(
  25.         "movl   %0, %%eax\n"
  26.         "movl   %2, %%ebx\n"
  27.         "movzb  %1, %%ecx\n"
  28.         "movl   %3, %%edx\n"
  29.         "int $0x80"
  30.         "movl %%eax, %0"
  31.         : : "g"(__NR_write),
  32.         "g"(c),
  33.         "g"(1),
  34.         "g"(1)
  35.         : "eax", "ebx", "ecx", "edx", "memory"
  36.     );
  37.     return 1;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement