Demo or Die #02
31 июля 1999 |
|
Demo-Building - Generator table of squares.
__________________________________________ (C) ra! D Generator table of squares The operation of this generator is based on very interesting dependence Mathematically, it looks like this: k k-1 X = X + Nk, k k-1 where X and X - the squares of consecutive numbers on this and previous iterations duschih; k-iteration number, respectively; Nk - the number of a number of positive odd numbers; I think that is a small table, help to understand this algorithm. - X 1 2 3 4 ... - X ^ 2 1 4 9 16 ... N 3 5 7 - Some comments on this Example: 1) This example creates a table squares of numbers from 0 to 255; 2) In the table, the squares of numbers are top-down, ie first is the square of 255, then the square 254 and so on (This is due to specific structures stack). The disadvantage of this is difficult to call, say so it's just a side effect, which very easily solved by a sufficiently inverted number whose square is like this: LD A, NUM, , Whose square ; To find. CPL LD BC, TABL LD H, 0 LD L, A ADD HL, HL ADD HL, BC LD E, (HL) INC HL LD D, (HL) 3) Do not forget at the end of the program redirect the stack. ;***************************************** ; * GEN_TABL_X ^ 2 * ; * (C) 1999 idea and code by ra! D * ; * Code len: 16b * ;***************************************** LD SP, TABL +512 LD HL, 1 LD D, H LD E, L LD B, # FF LP1 PUSH HL INC DE INC DE ADD HL, DE DJNZ LP1 ; LD SP, nnnn ; RET TABL DEFS 512 P.S. Incidentally, I have not met any a mathematical reference, description this method. __________________________________________
Other articles:
Similar articles:
В этот день... 21 November