cat64.asm 496 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. global _start
  2. section .data
  3. _start:
  4. call getchar
  5. cmp rax,-1
  6. je .done
  7. call putchar
  8. jmp _start
  9. .done:
  10. mov rdi,rax
  11. mov rax,60
  12. syscall
  13. getchar:
  14. mov rax,0x00
  15. mov rdi,0 ;stdin fd
  16. lea rsi,[rel buf]
  17. mov rdx,1 ;count
  18. syscall
  19. cmp rax,1
  20. jne .getchar_fail
  21. mov rax,0
  22. mov al,[rel buf]
  23. ret
  24. .getchar_fail:
  25. mov rax,-1
  26. ret
  27. putchar:
  28. mov [rel buf],al
  29. mov rax,0x01
  30. mov rdi,1 ;stdout fd
  31. lea rsi,[rel buf]
  32. mov rdx,1
  33. syscall
  34. ret
  35. buf:
  36. db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00