| ??? 10/24/02 11:36 Read: times |
#31349 - long number arithmetics |
Very often assembler programmers dont know, how to deal with big values or with values with decimal point.
Since the assembler support not the IEEE floating point format its very difficult to use a floating point library. The solution, you can expand the existing algorithm from 16 bit to 24 bit or whatever you want. After you understand the algorithm for 16 bit numbers, then it was easy to expand it to every other size. Since the algorithm was the same it can be done very comfortable on using macros. Following an example for the division: Simple change the definitions "a_size" and "b_size" to the size of the divident and the divisor in bytes, which you need. The macros can be expanded with the Keil assembler. But it should be possible to do some small changes to use the free Metalink assembler. <pre> ;************************************************************************/ ;* */ ;* Scalable Mathematics: Division */ ;* */ ;* Author: Peter Dannegger */ ;* danni@specs.de */ ;* */ ;************************************************************************/ $nosb a_size equ 5 ;divident: 5 bytes b_size equ 2 ;divisor: 2 bytes ra0 equ r0 ;divident ra1 equ r1 ra2 equ r2 ra3 equ r3 ra4 equ r4 rb0 equ 30h ;divisor rb1 equ 31h rr0 equ r5 ;remainder rr1 equ r6 ri0 equ r7 ;loop counter $sa noli _mset macro a0, a1, a2 a0 set a1&a2 endm $rs ;------------------------------------------------------------------------- scaldiv: clr a $sa noli _count set 0 rept b_size _mset _regr, rr, %_count _count set _count + 1 $rs mov _regr, a ;clear remainder $sa noli endm $rs mov ri0, #a_size * 8 _scd1: clr c $sa noli _count set 0 rept a_size _mset _rega, ra, %_count _count set _count + 1 $rs mov a, _rega rlc a ;shift divident mov _rega, a $sa noli endm _count set 0 rept b_size _mset _regr, rr, %_count _count set _count + 1 $rs mov a, _regr rlc a ;shift remainder mov _regr, a $sa noli endm if a_size <> b_size $rs jbc cy, _scd2 $sa noli endif _count set 0 rept b_size _mset _regr, rr, %_count _mset _regb, rb, %_count _count set _count + 1 $rs mov a, _regr subb a, _regb ;test subtraction $sa noli endm $rs jc _scd3 _scd2: $sa noli _count set 0 rept b_size _mset _regr, rr, %_count _mset _regb, rb, %_count _count set _count + 1 $rs mov a, _regr subb a, _regb ;subtract mov _regr, a $sa noli endm $rs inc ra0 ;set result bit _scd3: djnz ri0, _scd1 ret ;------------------------------------------------------------------------- end Peter |
| Topic | Author | Date |
| long number arithmetics | 01/01/70 00:00 | |
| RE: long number arithmetics | 01/01/70 00:00 | |
| RE: long number arithmetics | 01/01/70 00:00 | |
| RE: Boolean number? | 01/01/70 00:00 | |
| RE: Floating Point: Peter | 01/01/70 00:00 | |
| RE: Trig functions....CORDIC? | 01/01/70 00:00 | |
RE: Floating Point: Peter | 01/01/70 00:00 |



