DOS stdin stdout inline ASM


/ Published in: C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. void putch(char c){
  2. asm(
  3. "movb $2,%%ah\n"
  4. "int $0x21\n"
  5. :
  6. :"d"(c)
  7. :"ah"
  8. );
  9. }
  10.  
  11. void newline(){
  12. putch('\r');
  13. putch('\n');
  14. }
  15.  
  16. void puts(char*s){
  17. while(*s){
  18. putch(*s);
  19. ++s;
  20. }
  21. newline();
  22. }
  23.  
  24. char kbhit(){
  25. char c;
  26. asm(
  27. "movb $1,%%ah\n"
  28. "int $0x16\n"
  29. "setnzb %0"
  30. :"=g"(c)
  31. :
  32. );
  33. return c;
  34. }
  35.  
  36. char kbhit2(){
  37. char c;
  38. asm(
  39. "movb $0x0b,%%ah\n"
  40. "int $0x21\n"
  41. :"=a"(c)
  42. :
  43. );
  44. return c;
  45. }
  46.  
  47. char getch(){
  48. char c;
  49. asm(
  50. "movb $0,%%ah\n"
  51. "int $0x16\n"
  52. :"=a"(c)
  53. :
  54. );
  55. return c;
  56. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.