aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / om / omega-reference / vendor / examples / om2_hex_rotr.om
| 1 | note om2_hex_rotr: the first line that is not blank or a note opts in to OM-2: hex literals and rotr |
| 2 | om2 |
| 3 | note ---- OM-2 output helpers: an unsized view parameter takes an array or text of any length |
| 4 | note outv: write all of a to stdout; a short write continues, 0 or an error exits 90 |
| 5 | fn outv a view uchar * to void |
| 6 | e = len a |
| 7 | p = ulong 0 |
| 8 | while lt p e bound 65536 |
| 9 | k = write 1 a p sub e p |
| 10 | if le k 0 |
| 11 | exit 90 |
| 12 | end |
| 13 | p = add p ulong k |
| 14 | end |
| 15 | end |
| 16 | note putu: v in decimal, then a newline |
| 17 | note a part of a global is error 19, so the digits go in a local array |
| 18 | fn putu v ulong to void |
| 19 | b = new uchar 21 0 |
| 20 | i = ulong 20 |
| 21 | put b 20 10 |
| 22 | n = v |
| 23 | while true bound 20 |
| 24 | i = sub i 1 |
| 25 | put b i uchar add rem n 10 48 |
| 26 | n = div n 10 |
| 27 | if eq n 0 |
| 28 | break |
| 29 | end |
| 30 | end |
| 31 | outv part b i sub 21 i |
| 32 | end |
| 33 | fn main to int |
| 34 | x = uint 0xdeadbeef |
| 35 | putu ulong x |
| 36 | putu ulong rotr x 8 |
| 37 | putu 0xffffffffffffffff |
| 38 | putu ulong and x 0xff |
| 39 | ret 0 |
| 40 | end |