// This may look like C code, but it is really -*- Asm -*-
/*
 *  smoke16/src16/fprintx.s - Part of a sub-minimal SMOKE-16 I/O library.
 *  $Revision: 1.2 $
 *  Copyright 2000, Benjamin Sittler
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <smoke16/asm.h>

	.rodata
hex:	.string "0123456789abcdef"

	.text
	.align 1
// int printx(int d)
	.global _printx
_printx:
	mov [_stdout], %a1
// int fprintx(int d, FILE *stream)
	FUNCTION(_fprintx)
	push %t0 // d
	push %t1 // stream
	push %t2 // count
	mov %a0, %t0
	mov %a1, %t1
	mov %0, %t2
	mov %t0, %a0
	srl %t0, 4, %a0
	cmpl %0, %a0
	be fprintx1
	mov %t1, %a1
	call _fprintx
	add %a0, %t2, %t2
fprintx1:
	sll %t0, 12, %t0
	srl %t0, 12, %t0
	mov hex, %a0
	add %t0, %a0, %a1
	mov %0, %a0
	movb [%a1], %a0
	mov %t1, %a1
	call _fputc
	cmp %a0, %0
	bl fprintx2
	add 1, %t2
fprintx2:
	mov %t2, %a0
	pop %t2
	pop %t1
	pop %t0
	RET
