Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Well, I have some problems when I try to input more than 9 letters, not because the length of input,
- ;but because it is a little complicated to save number bigger than 9, so, for now,
- ;it is what it is, and soon I will share more codes
- ;Have a nice day ;)
- %assign SYS_READ 3
- %assign SYS_WRITE 4
- %assign STDIN 0
- %assign STDOUT 1
- section .data
- msg1 db "The length is:",0xA
- len_msg1 equ $-msg1
- segment .bss
- text resb 8 ;reserve 8bits for letter (max 8 letters)
- textLength resb 1 ;reserve 1bit to save the length
- section .text
- global _start
- _getLength:
- pushad ;save the registers
- xor esi, esi ;esi = 0
- mov ecx, 0 ;ecx = 0
- myloop:
- mov eax, [text + esi] ;read letter in specific position
- inc esi ;increment the position
- add ecx, 1 ;add 1
- cmp eax, 0 ;verify if is the end of string
- jne myloop ;jne (jump if not equal) if is not the end of string, return to loop
- sub ecx, 2 ;it count's the end of string and stop in the next loop, so, it need to subtract 2
- add ecx, '0' ;convert from decimal to ASCII
- mov [textLength], ecx ;save length in variable
- popad ;return the saved values to registers
- ret
- _start:
- mov eax, SYS_READ ;sys_read
- mov ebx, STDIN ;stdit
- mov ecx, text ;variable to save the input
- mov edx, 8 ;max length of input
- int 0x80
- call _getLength
- mov eax, SYS_WRITE ;sys_write
- mov ebx, STDOUT ;stdout
- mov ecx, msg1 ;variable to output
- mov edx, len_msg1 ;max length of output
- int 0x80
- mov eax, SYS_WRITE
- mov ebx, STDOUT
- mov ecx, textLength
- mov edx, 1
- int 0x80
- mov eax, 1 ;system call number (sys_exit)
- xor ebx, ebx ;ebx = 0 (success)
- int 0x80 ;call kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement