[41] | 1 | ; Project name : Assembly Library |
---|
| 2 | ; Description : Functions for size calculations. |
---|
| 3 | |
---|
[85] | 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 | |
---|
[41] | 12 | ; Section containing code |
---|
| 13 | SECTION .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 | ;-------------------------------------------------------------------- |
---|
| 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 | add sp, BYTE 2 ; Clean return address from stack |
---|
[141] | 46 | xchg si, cx ; CX = Remainder (0...1023), SI = Magnitude |
---|
[41] | 47 | |
---|
[141] | 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 | |
---|
[41] | 59 | pop si |
---|
| 60 | ret |
---|
[141] | 61 | .rgbMagnitudeToChar: db " kMGTP" |
---|
[41] | 62 | |
---|
[141] | 63 | |
---|
[41] | 64 | ;-------------------------------------------------------------------- |
---|
| 65 | ; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX |
---|
| 66 | ; Parameters: |
---|
| 67 | ; BX:DX:AX: Size |
---|
[85] | 68 | ; CX: Magnitude in BYTE_MULTIPLES |
---|
[41] | 69 | ; Returns: |
---|
| 70 | ; BX:DX:AX: Size in magnitude |
---|
| 71 | ; SI: Remainder (0...1023) |
---|
[85] | 72 | ; CX: Magnitude in BYTE_MULTIPLES |
---|
[41] | 73 | ; Corrupts registers: |
---|
| 74 | ; Nothing |
---|
| 75 | ;-------------------------------------------------------------------- |
---|
| 76 | ALIGN JUMP_ALIGN |
---|
| 77 | Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX: |
---|
| 78 | push cx |
---|
| 79 | xor si, si ; Zero remainder |
---|
| 80 | mov cl, 10 ; Divide by 1024 |
---|
| 81 | ALIGN 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 | ;-------------------------------------------------------------------- |
---|
| 103 | ALIGN JUMP_ALIGN |
---|
| 104 | Size_ConvertSectorCountInBXDXAXtoKiB: |
---|
| 105 | Size_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 |
---|