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