// K1-16/16 Microcode // 2015-12-22 16:10:39 : abs__5int32_6uint32 ( int32 -- uint32 ) Millicoded // Size: 20 microcodes mc Lvar+255 mc Peek2 mc Int8+0 mc Int8+0 mc GeL mc BraIf0+3 mc Lvar+255 mc Peek2 mc Bra+3 mc Lvar+255 mc Peek2 mc NegL mc ToR2 mc MDrop0-2 mc FromR2 mc Ret : min__6uint32_6uint32_6uint32 ( uint32, uint32 -- uint32 ) Millicoded // Size: 18 microcodes mc Lvar+253 mc Peek2 mc Lvar+253 mc Peek2 mc LtUL mc BraIf0+3 mc Lvar+253 mc Peek2 mc Bra+2 mc Lvar+255 mc Peek2 mc Lvar+251 mc Poke2 mc MDrop0_Next-2 : random__6uint32 ( -- uint32 ) Millicoded mc random__6uint16 mc random__6uint16 mc Next : hexstr__6uint32_6uint16_8ucs2charAE ( uint32, uint16 -- ucs2str ) Millicoded // Size: 27 microcodes mc Dup mc Subq+1 mc Int8+7 mc And mc Addq+1 mc Nip mc Dup mc Int8+4 mc Ugt mc BraIf0+9 mc Lget+254 mc Lget+255 mc Subq+4 mc hexstr__6uint16_6uint16_8ucs2charAE mc Lget+254 mc Int8+4 mc hexstr__6uint16_6uint16_8ucs2charAE mc CatStrStr mc Bra+3 mc Lget+255 mc Lget+255 mc hexstr__6uint16_6uint16_8ucs2charAE mc MNip0_Next-3 : numstr__5int32_8ucs2charAE ( int32 -- ucs2str ) Millicoded // Size: 21 microcodes mc Lget+255 mc Int8+0 mc Lt mc BraIf0+9 mc Istr+1 dm '-' ld cmd,atmp mc Lvar+254 mc Peek2 mc NegL mc numstr__6uint32_8ucs2charAE mc CatStrStr mc Bra+3 mc Lvar+255 mc Peek2 mc numstr__6uint32_8ucs2charAE mc MNip0_Next-2 : numstr__6uint32_8ucs2charAE ( uint32 -- ucs2str ) Millicoded // Size: 132 microcodes mc Lget+255 mc BraIf0+121 mc Int8+0 mc Int8+0 mc Int8+0 mc Int8+0 mc Lvar+251 mc Peek2 mc Int8+154 mc Int16+59 mc Int8+0 mc Int16+202 mc GeUL mc BraIf0+33 mc Int8+49 mc Lset+255 mc Int8+154 mc Int16+59 mc Int8+0 mc Int16+202 mc Lvar+249 mc SubPokeL mc Lvar+251 mc Peek2 mc Int8+154 mc Int16+59 mc Int8+0 mc Int16+202 mc GeUL mc BraIf0+4 mc Int8+1 mc Lvar+254 mc AddPoke mc Bra-18 mc Int8+10 mc Lset+253 mc Int8+10 mc Alloc mc Lvar+255 mc SwapWithVar mc DropStr mc Lget+255 mc Lget+255 mc Lvar+252 mc Peekpp mc AtIndexPoke mc Bra+29 mc Int8+9 mc Lset+253 mc Lvar+251 mc Peek2 mc Int8+245 mc Int16+5 mc Int8+0 mc Int16+225 mc LtUL mc BraIf0+14 mc Int8+1 mc Lvar+252 mc SubPoke mc Lvar+251 mc Peek2 mc Lvar+249 mc AddPokeL mc Lvar+251 mc Peek2 mc Int8+2 mc SlL mc Lvar+249 mc AddPokeL mc Bra-22 mc Lget+253 mc Alloc mc Lvar+255 mc SwapWithVar mc DropStr mc Lget+254 mc Lget+252 mc Ult mc BraIf0+36 mc Int8+48 mc Lset+255 mc Lvar+251 mc Peek2 mc Int8+245 mc Int16+5 mc Int8+0 mc Int16+225 mc GeUL mc BraIf0+10 mc Int8+1 mc Lvar+254 mc AddPoke mc Int8+245 mc Int16+5 mc Int8+0 mc Int16+225 mc Lvar+249 mc SubPokeL mc Bra-18 mc Lget+255 mc Lget+255 mc Lvar+252 mc Peekpp mc AtIndexPoke mc Lvar+251 mc Peek2 mc Lvar+249 mc AddPokeL mc Lvar+251 mc Peek2 mc Int8+2 mc SlL mc Lvar+249 mc AddPokeL mc Bra-40 mc Dup mc Retain mc ToR mc DropStr mc MDrop0-3 mc FromR mc Bra+4 mc Lvar+255 mc Addq+1 mc Peek mc numstr__6uint16_8ucs2charAE mc MNip0_Next-2 : new__5int16_5int32 ( int16 -- int32 ) tst alu psh ival :bit15 if 0 dw 0 else dw $ffff then next_m : new__6uint16_6uint32 ( uint16 -- uint32 ) psh 0 next_m : msbit__5int32_5int16 ( int32 -- int16 ) // next_m n.h ? msbit(n.h)+16 : msbit(n.l) tst (hp) // delay tst (hp) pop dtmp :z if 1 ldn alu ld msbit,alu ld alu,msbit next_m else ldn dtmp ld msbit,alu ld alu,msbit or 16 next_m then : mulu_16_32__6uint16_6uint16_6uint32 ( uint16, uint16 -- uint32 ) // ulong r,c // if a>b swap(a,b) // sort: a < b // c.l=b // do{ // while a // if a&1 r += c // a >>= 1 // c <<= 1 // } // next_m r ld d0,(hp) // d0 = a; alu = b cmp_nc d0 // b-a-1 if cy // cy => !cy => alu≥d0+1 => swap ld d0,alu // d0 = alu ld alu,(hp) // alu = d0 then // alu = a ≤ d0 = b = c.l ld sl,0,nc // sl,d0 = c ld d1,sl ld d2,sl // d2.d1 = r ld sr,alu,nc // sr = a ld cmd,ival :bit0 if 1 dw a :bit15 else dw na :bit15 then do // while a != 0 ld sr,sr,nc // next bit if bit0 // if a&1 then r += c a ld alu,d0 add d1 ld d1,alu :cy if 1 ld alu,sl add_c d2 else ld alu,sl add d2 then ld d2,alu then // c <<= 1 na ld alu,d0 // alu = c.l add alu // nodelay ld d0,alu : cy // c.l <<= 1 if 1 ld sl,sl,cy // c.h <<= 1 + cy else ld sl,sl,nc then tst sr // a == 0? while !z // no => loop // result = d2.d1 ld (hp),d2 ld alu,d1 next_m : mul10__6uint32_6uint32 ( uint32 -- uint32 ) add alu // nodelay if cy ld sl,(hp),cy else ld sl,(hp),nc // sl.alu = x*2 then ld d0,alu ld d1,sl // d1.d0 = x*2 add alu // nodelay if cy ld sl,sl,cy else ld sl,sl,nc // sl.alu = x*4 then add alu // nodelay if cy ld sl,sl,cy else ld sl,sl,nc // sl.alu = x*8 then add d0 ld d0,alu :cy if 1 ld alu,sl add_c d1 else ld alu,sl add d1 then ld (hp),alu ld alu,d0 next_m : exp10l__6uint16_6uint32 ( uint16 -- uint32 ) // if x<=4 next_m exp10 uint(x) // next_m x<=6 ? x==5?100000:1000000 : x==7?10000000:x==8?100000000:1000000000 cmp 10 // dtmp if !cy // !cy => cy => x<10 add alu // nodelay add tab1 // dtmp inc hp // prepare psh ld cmd,alu ld (hp),ival :bit15 tab1 dm 0,0,0,0,0, 1e5>>16, 1e6>>16, 1e7>>16, 1e8>>16, 1e9>>16 add tab2-tab1 // dtmp ld cmd,alu ld alu,ival :bit15 tab2 dm 1,10,100,1e3,1e4, 1e5&$ffff, 1e6&$ffff, 1e7&$ffff, 1e8&$ffff, 1e9&$ffff else xor alu psh alu then next_m : log10__6uint32_6uint16 ( uint32 -- uint16 ) // if x.h next_m x<1000000 ? x<10?1:2 : x<10000 ? x<1000?3:4 : 5 // else next_m log10(x.l) tst (hp) // delay pop d1 ld d0,alu :z // x = d1.d0 jp 1,Log10 // if x.h==0 next_m log10(x.l) instr lt_32(AH,AL,NN) ld alu,AH equ NN>>16 :z if 1 // a.h==n.h ? ld alu,AL // => compare a.l and n.l ld dtmp,NN&$ffff else ld alu,AH ld dtmp,NN>>16 then cmp dtmp // A-N: cy => !cy => A≥N ld alu,d2 :cy // !cy => cy => A(int)b.h : a.l>b.l ld d2,alu // d2=b.l pop alu,d0,dtmp // a=dtmp.d0; b=alu.d2 equ dtmp // b.h==a.h? ld cmd,ival :z if 1 dw ougt :bit15 // => (uint)a.l>(uint)b.l else dw ogt :bit15 // !> (int)a.h>(int)b.h (( Gt() in millicode_int.asm )) then next_m : op__GE__5int32_5int32_5int16 ( int32, int32 -- int16 ) // next_m a.h!=b.h ? (int)a.h>(int)b.h : a.l>=b.l ld d1,alu // d1=b.l pop alu,d0,dtmp // a=dtmp.d0; b=alu.d1 equ dtmp // b.h==a.h? ld cmd,ival :z if 1 dw ouge :bit15 // => (uint)a.l>=(uint)b.l else dw oge :bit15 // !> (int)a.h>=(int)b.h (( Ge() in millicode_int.asm )) then next_m : op__LT__5int32_5int32_5int16 ( int32, int32 -- int16 ) // next_m a.h!=b.h ? (int)a.h<(int)b.h : a.l (uint)a.l<(uint)b.l else dw olt :bit15 // !> (int)a.h<(int)b.h (( Lt() in millicode_int.asm )) then next_m : op__LE__5int32_5int32_5int16 ( int32, int32 -- int16 ) // next_m a.h!=b.h ? (int)a.h<(int)b.h : a.l<=b.l ld d2,alu // d2=b.l pop alu,d0,dtmp // a=dtmp.d0; b=alu.d2 equ dtmp // b.h==a.h? ld cmd,ival :z if 1 dw oule :bit15 // => (uint)a.l<=(uint)b.l else dw ole :bit15 // !> (int)a.h<=(int)b.h (( Le() in millicode_int.asm )) then next_m : op__NE__5int32_5int32_5int16 ( int32, int32 -- int16 ) // next_m a.h!=b.h || a.l!=b.l pop d0,d1,d2 xor d1 xor alu :z if 0 add_c alu // => 1 = yes nodelay next_m else ld alu,d0 equ d2 xor alu :z if 0 add_c alu // => 1 = yes nodelay then next_m then : op__EQ__5int32_5int32_5int16 ( int32, int32 -- int16 ) // next_m a.h==b.h && a.l==b.l pop d0,d1,d2 xor d1 xor alu :z if 0 next_m // => 0 = no else ld alu,d0 equ d2 xor alu :z if 1 add_c alu // => 1 = yes nodelay then next_m then : op__CPL__4void_5int32_6uint32 ( void, int32 -- uint32 ) ld dtmp,alu ldn (hp) ld (hp),alu ldn dtmp next_m : op__SUB__4void_5int32_5int32 ( void, int32 -- int32 ) ld atmp,alu dec atmp :z if 0 ldn (hp) // a.l!=0 => kein übertrag => a.h := ~a.h else //xor alu // a.l==0 => übertrag => a.h := -a.h sub_nc (hp) then ld (hp),alu ldn atmp next_m : op__ADD__5int32_5int32_5int32 ( int32, int32 -- int32 ) // alu = b.l pop d1 // d1 = b.h add (hp--) // alu = b.l+a.l ld d2,alu :cy // d2 = b.l+a.l if 1 ld alu,(hp) // alu = a.h add_c d1 // alu = a.h+b.h+cy else ld alu,(hp) // alu = a.h add d1 // alu = a.h+b.h then ld (hp),alu // a.h+b.h ld alu,d2 // a.l+b.l next_m : op__SUB__5int32_5int32_5int32 ( int32, int32 -- int32 ) // note: a-b = a+(~b)+1 cpl // alu = ~b.l pop d1 // d1 = b.h add_c (hp--) // alu = a.l + ~b.l + 1 ld d2,alu :cy if 1 ldn d1 // alu = ~b.h add_c (hp) // alu = a.h + ~b.h + 1 else ldn d1 // alu = ~b.h add (hp) // alu = a.h + ~b.h then ld (hp),alu // a.h+b.h ld alu,d2 // a.l+b.l next_m : op__MUL__5int32_5int32_5int32 ( int32, int32 -- int32 ) Millicoded // Size: 51 microcodes mc Lget+253 mc Int8+0 mc Int16+128 mc And mc BraIf0+21 mc Lget+255 mc Int8+0 mc Int16+128 mc And mc BraIf0+8 mc Lvar+253 mc Peek2 mc NegL mc Lvar+253 mc Peek2 mc NegL mc MulUL mc Bra+26 mc Lvar+253 mc Peek2 mc NegL mc Lvar+253 mc Peek2 mc MulUL mc NegL mc Bra+18 mc Lget+255 mc Int8+0 mc Int16+128 mc And mc BraIf0+8 mc Lvar+253 mc Peek2 mc Lvar+253 mc Peek2 mc NegL mc MulUL mc NegL mc Bra+5 mc Lvar+253 mc Peek2 mc Lvar+253 mc Peek2 mc MulUL mc Lvar+251 mc Poke2 mc MDrop0_Next-2 : op__DIV__5int32_5int32_5int32 ( int32, int32 -- int32 ) Millicoded // Size: 51 microcodes mc Lget+253 mc Int8+0 mc Int16+128 mc And mc BraIf0+21 mc Lget+255 mc Int8+0 mc Int16+128 mc And mc BraIf0+8 mc Lvar+253 mc Peek2 mc NegL mc Lvar+253 mc Peek2 mc NegL mc DivUL mc Bra+26 mc Lvar+253 mc Peek2 mc NegL mc Lvar+253 mc Peek2 mc DivUL mc NegL mc Bra+18 mc Lget+255 mc Int8+0 mc Int16+128 mc And mc BraIf0+8 mc Lvar+253 mc Peek2 mc Lvar+253 mc Peek2 mc NegL mc DivUL mc NegL mc Bra+5 mc Lvar+253 mc Peek2 mc Lvar+253 mc Peek2 mc DivUL mc Lvar+251 mc Poke2 mc MDrop0_Next-2 : op__AND__5int32_5int32_5int32 ( int32, int32 -- int32 ) Millicoded // Size: 13 microcodes mc Lget+255 mc Lvar+252 mc AndPoke mc Lvar+255 mc Addq+1 mc Peek mc Lvar+253 mc AndPoke mc MDrop0_Next-2 : op__OR__5int32_5int32_5int32 ( int32, int32 -- int32 ) Millicoded // Size: 13 microcodes mc Lget+255 mc Lvar+252 mc OrPoke mc Lvar+255 mc Addq+1 mc Peek mc Lvar+253 mc OrPoke mc MDrop0_Next-2 : op__XOR__5int32_5int32_5int32 ( int32, int32 -- int32 ) Millicoded // Size: 13 microcodes mc Lget+255 mc Lvar+252 mc XorPoke mc Lvar+255 mc Addq+1 mc Peek mc Lvar+253 mc XorPoke mc MDrop0_Next-2 : op__GT__6uint32_6uint32_5int16 ( uint32, uint32 -- int16 ) // next_m a.h!=b.h ? a.h>b.h : a.l>b.l ld d2,alu // d2=b.l pop alu,d0,dtmp // a=dtmp.d0; b=alu.d2 equ dtmp // b.h==a.h? if z // if a.h==b.h ougt: ld alu,d2 // then compare a.l with b.l else ld d0,dtmp // else compare a.h with b.h then cmp d0 xor alu :cy if 0 // !cy => cy => alu bb.h : a.l>=b.l ld d1,alu // d1=b.l pop alu,d0,dtmp // a=dtmp.d0; b=alu.d1 equ dtmp // b.h==a.h? if z // if a.h==b.h ouge: ld alu,d1 // then compare a.l with b.l else ld d0,dtmp then cmp_nc d0 xor alu :cy if 0 // !cy => cy => alu b≤a add_c alu // nodelay then next_m : op__LT__6uint32_6uint32_5int16 ( uint32, uint32 -- int16 ) // next_m a.h!=b.h ? a.h !cy => alu≥d1+1 => b>a add_c alu // nodelay then next_m : op__LE__6uint32_6uint32_5int16 ( uint32, uint32 -- int16 ) // next_m a.h!=b.h ? a.h !cy => alu≥d1 => b≥a add_c alu // nodelay then next_m : op__MUL__6uint32_6uint32_6uint32 ( uint32, uint32 -- uint32 ) Millicoded // Size: 26 microcodes mc Lget+254 mc Lget+255 mc mulu_16_32__6uint16_6uint16_6uint32 mc Lget+251 mc BraIf0+5 mc Lget+251 mc Lget+253 mc Mulu mc Lvar+254 mc AddPoke mc Lget+253 mc BraIf0+5 mc Lget+252 mc Lget+252 mc Mulu mc Lvar+254 mc AddPoke mc Lvar+255 mc Peek2 mc Lvar+249 mc Poke2 mc MDrop0_Next-4 : op__DIV__6uint32_6uint32_6uint32 ( uint32, uint32 -- uint32 ) Millicoded // Size: 97 microcodes mc Int8+0 mc Int8+0 mc Int8+0 mc Int8+0 mc Int8+0 mc Lvar+248 mc Peek2 mc Lvar+248 mc Peek2 mc GeUL mc BraIf0+77 mc Lget+250 mc Or1 mc Bra+1 mc Lget+251 mc BraIf0+66 mc Lvar+248 mc Peek2 mc msbit__5int32_5int16 mc Lvar+249 mc Peek2 mc msbit__5int32_5int16 mc Sub mc Nip mc Lvar+248 mc Peek2 mc Lget+254 mc SrUL mc Lvar+252 mc Poke2 mc Lvar+248 mc Peek2 mc Int8+32 mc Lget+253 mc Sub mc SlL mc Lvar+246 mc Poke2 mc Lvar+252 mc Peek2 mc Int8+1 mc SlL mc Lvar+250 mc Poke2 mc Lvar+254 mc Peek2 mc Lvar+248 mc Peek2 mc GeUL mc BraIf0+8 mc Int8+0 mc Int8+1 mc Lvar+250 mc AddPokeL mc Lvar+250 mc Peek2 mc Lvar+252 mc SubPokeL mc Lvar+254 mc Peek2 mc Int8+1 mc SlL mc Lvar+252 mc Poke2 mc Lget+248 mc Int8+0 mc Int16+128 mc And mc BraIf0+3 mc Int8+1 mc Lvar+254 mc AddPoke mc Lvar+248 mc Peek2 mc Int8+1 mc SlL mc Lvar+246 mc Poke2 mc PshHP mc Peekmm mc BraIf0+7 mc Bra-44 mc Int8+255 mc Int16+255 mc Int8+255 mc Int16+255 mc Lvar+250 mc Poke2 mc Lvar+252 mc Peek2 mc Lvar+246 mc Poke2 mc MDrop0_Next-7 : op__SR__6uint32_5int16_6uint32 ( uint32, int16 -- uint32 ) // if d & $10 { n.l=n.h n.h=0 } // d &= $F // if d // { // n.l = n.l>>d + n.h<<(16-d) // n.h = n.h>>d // } // next_m n pop d0 // d0 = n.l ld d1,(hp) // d1 = n.h tst_and $10 :z // d ≥ 16 ? if 0 // shift distance ≥ 16 => n.l = n.h>>d // n.h = 0 ld (hp++),0 // n.h = 0 ld (hp),d1 // n.l = n.h jp Sru else // shift distance < 16 // shift across word boundary: and $F ld atmp,alu jp p1 do ld sr,d1,nc ld d1,sr :bit0 if 1 ld sr,d0,cy else ld sr,d0,nc then ld d0,sr p1 tst atmp-- until z ld (hp),d1 // n.h back on stack ld alu,d0 // alu = top = n.l next_m then : op__SL__6uint32_5int16_6uint32 ( uint32, int16 -- uint32 ) // if d & $10 { n.h=n.l n.l=0 } // d &= $F // if d // { // n.h = n.h<>(16-d) // n.l = n.l< n.h = n.l< n.l=0 jp sln else // shift distance < 16 // shift across word boundary: and $F ld atmp,alu jp p1 do ld sl,d0,nc ld d0,sl :bit15 if 1 ld sl,d1,cy else ld sl,d1,nc then ld d1,sl p1 tst atmp-- until z ld (hp),d1 // n.h back on stack ld alu,d0 // alu = top = n.l next_m then : op__SUB__5int32_5int16_5int32 ( int32, int16 -- int32 ) tst alu,hp.clk,hp.oe,add1 ld (hp),ival :bit15 if 1 dw $FFFF else dw 0 then jp op__SUB__5int32_5int32_5int32 : op__ADD__5int32_5int16_5int32 ( int32, int16 -- int32 ) tst alu,hp.clk,hp.oe,add1 ld (hp),ival :bit15 if 1 dw $FFFF else dw 0 then jp op__ADD__5int32_5int32_5int32 : op__MUL__6uint32_6uint16_6uint32 ( uint32, uint16 -- uint32 ) Millicoded // Size: 19 microcodes mc Lget+255 mc Lget+255 mc mulu_16_32__6uint16_6uint16_6uint32 mc Lget+252 mc BraIf0+5 mc Lget+252 mc Lget+253 mc Mulu mc Lvar+254 mc AddPoke mc Lvar+255 mc Peek2 mc Lvar+250 mc Poke2 mc MDrop0_Next-3 : op__ADDGL__5int32_5int32P_ ( int32, int32& ) Millicoded // Size: 12 microcodes mc Dup mc Peek2 mc Lvar+252 mc Peek2 mc AddL mc Lget+254 mc Poke2 mc MDrop0_Next-3 : op__SUBGL__5int32_5int32P_ ( int32, int32& ) Millicoded // Size: 12 microcodes mc Dup mc Peek2 mc Lvar+252 mc Peek2 mc SubL mc Lget+254 mc Poke2 mc MDrop0_Next-3 : op__SLGL__5int16_6uint32P_ ( int16, uint32& ) Millicoded // Size: 11 microcodes mc Dup mc Peek2 mc Lget+253 mc SlL mc Lget+254 mc Poke2 mc MDrop0_Next-2 : op__SRGL__5int16_6uint32P_ ( int16, uint32& ) Millicoded // Size: 11 microcodes mc Dup mc Peek2 mc Lget+253 mc SrUL mc Lget+254 mc Poke2 mc MDrop0_Next-2 : peekpp__5int32P_5int32 ( int32& -- int32 ) Millicoded // Size: 19 microcodes mc Dup mc Peek2 mc Lget+254 mc Peek2 mc Int8+0 mc Int8+1 mc AddL mc Lget+252 mc Poke2 mc Lvar+255 mc Peek2 mc ToR2 mc MDrop0-3 mc FromR2 mc Ret