source: xtideuniversalbios/trunk/Assembly_Library/Src/Util/Size.asm@ 141

Last change on this file since 141 was 141, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:

  • Some inlining in Size.asm.
  • File Dialog can now enter in subdirectories starting with number.
File size: 3.0 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for size calculations.
3
4struc BYTE_MULTIPLES
5 .B resb 1
6 .kiB resb 1
7 .MiB resb 1
8 .GiB resb 1
9 .TiB resb 1
10endstruc
11
12; Section containing code
13SECTION .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;--------------------------------------------------------------------
32ALIGN JUMP_ALIGN
33Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX:
34 push si
35
36ALIGN 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 add sp, BYTE 2 ; Clean return address from stack
46 xchg si, cx ; CX = Remainder (0...1023), SI = Magnitude
47
48 ; Convert remainder to tenths
49 xchg bx, ax ; Store AX
50 mov ax, 10
51 mul cx ; DX:AX = remainder * 10
52 eSHR_IM ax, 10 ; Divide AX by 1024
53 xchg cx, ax ; CX = tenths
54 xchg ax, bx
55
56 ; Convert magnitude to character
57 mov dl, [cs:si+.rgbMagnitudeToChar]
58
59 pop si
60 ret
61.rgbMagnitudeToChar: db " kMGTP"
62
63
64;--------------------------------------------------------------------
65; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
66; Parameters:
67; BX:DX:AX: Size
68; CX: Magnitude in BYTE_MULTIPLES
69; Returns:
70; BX:DX:AX: Size in magnitude
71; SI: Remainder (0...1023)
72; CX: Magnitude in BYTE_MULTIPLES
73; Corrupts registers:
74; Nothing
75;--------------------------------------------------------------------
76ALIGN JUMP_ALIGN
77Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
78 push cx
79 xor si, si ; Zero remainder
80 mov cl, 10 ; Divide by 1024
81ALIGN JUMP_ALIGN
82.ShiftLoop:
83 call Size_DivideBXDXAXbyTwo
84 rcr si, 1 ; Update remainder
85 loop .ShiftLoop
86 eSHR_IM si, 6 ; Remainder to SI beginning
87 pop cx
88 inc cx ; Increment magnitude
89 ret
90
91
92;--------------------------------------------------------------------
93; Size_ConvertSectorCountInBXDXAXtoKiB
94; Size_DivideBXDXAXbyTwo
95; Parameters:
96; BX:DX:AX: Total sector count
97; Returns:
98; BX:DX:AX: Total size in kiB
99; CF: Remainder from division
100; Corrupts registers:
101; Nothing
102;--------------------------------------------------------------------
103ALIGN JUMP_ALIGN
104Size_ConvertSectorCountInBXDXAXtoKiB:
105Size_DivideBXDXAXbyTwo:
106 shr bx, 1 ; Divide sector count by 2...
107 rcr dx, 1 ; ...to get disk size in...
108 rcr ax, 1 ; ...kiB
109 ret
Note: See TracBrowser for help on using the repository browser.