! ASMIX Commands and Utilities
! (c) Sergei Zubkov (Cubbi) 1999-2001
!
! rmdir.s - Remove empty directories
!
! $Id: rmdir.s,v 1.1 2001/10/15 17:24:34 cubbi Exp $

        .seg "text"
        .proc 04
        .global start
start:
	ld	[%sp+0x40],%o5	
	mov	0x44,%i0
	mov	0x2D,%i1
0:	cmp	%o5,1
	beq	error_exit
	 mov	3,%o0
	dec	%o5
	add	%i0,4,%i0
	ld	[%sp+%i0],%o1
	ldub	[%o1],%l0
	cmp	%l0,%i1	
	bne	3f
	 nop
	ldub	[%o1+1],%l0
	cmp	%l0,0x2D
	bne	1f
	 nop
	cmp	%o5,1
	beq	error_exit
	 mov	3,%o0
	add	%i0,4,%i0
	b	3f	
	 ld	[%sp+%i0],%o1
1:	cmp	%l0,0x70
	bne	2f
	 nop
	mov	1,%l7	
	b	0b
	 nop
2:	b	error_exit
	 mov	2,%o0
3:	mov	%o1,%l1	
1:	ldub	[%l1],%l5
	inc	%l1
	cmp	%l5,0
	bne	1b
	 nop
	dec	%l1
0:	mov	0x0,%o3	
	stb	%o3,[%l1]
	mov	%o1,%o0
	mov	137,%g1	
	ta	%g0
	cmp	%o0,0
	bne	error_exit
	 mov	1,%o0
	cmp	%l7,1	
	bne	2f
	 nop
	inc     %l1
1:      dec     %l1
        cmp     %l1,%o1       
        beq     2f
         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     2f
         nop
        ldub    [%l1-1],%o3
        cmp     %o3,0x2f 
        beq     1b
         nop
	b	0b
	 nop
2:	clr	%o0
error_exit:
	mov	1,%g1
	ta	%g0
