# ASMIX Commands and Utilities
# (c) Sergei Zubkov (Cubbi) 1999-2001
#
# dirname.s - return directory portion of a pathname
#
# $Id: dirname.s,v 1.1 2001/10/16 19:23:36 cubbi Exp $

       .toc
        .globl __start
.csect __start[DS]
__start:
        .long .__start,TOC[tc0],0
.csect .text[PR]
.__start:
	cmpwi	3,1
	beq	error_exit
	lwz	16,4(4)	
	mr	19,16
	subi	19,19,1
1:	lbzu	8,1(19)	
	cmpwi	8,0
	bne	1b
	cmpw	16,19
	beq	3f
1:	subi	19,19,1	
	lbz	7,0(19)
	cmpwi	7,0x2F	
	beq	1b	
	addi	19,19,1
	cmpw	16,19
	beq	2f
1:	lbz	7,-1(19)
	cmpw	16,19
	beq	3f
	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	0f
2:	li	7,0x2F
	stb	7,0(19)
	addi	19,19,1
	bl	0f
3:	li	7,0x2E
	stb	7,0(19)
	addi	19,19,1
0:	li	7,10
	stb	7,0(19) 
	sub	5,19,16 
	addi	5,5,1	
	mr	4,16
	li	3,1
	li	0,26 	
	sc
	li	3,0    
real_exit:
        li      0,9
        sc
error_exit:
        li      3,1   
	bl	real_exit
