|
|
ru.algorithms- RU.ALGORITHMS ---------------------------------------------------------------- From : Alex Volkov 2:400/520.55 08 Aug 2003 13:27:56 To : Kirill Akopov Subject : Квадратные корни табличным методом --------------------------------------------------------------------------------
KA> Возникла проблема при программировании на ассемблере - надо создать
KA> процедуру вычисления квадратного корня табличным методом. Вопрос в
KA> том, как лучше составить таблицу и какими критериями руководствоваться
KA> при её составлении?
Hичего что мотороллеровский асм?
Ты извини, я амижник.. Могу накрйняк для спектрумя.
==== Begin of azure_22.txt ====
;-----------------------------------------------------------------------
;
;Calculate SQRT-Table 64k
;
;Basically this routine is integrating 2x via summing up the function
;in intervals of 1 - giving x^2. The result is used in an appropriate way
;to get the reziproc-function, the squareroot.
;
;(a0 holds x^2+offset , d0 holds x)
;
;Done 4.6.97 by Tim Boescke (Azure)
;
;numbers are always rounded off.. (2.7 gets 2)
;
;currently 8 commands - 22 bytes
;
;Trashed registers: d0 d1
; a0
;
;-----------------------------------------------------------------------
section code,code
CalcSQRTtab:
a
lea sqrttab,a0
moveq #0,d0 ;x
.lop2
move d0,d1
add d1,d1
.lop1
move.b d0,(a0)+ ;repeated 2x+1 times.
dbf d1,.lop1
addq.b #1,d0 ;increase and reapeat , until x=0 because
bne.s .lop2 ;of wrapping around.
b
rts
printt "Number of Bytes used:"
printv b-a
section bss,bss
sqrttab:
ds.b 65536
==== End of azure_22.txt ====
==== Begin of dave_22.txt ====
;Daves contribution
; Assemble with Asm-One
Sqr:
LEA sqrttab(PC),A0
;PC relative adressing was not possible in the compo!
MOVEQ #0,D0
1$ MOVE.W D0,D1
ADD.W D0,D1
2$ MOVE.B D0,(A0)+
DBF D1,2$
ADDQ.B #1,D0
BNE.B 1$
RTS
sqrttab:
DX.B 65536
==== End of dave_22.txt ====
==== Begin of dig-it~2.txt ====
;;
;; dig-it @ TBL ...
;;
Section flipp,code
j: lea sqrttab+65536,a0
moveq #-1,d0
move.w #$1ff,d2
.loop1:
move.w d2,d1
.loop2:
move.b d0,-(a0)
subq #1,d1
bne.s .loop2
subq #1,d0
subq #2,d2
bge.s .loop1
end: rts
Section rune,bss
sqrttab: ds.b 65536
sqrttabe:
==== End of dig-it~2.txt ====
==== Begin of grey_22.txt ====
* ****************************************************************** *
* **** Tiny square-root-table generator ****** (c) gREY in 1997 **** *
* ****** For the first official #amycoders coding competition ****** *
* *** Developed in 5 minutes while watching ST:TNG "Half a life" *** *
* ****************************************************************** *
SQRt:
lea sqrttab,a0 * load adress of table
moveq #0,d0 * clear d0 (start vlaue = 0)
.outer:
move.w d0,d1 * save d0
add.w d1,d1 * Multiply d1 with 2
* dbra below saves us from adding 1!
.inner:
move.b d0,(a0)+ * fill sqrttab
dbra d1,.inner * as many times as needed
addq.b #1,d0 * increase d0 by 1
bcc.s .outer * as long as d0 =< 255!
rts
* ****************************************************************** *
==== End of grey_22.txt ====
==== Begin of kruztu~1.txt ====
;Kruzturs version
start: lea sqrttab,a0 ;
moveq #0,d0 ;
moveq #0,d1 ;
.oloop move.l d1,d3 ;
.iloop move.b d0,(a0)+ ;
dbra d3,.iloop ;
addq.w #2,d1 ;
addq.b #1,d0 ;
bcc.s .oloop ;
rts: rts ;
PRINTV rts-start
section sqrtbss,bss
sqrttab: ds.b 65536
==== End of kruztu~1.txt ====
==== Begin of morbid~1.txt ====
; Morbids contribution
lea SqrtTab,a0
moveq #0,d0
loop0 move.w d0,d1
add.w d1,d1
loop1 move.b d0,(a0)+
dbf d1,loop1
addq.b #1,d0
bcc.s loop0
rts
SqrtTab ds.b 65536
==== End of morbid~1.txt ====
==== Begin of psalt^~1.txt ====
; Square root routine by Psalt & Accede
; Made for the #Amycoders sqrt competition.
; Somewhat inaccurate, like sqrt(15)=3
; But fast, and very small...
; bottom and the rts.
; Feel free to use it!
; contact us:
; Accede@hotmail.com
; Psalt@hotmail.com
initsqr lea sqrttab,a0 ;
movem.w (a0),d0/d2/d3 ;
.oloop move.b d2,(a0)+
dbra d0,.oloop
addq.w #2,d3
move.w d3,d0
addq.b #1,d2
.yo bne.s .oloop
rts
end
section data,bss_f
sqrttab ds.b 256*256
==== End of psalt^~1.txt ====
==== Begin of sp_22.txt ====
;sqrt precalc made by Sp^ctz for the #amycoders compo !!
;22 or 20 bytes without rts
section blah,code_f
;bytes
START:
lea Sqrttbl,a0 ;6 ;could become lea Sqrttbl(pc),a0
;if bss section is put right.
;But asm-one doesn't support it
;therefore if someone beats me with
; a (pc) rel lea. I'll be mad :)
moveq.l #0,d1 ;2
.loop
move.l d1,d3 ;2
add.l d3,d3 ;2
.in
move.b d1,(a0)+ ;2
dbf d3,.in ;4
addq.b #1,d1 ;2
bne.b .loop ;2
rts ;2
;--
;24
END:
section output,bss_f
Sqrttbl: ds.b $ffff
==== End of sp_22.txt ====
Вот такие дела, брат..
До свидания.
---
* Origin: #F3 #76 (2:400/520.55)
Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.algorithms/33123f33a734.html, оценка из 5, голосов 10
|