| ??? 02/11/99 21:31 Read: times |
#213 - RE: Arithmetic problem |
Mike,
Here is the code to do that- please modify to your needs. Regards, Shuba ;***************************************************************************; ; ; FUNCTION: d16by8 ; ; DESCRIPTION: Calculates QUOTIENT = DIVIDEND/DIVISOR ; REMAINDER = DIVIDEND - QUOTIENT * DIVISOR ; ; INPUTS: 16-bit dividend and an 8-bit divisor. ; DIVIDEND: 2 bytes in r2(lo),r3(hi) ; DIVISOR : 1 byte in r0 ; ; OUTPUTS: 16-bit quotient and an 8-bit remainder. Inputs and ; outputs are unsigned integers. ; QUOTIENT: 2 bytes in r2 (lo),r3(hi) ; REMAINDER: 1 byte in r0 ; ; ; VARIABLES AND REGISTERS MODIFIED: ; tempa,tempb,tempc, (temporary vars) ACC, B, PSW, R4, R5, R6, R7 ; ; ERROR EXIT: Exit with OV = 1 indicates DIVISOR = 0. ; ; ; NOTE: Downloaded from www.dcity.org ; ;***************************************************************************; public d16by8 d16by8: clr a mov tempa,r0 cjne a,tempa,ok ;cjne a,divisor,ok divide_by_zero: setb ov ret ok: mov tempa,a ;mov quotient,a mov r4,#8 mov r5,ar2 ;mov r5,dividend mov r6,ar3 ;mov r6,dividend+1 mov r7,#00h mov a,r6 mov b,r0 ;mov b,divisor div ab mov tempb,a ;mov quotient+1,a mov r6,b times_two: mov a,r5 rlc a mov r5,a mov a,r6 rlc a mov r6,a mov a,r7 rlc a mov r7,a compare: cjne a,#0,done mov a,r6 mov tempc,r0 cjne a,tempc,done ;cjne a,divisor,done cjne r5,#0,done done: cpl c build_quotient: mov a,tempa ;mov a,quotient rlc a mov tempa,a ;mov quotient,a jnb acc.0,loop subtract: mov a,r6 subb a,r0 ;subb a,divisor mov r6,a mov a,r7 subb a,#0 mov r7,a loop: djnz r4,times_two mov a,r0 ;mov a,divisor mov b,tempa ;mov b,quotient mul ab mov b,a mov a,r2 ;mov a,dividend subb a,b mov tempc,a ;mov remainder,a clr ov mov r2,tempa mov r3,tempb mov r0,tempc ret |
| Topic | Author | Date |
| Arithmetic problem | 01/01/70 00:00 | |
RE: Arithmetic problem | 01/01/70 00:00 |



