// This may look like C code, but it is really -*- Asm -*-
/*
 *  smoke16/src16/hextest.s - Prints some hexadecimal numbers.
 *  $Revision: 1.13 $
 *  Copyright 1997, 1999, 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>
	.rdata
trans:	.string "0123456789abcdef"
size:	.word 6
data:	.word 0xDEAD, 0xBEEF
	.word 61455 /* == 0xF00F */
	.word 0xC7C8
	.word -0x113 /* == 0xFEED */
	.word ~0b0100010101000001 /* == 0xBABE */

	.text
	.align 1
	FUNCTION(_main)
	push %t2
	push %t1
	push %t0
	mov trans, %t0
	mov [size], %t1
	mov data, %t2
loop:	cmpl %t1, %0
	be done
	mov [%t2], %a0		// current word
	sethi '\n', %a1		// end of string... higher on stack.
	push %a1
	sll %a0, 8, %a2		// extract third nybble
	srl 12, %a2
	add %t0, %a2
	movb [%a2], %a3		// load hex character
	sll 8, %a3
	sll %a0, 12, %a2	// extract fourth nybble
	srl 12, %a2
	add %t0, %a2
	movb [%a2], %a3		// load hex character
	push %a3
	srl %a0, 12, %a2	// extract first nybble
	add %t0, %a2
	movb [%a2], %a3		// load hex character
	sll 8, %a3
	sll %a0, 4, %a2		// extract second nybble
	srl 12, %a2
	add %t0, %a2
	movb [%a2], %a3		// load hex character
	push %a3
	// start of string.. lower on stack
	mov '0x', %a1
	mov %sp, %a0
	push %a1
	mov [_stdout], %a1
	call _fputs
	add 8, %sp
	add 2, %t2
	sub 1, %t1
	b loop
done:	mov %0, %a0
	pop %t0
	pop %t1
	pop %t2
	RET
