dino.asm 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 dw 0 ;hundreds
  12. ta dw 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. ;mov [ha], dword 0x0
  23. ;mov [ta], dword 0x0
  24. ; print rows
  25. hundreds:
  26. mov ecx, [sz+0] ;rows in ecx
  27. cmp ecx, 100 ;check if above 100
  28. jge inchundred ;jump to increment hundreds if needed
  29. mov eax,[ha] ;hundred count to eax
  30. add eax, '0' ;convert to ascii
  31. mov [num+0], eax ;move to first byte of num string
  32. tens:
  33. cmp ecx, 10 ;check if above 10
  34. jge inctens ;jump to increment tens if needed
  35. mov eax,[ta]
  36. add eax, '0'
  37. mov [num+1], eax
  38. mov eax, ecx
  39. add eax, '0'
  40. mov [num+2], eax
  41. mov [num+3], dword 0xa ;linebreak
  42. mov eax, SYS_WRITE
  43. mov ebx, STDOUT
  44. mov ecx, num
  45. mov edx, 4
  46. int 0x80
  47. ; print cols
  48. ;add [sz+2],'0'
  49. mov eax, SYS_WRITE
  50. mov ebx, STDOUT
  51. mov ecx, sz+2
  52. mov edx, 3
  53. int 0x80
  54. exit:
  55. ;exit
  56. mov eax, 1
  57. mov ebx, 0
  58. int 0x80
  59. inchundred:
  60. inc dword [ha] ;increment hundreds
  61. sub ecx, 100
  62. jmp hundreds
  63. inctens:
  64. inc dword [ta] ;increment hundreds
  65. sub ecx, 10
  66. jmp tens