numtoasc.asm 1.3 KB

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