;repeat 18 ; show_hex <13,10,'$'>, %-1, %-1, ';' ;end repeat macro show_hex intro, val, count, outro{ local c c = count if c > 0 & c < 17 display intro local v, d v = val while c > 0 c = c - 1 d = v shr (c * 4) and 1111b display d + d/10*7 + '0' if c = 0 display outro else if c mod 4 = 0 display '''' end if end while end if } ;show_float <13,10,'$'>,dw 0.1,';' ;show_float <13,10,'$'>,dd 0.1,';' ;show_float <13,10,'$'>,dq 0.1,';' ;show_float <13,10,'$'>,dt 0.1,';' macro show_float intro, val, outro{ virtual at 0 val local v, s load v word from $ - 2 show_hex , v, 4, '' s = ($ - 2) * 2 align 8 load v qword from 0 show_hex '''', v, s, '' display outro end virtual } ;repeat 64 ; show_frac <13,10>, 1 shl (%-1), ';' ;end repeat macro show_frac intro, val, outro{ display intro, '0.' local a, b a = (val) and $ffff'ffff b = (val) shr 32 repeat 18 a = a * 10 b = b * 10 + a shr 32 display b shr 32 + '0' a = a and $ffff'ffff b = b and $ffff'ffff if % = 18 display outro else if % mod 3 = 0 display '''' end if end repeat } ;LANG equ RUS ;repeat 256 ; display 13,10 ; rcp32 %-1 ;end repeat ; ;LANG equ ENU ;repeat 256 ; display 13,10 ; rcp32 %-1 ;end repeat macro rcp32 val{ local dvs dvs = (val) and $ffff'ffff repeat 1 if dvs < 2 match =RUS, LANG\{display 13, 10, '; не делиться на ', dvs + '0', ' :?'\} match =ENU, LANG\{display 13, 10, '; can you not divide by ', dvs + '0', ' :?'\} break end if _ equ (dvs / . equ ) mod 10 + '0' match =RUS, LANG\{show_hex <13, 10, '; делитель[31..0] = ', dvs / 1'000'000'000 + '0', '''', _ 0'100'000'000 ., _ 0'010'000'000 ., _ 0'001'000'000 ., '''', _ 0'000'100'000 ., _ 0'000'010'000 ., _ 0'000'001'000 ., '''', _ 0'000'000'100 ., _ 0'000'000'010 ., dvs mod 10 + '0', ' = $'>, dvs, 8, ''\} match =ENU, LANG\{show_hex <13, 10, '; divisor[31..0] = ', dvs / 1'000'000'000 + '0', '''', _ 0'100'000'000 ., _ 0'010'000'000 ., _ 0'001'000'000 ., '''', _ 0'000'100'000 ., _ 0'000'010'000 ., _ 0'000'001'000 ., '''', _ 0'000'000'100 ., _ 0'000'000'010 ., dvs mod 10 + '0', ' = $'>, dvs, 8, ''\} restore _, . local dvd, quo, cnt, cnt? dvd = 1 quo = 0 cnt = 0 cnt? = 1 repeat 64 dvd = dvd shl 1 quo = quo shl 1 if dvd < dvs if cnt? = 1 cnt = cnt + 1 end if else cnt? = 0 dvd = dvd - dvs quo = quo + 1 end if end repeat match =RUS, LANG\{show_frac <13, 10, '; 1/делитель[31..0] = '>, quo, ''\} match =ENU, LANG\{show_frac <13, 10, '; 1/divisor[31..0] = '>, quo, ''\} show_hex ' = $0.', quo, 16, '' repeat 31 if dvs = 1 shl % match =RUS, LANG\{display 13, 10, 'код: shr eax,', % / 10 + '0', % mod 10 + '0', ' ; 2 в этой степени и есть делитель'\} match =ENU, LANG\{display 13, 10, 'code: shr eax,', % / 10 + '0', % mod 10 + '0', ' ; divisor is this power of 2'\} dvs = 0 break end if end repeat if dvs = 0 break end if quo = quo shr (32-cnt) + quo shr (32-cnt-1) and 1 match =RUS, LANG\{show_hex <13, 10, 'код: mov edx,$'>, quo, 8, <' ; 1/делитель[31..0], сведенное в 32 бит(shr 32-', (32-cnt) / 10 + '0', (32-cnt) mod 10 + '0', '), округленное', 13, 10, ' mul edx ; множим т.е. делим :)' , 13, 10, ' shr edx,', cnt / 10 + '0', cnt mod 10 + '0', ' ; компенсируем нормализацию'>\} match =ENU, LANG\{show_hex <13, 10, 'code: mov edx,$'>, quo, 8, <' ; 1/divisor[31..0], shortened to 32 bits(shr 32-', (32-cnt) / 10 + '0', (32-cnt) mod 10 + '0', ') and rounded', 13, 10, ' mul edx ; multiply i.e. divide :)', 13, 10, ' shr edx,', cnt / 10 + '0', cnt mod 10 + '0', ' ; compensate normalization'>\} end repeat}