Q: Write an ALP to find the length of a string entered by the user.
Assembler: NASM
Debugger: GDB
OS: Ubuntu 14.04 LTS
Assembler: NASM
Debugger: GDB
OS: Ubuntu 14.04 LTS
Code
;Author:-Abhishek Vilas Munagekar section .data str: db "Enter text for which u wish to find the length!" section .bss len: resb 02 string: resb 100 count: resb 01 global _start section .text _start: mov eax, 04 ;Write syscall to print msg mov ebx, 01 mov ecx, str mov edx, 47 int 80H mov eax, 03 ;Read syscall to accept string mov ebx, 01 mov ecx, string mov edx, 32 int 80H sub al, 01 ;Remove the extra character stored mov esi, len mov byte[count],02 l: rol al, 04H ;Moving MSD to LSD mov bl, al and bl, 0FH ;Masking the higher bits cmp bl, 09 ;Compare with nine JBE m ;If below or equal jump to label m add bl, 07H ;else add correction factor m: add bl, 30H mov [esi], bl ;store ASCII value in esi inc esi Dec byte[count] JNZ l mov esi, len mov eax, 04 ;Write syscall for printing the length mov ebx, 01 mov ecx, esi mov edx, 02 int 80H mov eax, 01 ;Exit System Call mov ebx, 00 int 80H
No comments:
Post a Comment