Fixed HTML style.
[fifth.git] / doc / commands / math&mem.txt
1                         Math, memory & stack manipulation\r
2                         ---------------------------------\r
3 \r
4 \r
5 off             ( n -- ) writes 0 to given address, good for zeroing variable.\r
6                 ex: MyVariable off\r
7 on              ( n -- ) writes -1 (true flag) to given address.\r
8                 ex: MyVariable on\r
9 \r
10 2dup            ( n1 n2 -- n1 n2 n1 n2 )\r
11 2drop           ( n1 n2 -- )\r
12 nip             ( n1 n2 -- n2 )\r
13 neg             ( n1 -- -n1 ) negotiate\r
14 bit@            ( n bit -- result ) return specified bit from n.\r
15                 ex: 38 2 bit@   (result will be 1)\r
16 to32bit         ( n1 n2 n3 n4 -- n32 ) treat 4 last stack elements as bytes\r
17                 and unite them into 32 bit dword. Most significant byte\r
18                 on top.\r
19                 ex: 12 76 23 11 to32bit   result: 186076172\r
20 \r
21 to8bit          ( n32 -- n1 n2 n3 n4 ) break 32 bit number into 4 bytes.\r
22                 Useful if you need to send 32 bit numbers thru 8 bit COM\r
23                 port.\r
24                 ex: 186076172 to8bit   result: 12 76 23 11\r
25 \r
26 mod             ( n1 n2 -- reminder ) divide n1 by n2 and returns reminder.\r
27                 ex: 12 5 mod   result: 2\r
28 \r
29 bound           ( low n high -- n ) check if n is in given bounds,\r
30                 if not then incarease/decarease it to match bounds.\r
31                 ex: 5 80 15 bound    result: 15\r
32                     5 10 15 bound    result: 10\r
33                     5 -10 15 bound   result: 5\r
34 \r
35 bound?          ( low n high -- result ) returns true if n is in the\r
36                 given bounds.\r
37 \r
38 tab             ( col -- spaces) calculate amount of spaces to add\r
39                 ta reach next tabulation from given column.\r
40 \r
41 count           ( addr -- addr+1 n )\r
42                 Useful for returning bytes from constantly incareasing\r
43                 address. Module "type" is nice example.\r
44 \r
45 c,              ( n -- )\r
46                 store one byte at memory specified by "h". And incarease\r
47                 "h" by 1.\r
48 \r
49 ,               ( n -- )\r
50                 store 32 bit number at memory specified by "h". And\r
51                 incarease "h" by 4.\r
52 \r
53 cmove           ( addr1 addr2 n -- )\r
54                 copy "n" amount of bytes from memory at "addr1" to memory\r
55                 at "addr2".\r
56 \r
57 rnd             ( limit -- result )\r
58                 generates random number in range 0 to "limit"-1.\r
59 \r
60 abs             ( n -- |n| )\r
61                 returns absolute value of "n"\r