1 | ; Project name : Assembly Library |
---|
2 | ; Description : Functions for size calculations. |
---|
3 | |
---|
4 | struc BYTE_MULTIPLES |
---|
5 | .B resb 1 |
---|
6 | .kiB resb 1 |
---|
7 | .MiB resb 1 |
---|
8 | .GiB resb 1 |
---|
9 | .TiB resb 1 |
---|
10 | endstruc |
---|
11 | |
---|
12 | ; Section containing code |
---|
13 | SECTION .text |
---|
14 | |
---|
15 | ;-------------------------------------------------------------------- |
---|
16 | ; Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX |
---|
17 | ; Parameters: |
---|
18 | ; BX:DX:AX: Size in magnitude |
---|
19 | ; CX: Magnitude in BYTE_MULTIPLES |
---|
20 | ; Returns: |
---|
21 | ; AX: Size in magnitude |
---|
22 | ; CX: Tenths |
---|
23 | ; DL: Magnitude character: |
---|
24 | ; 'k' = *1024 B = kiB |
---|
25 | ; 'M' = *1024 kiB = MiB |
---|
26 | ; 'G' = *1024 MiB = GiB |
---|
27 | ; 'T' = *1024 GiB = TiB |
---|
28 | ; 'P' = *1024 TiB = PiB |
---|
29 | ; Corrupts registers: |
---|
30 | ; BX, DH |
---|
31 | ;-------------------------------------------------------------------- |
---|
32 | ALIGN JUMP_ALIGN |
---|
33 | Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX: |
---|
34 | push si |
---|
35 | |
---|
36 | ALIGN JUMP_ALIGN |
---|
37 | .MagnitudeConversionLoop: |
---|
38 | ePUSH_T si, .MagnitudeConversionLoop |
---|
39 | test bx, bx ; Bits 32...47 in use? |
---|
40 | jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX |
---|
41 | test dx, dx ; Bits 16...31 in use? |
---|
42 | jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX |
---|
43 | cmp ax, 10000 ; 5 digits needed? |
---|
44 | jae SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX |
---|
45 | |
---|
46 | add sp, BYTE 2 ; Clean return address from stack |
---|
47 | call Size_ConvertMagnitudeRemainderInSItoTenths |
---|
48 | call Size_GetMagnitudeCharacterToDLfromMagnitudeInCX |
---|
49 | mov cx, si |
---|
50 | |
---|
51 | pop si |
---|
52 | ret |
---|
53 | |
---|
54 | ;-------------------------------------------------------------------- |
---|
55 | ; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX |
---|
56 | ; Parameters: |
---|
57 | ; BX:DX:AX: Size |
---|
58 | ; CX: Magnitude in BYTE_MULTIPLES |
---|
59 | ; Returns: |
---|
60 | ; BX:DX:AX: Size in magnitude |
---|
61 | ; SI: Remainder (0...1023) |
---|
62 | ; CX: Magnitude in BYTE_MULTIPLES |
---|
63 | ; Corrupts registers: |
---|
64 | ; Nothing |
---|
65 | ;-------------------------------------------------------------------- |
---|
66 | ALIGN JUMP_ALIGN |
---|
67 | Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX: |
---|
68 | push cx |
---|
69 | xor si, si ; Zero remainder |
---|
70 | mov cl, 10 ; Divide by 1024 |
---|
71 | ALIGN JUMP_ALIGN |
---|
72 | .ShiftLoop: |
---|
73 | call Size_DivideBXDXAXbyTwo |
---|
74 | rcr si, 1 ; Update remainder |
---|
75 | loop .ShiftLoop |
---|
76 | eSHR_IM si, 6 ; Remainder to SI beginning |
---|
77 | pop cx |
---|
78 | inc cx ; Increment magnitude |
---|
79 | ret |
---|
80 | |
---|
81 | |
---|
82 | ;-------------------------------------------------------------------- |
---|
83 | ; Size_ConvertSectorCountInBXDXAXtoKiB |
---|
84 | ; Size_DivideBXDXAXbyTwo |
---|
85 | ; Parameters: |
---|
86 | ; BX:DX:AX: Total sector count |
---|
87 | ; Returns: |
---|
88 | ; BX:DX:AX: Total size in kiB |
---|
89 | ; CF: Remainder from division |
---|
90 | ; Corrupts registers: |
---|
91 | ; Nothing |
---|
92 | ;-------------------------------------------------------------------- |
---|
93 | ALIGN JUMP_ALIGN |
---|
94 | Size_ConvertSectorCountInBXDXAXtoKiB: |
---|
95 | Size_DivideBXDXAXbyTwo: |
---|
96 | shr bx, 1 ; Divide sector count by 2... |
---|
97 | rcr dx, 1 ; ...to get disk size in... |
---|
98 | rcr ax, 1 ; ...kiB |
---|
99 | ret |
---|
100 | |
---|
101 | |
---|
102 | ;-------------------------------------------------------------------- |
---|
103 | ; Size_ConvertMagnitudeRemainderInSItoTenths |
---|
104 | ; Parameters: |
---|
105 | ; SI: Remainder from last magnitude division (0...1023) |
---|
106 | ; Returns: |
---|
107 | ; SI: Tenths |
---|
108 | ; Corrupts registers: |
---|
109 | ; DX |
---|
110 | ;-------------------------------------------------------------------- |
---|
111 | ALIGN JUMP_ALIGN |
---|
112 | Size_ConvertMagnitudeRemainderInSItoTenths: |
---|
113 | push ax |
---|
114 | |
---|
115 | mov ax, 10 |
---|
116 | mul si ; DX:AX = remainder * 10 |
---|
117 | eSHR_IM ax, 10 ; Divide AX by 1024 |
---|
118 | xchg si, ax ; SI = tenths |
---|
119 | |
---|
120 | pop ax |
---|
121 | ret |
---|
122 | |
---|
123 | |
---|
124 | ;-------------------------------------------------------------------- |
---|
125 | ; Size_GetMagnitudeCharacterToDLfromMagnitudeInCX |
---|
126 | ; Parameters: |
---|
127 | ; CX: Magnitude in BYTE_MULTIPLES |
---|
128 | ; Returns: |
---|
129 | ; DL: Magnitude character |
---|
130 | ; Corrupts registers: |
---|
131 | ; BX |
---|
132 | ;-------------------------------------------------------------------- |
---|
133 | ALIGN JUMP_ALIGN |
---|
134 | Size_GetMagnitudeCharacterToDLfromMagnitudeInCX: |
---|
135 | mov bx, cx |
---|
136 | mov dl, [cs:bx+.rgbMagnitudeToChar] |
---|
137 | ret |
---|
138 | ALIGN WORD_ALIGN |
---|
139 | .rgbMagnitudeToChar: db " kMGTP" |
---|