! ASMIX Commands and Utilities
! (c) Sergei Zubkov (Cubbi) 1999-2001
!
! dirname.s - return the directory portion of pathname
!
! $Id: dirname.s,v 1.1 2001/10/11 19:38:54 cubbi Exp $

	.section ".text"
	.globl _start
_start:
	ld	[%sp+0x40],%o5
	cmp	%o5,1
	beq	error_exit
	nop
	ld	[%sp+0x48],%o1
	mov	%o1,%l1
1:	ldub	[%l1],%l5
	inc	%l1
	cmp	%l5,0
	bne	1b
	nop
	sub	%l1,1,%o3
	cmp	%o3,%o1
	beq	2f
	nop
1:      dec     %l1
        cmp     %l1,%o1 
        beq     3f
        nop
        ldub    [%l1-1],%o3
        cmp     %o3,0x2f 
        beq     1b
        nop
1:      dec     %l1
        cmp     %l1,%o1 
        beq     2f
        nop
        ldub    [%l1-1],%o3
        cmp     %o3,0x2f 
        bne     1b
        nop
1:      dec     %l1
        cmp     %l1,%o1 
        beq     3f
        nop
        ldub    [%l1-1],%o3
        cmp     %o3,0x2f 
        beq     1b
        nop
	ba	_write
	nop
2:	mov     0x2e,%o3
	ba	1f
	nop
3:	mov	0x2f,%o3
1:	stub    %o3,[%l1]
        inc     %l1
end_parse:
_write:
	mov	0xA,%o3
	stub	%o3,[%l1]
	inc	%l1
	sub	%l1,%o1,%o2
	mov	1,%o0
	mov	4,%g1	
	ta	8
exit:
	clr	%o0
	mov	1,%g1	
	ta	8
error_exit:
	mov	1,%o0
	mov	1,%g1
	ta	8
