fork download
  1. /* システムコールを使用してstrを標準出力に書き出す(EINTRなどへの対応は省略) */
  2. void print_using_write(const char *str) {
  3. asm volatile (
  4. "mov $4, %%eax\n\t" /* write */
  5. "mov $1, %%ebx\n\t" /* 標準出力 */
  6. "mov %0, %%ecx\n\t" /* 出力する内容へのポインタ */
  7. "xor %%edx, %%edx\n\t" /* 文字列の長さを計算する */
  8. "1:\n\t"
  9. "testb $0xff, (%%ecx, %%edx)\n\t"
  10. "jz 2f\n\t"
  11. "inc %%edx\n\t"
  12. "jmp 1b\n\t"
  13. "2:\n\t"
  14. "int $0x80\n\t" /* システムコール呼び出し */
  15. :: "m"(str) : "%eax", "%ebx", "%ecx", "%edx");
  16. }
  17.  
  18. int
  19. Main(int argc,char*argv[])
  20. {
  21. (void)argc; /* 警告避け */
  22. (void)argv; /* 警告避け */
  23. print_using_write("hello, world");
  24. print_using_write("\n");
  25. return 0;
  26. }
  27.  
  28. int main(int asumi_kana, char **sakura_ayane) {
  29. return Main(asumi_kana, sakura_ayane);
  30. }
  31.  
Success #stdin #stdout 0s 2004KB
stdin
Standard input is empty
stdout
hello, world