|
|
1.1 root 1: ////////
2: /
3: / Intel 8086 floating point.
4: / double to int and unsigned int.
5: / small model.
6: /
7: ////////
8:
9: .globl idcvt
10: .globl udcvt
11: .globl _fpac_
12:
13: ////////
14: /
15: / idcvt - double to integer.
16: / udcvt - double to unsigned integer.
17: /
18: / compiler calling sequence:
19: / push <double argument>
20: / call [iu]dcvt
21: / add sp,8
22: /
23: / outputs:
24: / ax=int or unsigned int result.
25: /
26: / uses:
27: / ax, bx, cx, dx
28: /
29: ////////
30:
31: n = 8 / double argument
32:
33: idcvt: push si / standard
34: push di / c
35: push bp / function
36: mov bp,sp / linkage
37:
38: mov si,$15 / si=largest exponent.
39: jmp l0 / go to common code.
40:
41: udcvt: push si / standard
42: push di / c
43: push bp / function
44: mov bp,sp / linkage
45:
46: testb n+7(bp),$0x80 / double < 0 ??
47: jnz l3 / (error) yes, return 0.
48: mov si,$16 / si=largest exponant.
49:
50: l0: mov dx,n+6(bp) / scoop up the front
51: mov bx,n+4(bp) / of the double.
52:
53: shl bx,$1 / slide
54: rcl dx,$1 / sign.
55:
56: movb cl,dh / cl=biased exponant.
57: and cx,$0xFF / extract, test for all zeros.
58: jz l3 / if exp=0, it's 0.
59: sub cx,$0x81 / unbias.
60: jl l3 / if small, it's 0.
61: cmp cx,si / legal range ??
62: jge l3 / (error) nope, return 0.
63:
64: mov ax,$0x01 / hidden bit.
65: jcxz l2 / skip if done.
66:
67: l1: shlb bh,$1 / shift
68: rclb dl,$1 / up
69: rcl ax,$1 / int.
70: loop l1 / do all bits.
71:
72: l2: testb n+7(bp),$0x80 / check sign of double.
73: jz l4 / jump if pos.
74: neg ax / fix.
75: jmp l4 / done.
76:
77: l3: sub ax,ax / return 0.
78:
79: l4: pop bp / standard
80: pop di / c
81: pop si / function
82: ret / return.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.