| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- SYS_EXIT equ 1
- SYS_READ equ 3
- SYS_WRITE equ 4
- STDIN equ 0
- STDOUT equ 1
- SYS_IOCTL equ 54
- section .bss
- sz RESB 4 ; 4 byte for window size
- num resb 4 ;4 byte for ascii numbers
- section .data
- ha db 0 ;hundreds
- ta db 0 ;tens
- section .text
- global _start
- _start:
- ; get windwo size
- mov eax, SYS_IOCTL ; syscall ioctl
- mov ebx, STDOUT ; stdout for something?
- mov ecx, 0x5413 ; get windowsize command TIOCGWINSZ
- mov edx, sz ; target struct
- int 0x80 ; call kernel
- ; print rows
- mov ecx, [sz+0] ;rows in ecx
- hundreds:
- cmp ecx, 100 ;check if above 100
- jge inchundred ;jump to increment hundreds if needed
-
- mov eax,[ha] ;hundred count to eax
- add eax, '0' ;convert to ascii
- mov [num+0], eax ;move to first byte of num string
- tens:
- cmp ecx, 10 ;check if above 10
- jge inctens ;jump to increment tens if needed
-
- mov eax,[ta]
- add eax, '0'
- mov [num+1], eax
- mov eax, ecx
- add eax, '0'
- mov [num+2], eax
- mov [num+3], byte 0xa ;linebreak
- mov eax, SYS_WRITE
- mov ebx, STDOUT
- mov ecx, num
- mov edx, 4
- int 0x80
- ; print cols
- mov eax, SYS_WRITE
- mov ebx, STDOUT
- mov ecx, sz+2
- mov edx, 3
- int 0x80
- exit:
- ;exit
- mov eax, 1
- mov ebx, 0
- int 0x80
- inchundred:
- inc byte [ha] ;increment hundreds
- sub ecx, 100
- jmp hundreds
- inctens:
- inc byte [ta] ;increment tens
- sub ecx, 10
- jmp tens
|