dino.asm 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. SYS_EXIT equ 1
  2. SYS_READ equ 3
  3. SYS_WRITE equ 4
  4. STDIN equ 0
  5. STDOUT equ 1
  6. SYS_IOCTL equ 54
  7. section .bss
  8. sz RESB 4 ; 4 byte for window size
  9. num resb 4 ;4 byte for ascii numbers
  10. section .data
  11. ha db 0 ;hundreds
  12. ta db 0 ;tens
  13. section .text
  14. global _start
  15. _start:
  16. ; get windwo size
  17. mov eax, SYS_IOCTL ; syscall ioctl
  18. mov ebx, STDOUT ; stdout for something?
  19. mov ecx, 0x5413 ; get windowsize command TIOCGWINSZ
  20. mov edx, sz ; target struct
  21. int 0x80 ; call kernel
  22. ; print rows
  23. mov ecx, [sz+0] ;rows in ecx
  24. hundreds:
  25. cmp ecx, 100 ;check if above 100
  26. jge inchundred ;jump to increment hundreds if needed
  27. mov eax,[ha] ;hundred count to eax
  28. add eax, '0' ;convert to ascii
  29. mov [num+0], eax ;move to first byte of num string
  30. tens:
  31. cmp ecx, 10 ;check if above 10
  32. jge inctens ;jump to increment tens if needed
  33. mov eax,[ta]
  34. add eax, '0'
  35. mov [num+1], eax
  36. mov eax, ecx
  37. add eax, '0'
  38. mov [num+2], eax
  39. mov [num+3], byte 0xa ;linebreak
  40. mov eax, SYS_WRITE
  41. mov ebx, STDOUT
  42. mov ecx, num
  43. mov edx, 4
  44. int 0x80
  45. ; print cols
  46. mov eax, SYS_WRITE
  47. mov ebx, STDOUT
  48. mov ecx, sz+2
  49. mov edx, 3
  50. int 0x80
  51. exit:
  52. ;exit
  53. mov eax, 1
  54. mov ebx, 0
  55. int 0x80
  56. inchundred:
  57. inc byte [ha] ;increment hundreds
  58. sub ecx, 100
  59. jmp hundreds
  60. inctens:
  61. inc byte [ta] ;increment tens
  62. sub ecx, 10
  63. jmp tens