[an error occurred while processing this directive]
|
******************************************************************************
* IDIV.ASM v3.83
* Copyright (c) 1993-2002 Texas Instruments Incorporated
******************************************************************************
.mmregs
.c_mode
******************************************************************************
* This module contains the functions for signed 16-bit divide and modulus.
* This stack map and these defines apply to all the routines in this module.
*
* SYMBOL DEFINITIONS:
*
* Q - Dividend on input, quotient on output
* D - Divisor
*
******************************************************************************
; STACK MAP
;
; +-----------+ <-- SP (after FRAME instruction)
; | SIGN | 0
; +-----------+
; | save BG | 1
; +-----------+
; | save BHI | 2
; +-----------+
; | save BLO | 3
; +-----------+ <-- SP (on entry)
; | ret addr | 4
; +-----------+
; | D | 5
; +-----------+
; | |
;
; Q is in accumulator A
FSIZE .set 2 ; frame size
******************************************************************************
* If using extended addressing the return address occupies 2 words on stack
******************************************************************************
.if __far_mode
offset .set 1
.else
offset .set 0
.endif
.asg *SP(0),SIGN ;sign of result
.asg *SP(6 + (2*offset)),D ; divisor
.global _freti549
.page
******************************************************************************
* 16-BIT SIGNED DIVIDE, CALCULATE Q / D AND RETURN IN ACCUMULATOR "A"
******************************************************************************
.global I$$DIV
I$$DIV:
******************************************************************************
* SAVE OFF REGISTERS, ALLOCATE FRAME
******************************************************************************
NOP ; make sure read new value of B
PSHM BL
PSHM BH ; save off B
PSHM BG
SSBX SXM ; turn on SXM mode
FRAME #-FSIZE - offset; allocate space
******************************************************************************
* DETERMINE SIGN OF RESULT, TAKE ABSOLUTE VALUE OF OPERANDS
******************************************************************************
LD *(AL),A ; sign extend Q
LD D,B ; load D
XOR A,B
STH B,SIGN ; determine sign of result
ABS A ; take absolute value of Q
LD D,B ; load D again
ABS B ; take absolute value of D
STL B,D ; save off
******************************************************************************
* PERFORM DIVIDE
******************************************************************************
RSBX SXM ; turn off SXM mode
RPT #15 ; repeat 16 times
SUBC D,A ; divide step
******************************************************************************
* QUOTIENT IS IN ALO, REMAINDER IS IN AHI
******************************************************************************
BITF SIGN,08000h ; check MSB(sign)
BC RET1,NTC ; if (1)
NEG A ; negate Q
RET1:
FRAME #FSIZE + offset; deallocate frame
POPM BG
POPM BH ; restore B
POPM BL
.if __far_mode ; use far return for C548 in far mode
.if __no_fret
FB _freti549
.else
FRET ; return
.endif
.else
RET
.endif
.page
E-mail: info@telesys.ru