Write an ALP to read command line arguments passed to a program


section .data
nomsgdb 10,"No.of arguments:"
nomsg_len: equ $-nomsg
argmsgdb 10,10,"Arguments are::",10
argmsg_len: equ $-argmsg
nwlinedb 10
section .bss
argresd 1
argcntresd 1
%macro dispmsg 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 0x80
%endmacro
section .text
global _start
start:
dispmsgnomsg,nomsg_len
pop ecx
mov [argcnt],ecx
add ecx,'0'
cmp ecx,39h
jbe skip
add ecx,07
skip: mov [arg],ecx
dispmsg arg,1
dispmsgargmsg,argmsg_len
next: pop ecx
mov edx,00
up: cmp byte [ecx+edx],0
jz l1
incedx
jmp up
l1: mov eax,4
mov ebx,1
int 0x80
dispmsg nwline,1
decdword [argcnt]
jnz next
exit: mov eax,1
mov ebx,0
int 0x80

OUTPUT
;[mahendra@(none) alp]$ nasm -f elf32 msmalb07.asm
;[mahendra@(none) alp]$ ld -o msmalb07 msmalb07.o -m elf_i386
;[mahendra@(none) alp]$ ./msmalb07 SITS Narhe Pune Maharashtra 411041

;No.of arguments:6

;Arguments are::
;./msmalb07
;SITS
;Narhe
;Pune
;Maharashtra
;411041
;[mahendra@(none) alp]$

Comments