# ASMIX Commands and Utilities
# (c) Sergei Zubkov (Cubbi) 1999-2001
#
# rmdir.s - remove empty directories
#
# $Id: rmdir.s,v 1.1 2001/10/16 19:23:31 cubbi Exp $

        .globl _start
_start:
	lwz	3,0(1)
	li	10,4		
0:	cmpwi	3,1		
	beq	error_noop
	subi	3,3,1
	addi	10,10,4		
	lwzx	16,10,1		
	lbz	7,0(16)		
	cmpwi	7,0x2D		
	bne	2f		
	lbz	7,1(16)		
	cmpwi	7,0x2D		
	bne	1f		
	cmpwi	3,1		
	beq	error_noop	
	addi	10,10,4		
	lwzx	16,10,1		
	bl	2f
1:	cmpwi	7,0x70		
	bne	error_unk
	li	21,1		
	bl	0b
2:	mr	19,16
	subi	19,19,1
1:	lbzu	8,1(19)		
	cmpwi	8,0
	bne	1b		
0:	li	7,0	
	stb	7,0(19) 
	mr	3,16
	li	0,40 	
	sc
	cmpwi	3,0
	bne	error_exit
	cmpwi	21,1		
	bne	0f		
	cmpw	16,19
	beq	0f
1:	subi	19,19,1	
	lbz	7,0(19)
	cmpwi	7,0x2F		
	beq	1b		
	addi	19,19,1
	cmpw	16,19
	beq	0f
1:	lbz	7,-1(19)
	cmpw	16,19		
	beq	0f
	subi	19,19,1
	cmpwi	7,0x2F		
	bne	1b		
	addi	19,19,1
1:	subi	19,19,1		
	lbz	7,0(19)
	cmpwi	7,0x2F		
	beq	1b		
	addi	19,19,1
	cmpw	16,19
	bne	0b
0:	li	3,0    
real_exit:
        li      0,1
        sc
error_exit:
        li      3,1   
	bl	real_exit
error_unk:
	li	3,2
	bl	real_exit
error_noop:
	li	3,3
	bl	real_exit
