<<<--- % Author M.Ruckert LOC #100 --->>> PREFIX :Fix: u IS $0 1. parameter and return value s IS$1 $u$ unpacked e IS $2 f IS$3 carry IS $4 for rounding tmp IS$5 :Fix ZSN s,u,1 % \ul{Unpack.} Set sign SETH tmp,#FFF0; ANDN f,u,tmp Remove sign and exponet bits to get $f$ INCH f,#0010 Add hidden bit. $2^{52}\le f < 2^{53}$ SLU e,u,1; SRU e,e,53 Get exponent. Now $u=f2^{e-q}/2^{52}$. % \ul{Check exponent range.} SET tmp,1023-1; SUB e,e,tmp Subtract $q-1$. Now $u = f2^e/2^{53}$ BN e,Zero $u<1/2$ CMP tmp,e,63; BP tmp,:Error $u\ge2^{63}$ (Overflow) SUB e,e,53 Now $u=f2^e$. BN e,Round SLU u,f,e JMP Sign % \ul{Round.} Round NEG e,e; SUB e,e,2; SRU f,f,e Now $u=f/4$ SRU u,f,2 $u \is \lfloor f \rfloor$ AND tmp,f,3; CMP tmp,tmp,2 Compare $(f \bmod 4)/4$ to $1/2$ CSOD carry,u,1 $u$ is odd; round up if $(f \bmod 4)/4 \ge {1\over 2}$ CSEV carry,u,tmp $u$ is even; round up if $(f \bmod 4)/4 > {1\over 2}$ ZSNN carry,tmp,carry Round down if $(f \bmod 4)/4 < {1\over 2}$ ADDU u,u,carry % \ul{Attach Sign.} Sign NEG tmp,u; CSNZ u,s,tmp If $s$, set $u \is -u$. POP 1,0 Zero SET u,0 % \ul{Return zero.} POP 1,0 <<<--- PREFIX : Main FLOT $1,77 PUSHJ$0,Fix NEG $1,33 FLOT$1,$1 PUSHJ$0,Fix FLOT $2,2 FLOT$1,1 FDIV $1,$1,$2 FIX$0,$1 PUSHJ$0,Fix FLOT $2,2 FLOT$1,3 FDIV $1,$1,$2 FIX$0,$1 PUSHJ$0,Fix SET $255,0 TRAP 0,Halt,0 Error SET$255,1 TRAP 0,Halt,0 --->>>