cat.asm 523 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. global _start
  2. section .data
  3. getchar:
  4. mov eax,0x03
  5. mov ebx,0 ;stdin fd
  6. mov ecx,buf
  7. mov edx,1 ;count
  8. int 0x80
  9. cmp eax,1
  10. jne .getchar_fail
  11. mov eax,[buf]
  12. ret
  13. .getchar_fail:
  14. mov eax,-1
  15. ret
  16. putchar:
  17. mov [buf],eax
  18. mov eax,0x04
  19. mov ebx,1 ;stdout fd
  20. mov ecx,buf
  21. mov edx,1
  22. int 0x80
  23. ret
  24. _start:
  25. call getchar
  26. cmp eax,-1
  27. je .done
  28. call putchar
  29. jmp _start
  30. .done:
  31. mov ebx,eax
  32. mov eax,0x01
  33. int 0x80
  34. buf:
  35. db 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff