getput.asm 328 B

1234567891011121314151617181920212223242526272829303132333435
  1. section .bss
  2. buf resq 1
  3. section .text
  4. getchar:
  5. mov rax,0x00
  6. mov rdi,0 ;stdin fd
  7. lea rsi,[buf]
  8. mov rdx,1 ;count
  9. syscall
  10. cmp rax,1
  11. jne .getchar_fail
  12. mov rax,0
  13. mov al,[buf]
  14. ret
  15. .getchar_fail:
  16. mov rax,-1
  17. ret
  18. putchar:
  19. mov [buf],al
  20. mov rax,0x01
  21. mov rdi,1 ;stdout fd
  22. lea rsi,[buf]
  23. mov rdx,1
  24. syscall
  25. ret