// This may look like C code, but it is really -*- Asm -*-
/*
 *  smoke16/src16/mul.s - Tests the _umul and _udiv functions.
 *  $Revision: 1.16 $
 *  Copyright 1997, 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>
#include <smoke16/syscall.h>

	.data
LCerror:.zstring "X: mul/div test failed.\n"

	.rdata
LCok:	.zstring "All tests succeeded.\n"

	.text
	.align 1
	FUNCTION(_main)
	push %t0
	mov %0, %a0
	mov %0, %a1
	movb 'A', %t0
	call __umul
	cmpl %a0, %0
	bne error
	cmpl %a1, %0
	bne error
	mov %0, %a1
	mov 1, %a0
	movb 'B', %t0
	call __umul
	cmpl %a0, %0
	bne error
	cmpl %a1, %0
	bne error
	mov 10, %a0
	mov 10, %a1
	movb 'C', %t0
	call __umul
	mov (10*10)>>16, %a2
	mov 10*10, %a3
	cmpl %a0, %a2
	bne error
	cmpl %a1, %a3
	bne error
	mov 666, %a0
	mov 777, %a1
	movb 'D', %t0
	call __umul
	mov %hi16(666*777), %a2
	mov %lo16(666*777), %a3
	cmpl %a0, %a2
	bne error
	cmpl %a1, %a3
	bne error
	mov 50, %a0
	mov 10, %a1
	movb 'E', %t0
	call __udiv
	mov 50/10, %a1
	cmpl %a0, %a1
	bne error
	mov 31415, %a0
	mov 2345, %a1
	movb 'F', %t0
	call __udiv
	mov 31415/2345, %a1
	cmpl %a0, %a1
	bne error
	mov 10, %a0
	mov 50, %a1
	movb 'G', %t0
	call __udiv
	mov 10/50, %a1
	cmpl %a0, %a1
	bne error
	mov LCok, %a0
	mov [_stdout], %a1
	call _fputs
	mov %0, %a0
	b done
error:	int SMOKE16__SYS_REGDUMP
	mov LCerror, %a0
	movb %t0, [%a0]
	mov [_stderr], %a1
	call _fputs
	mov 1, %a0
done:	pop %t0
	RET
