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

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

Changes to Assembly Library:

  • Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX now returns right value on 8086/8088 build.
  • Debug macros again work on XTIDE Universal BIOS.
File size: 3.2 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for size calculations.
3
[85]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
[41]12; Section containing code
13SECTION .text
14
15;--------------------------------------------------------------------
[85]16; Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
[41]17; Parameters:
18; BX:DX:AX: Size in magnitude
[85]19; CX: Magnitude in BYTE_MULTIPLES
[41]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:
[142]34%ifndef USE_186 ; If 8086/8088
35 push di
36%endif
[41]37 push si
38
39ALIGN JUMP_ALIGN
40.MagnitudeConversionLoop:
[142]41 ePUSH_T di, .MagnitudeConversionLoop; DI corrupted only on 8086/8088 build
42 test bx, bx ; Bits 32...47 in use?
[41]43 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
[142]44 test dx, dx ; Bits 16...31 in use?
[41]45 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
[142]46 cmp ax, 10000 ; 5 digits needed?
[41]47 jae SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
[142]48 add sp, BYTE 2 ; Clean return address from stack
49 xchg si, cx ; CX = Remainder (0...1023), SI = Magnitude
[41]50
[141]51 ; Convert remainder to tenths
[142]52 xchg bx, ax ; Store AX
[141]53 mov ax, 10
[142]54 mul cx ; DX:AX = remainder * 10
55 eSHR_IM ax, 10 ; Divide AX by 1024
56 xchg cx, ax ; CX = tenths
[141]57 xchg ax, bx
58
59 ; Convert magnitude to character
60 mov dl, [cs:si+.rgbMagnitudeToChar]
61
[41]62 pop si
[142]63%ifndef USE_186
64 pop di
65%endif
[41]66 ret
[141]67.rgbMagnitudeToChar: db " kMGTP"
[41]68
[141]69
[41]70;--------------------------------------------------------------------
71; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
72; Parameters:
73; BX:DX:AX: Size
[85]74; CX: Magnitude in BYTE_MULTIPLES
[41]75; Returns:
76; BX:DX:AX: Size in magnitude
77; SI: Remainder (0...1023)
[85]78; CX: Magnitude in BYTE_MULTIPLES
[41]79; Corrupts registers:
80; Nothing
81;--------------------------------------------------------------------
82ALIGN JUMP_ALIGN
83Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
84 push cx
85 xor si, si ; Zero remainder
86 mov cl, 10 ; Divide by 1024
87ALIGN JUMP_ALIGN
88.ShiftLoop:
89 call Size_DivideBXDXAXbyTwo
90 rcr si, 1 ; Update remainder
91 loop .ShiftLoop
92 eSHR_IM si, 6 ; Remainder to SI beginning
93 pop cx
94 inc cx ; Increment magnitude
95 ret
96
97
98;--------------------------------------------------------------------
99; Size_ConvertSectorCountInBXDXAXtoKiB
100; Size_DivideBXDXAXbyTwo
101; Parameters:
102; BX:DX:AX: Total sector count
103; Returns:
104; BX:DX:AX: Total size in kiB
105; CF: Remainder from division
106; Corrupts registers:
107; Nothing
108;--------------------------------------------------------------------
109ALIGN JUMP_ALIGN
110Size_ConvertSectorCountInBXDXAXtoKiB:
111Size_DivideBXDXAXbyTwo:
112 shr bx, 1 ; Divide sector count by 2...
113 rcr dx, 1 ; ...to get disk size in...
114 rcr ax, 1 ; ...kiB
115 ret
Note: See TracBrowser for help on using the repository browser.