[an error occurred while processing this directive]
|
|
******************************************************************************
* 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