; Erdogan TAN 11-01-2011
; Prints command line tail/arguments

CODE_SEG_1	segment para public
		assume  CS:CODE_SEG_1, DS:CODE_SEG_1, SS:CODE_SEG_1, ES:CODE_SEG_1

		org	100h

proc_start	proc	far

start:
                mov si, offset 80h
                lodsb
                cmp al, 0
                ja short convert_byte_to_decimal
                mov si, offset msg_no_arguments
                call proc_printmsg
                jmp short print_next_line

convert_byte_to_decimal:
                push si    
                aam
                mov si, offset TailLength
                cmp ah, 0
                jna short print_tail_length2
print_tail_length1:
                add ah, 30h
                mov byte ptr [SI], ah
                inc si
print_tail_length2:
                add al, 30h                  
                mov byte ptr [SI], al
move_cmd_tail:
                pop si
                mov cx, 78
                mov di, offset Arguments
move_cmd_tail_next:
                lodsb
                cmp al, 20h
                jb short print_cmd_tail_msg
move_cmd_tail_stosb:
                stosb
                loop move_cmd_tail_next

print_cmd_tail_msg:
                mov si,offset CmdTailMsg
                call proc_printmsg
print_next_line:
                mov si, offset NextLine
                call proc_printmsg
exit:
                int 20h

proc_start	endp

proc_bytetodecimal  proc    near

               ; INPUT -> AL: Byte
               ; OUTPUT -> AX = decimal number string 

                aam
                xchg ah, al
                add ax, 3030h
                retn

proc_bytetodecimal        endp

proc_printmsg   proc near

                ; INPUT: DS:SI -> ASCIIZ string 
loc_print:          
		lodsb				
                and al, al            
                je short loc_return 
		mov ah, 0Eh			
                mov bx, 07h             
		int 10h				
			
                jmp short loc_print           
loc_return:
                retn

proc_printmsg   endp

CmdTailMsg:
                db 0Dh,0Ah
                db 'Command Line Tail (at PSP+81h)'
                db 0Dh,0Ah
                db 'Length: '
TailLength:     db 30h, 20h
                db 0Dh,0Ah
                db 'Arguments:'
Arguments:      db 80 dup (0)
 
NextLine:       db 0Dh,0Ah,0h

msg_no_arguments: db "Command has no arguments !", 0

CODE_SEG_1	ends

		end	start
