[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for bit handling.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | ;--------------------------------------------------------------------
|
---|
| 8 | ; Bit_GetSetCountToCXfromDXAX
|
---|
| 9 | ; Parameters
|
---|
| 10 | ; DX:AX: Source DWORD
|
---|
| 11 | ; Returns:
|
---|
| 12 | ; CX: Number of bits set in DX:AX
|
---|
| 13 | ; Corrupts registers:
|
---|
| 14 | ; Nothing
|
---|
| 15 | ;--------------------------------------------------------------------
|
---|
| 16 | ALIGN JUMP_ALIGN
|
---|
| 17 | Bit_GetSetCountToCXfromDXAX:
|
---|
| 18 | push bx
|
---|
| 19 |
|
---|
| 20 | call Bit_GetSetCountToCXfromAX
|
---|
| 21 | mov bx, cx
|
---|
| 22 | xchg ax, dx
|
---|
| 23 | call Bit_GetSetCountToCXfromAX
|
---|
| 24 | xchg ax, dx
|
---|
| 25 | add cx, bx
|
---|
| 26 |
|
---|
| 27 | pop bx
|
---|
| 28 | ret
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | ;--------------------------------------------------------------------
|
---|
| 32 | ; Bit_GetSetCountToCXfromAX
|
---|
| 33 | ; Parameters
|
---|
| 34 | ; AX: Source WORD
|
---|
| 35 | ; Returns:
|
---|
| 36 | ; CX: Number of bits set in AX
|
---|
| 37 | ; Corrupts registers:
|
---|
| 38 | ; Nothing
|
---|
| 39 | ;--------------------------------------------------------------------
|
---|
| 40 | ALIGN JUMP_ALIGN
|
---|
| 41 | Bit_GetSetCountToCXfromAX:
|
---|
| 42 | push ax
|
---|
| 43 |
|
---|
| 44 | xor cx, cx
|
---|
| 45 | ALIGN JUMP_ALIGN
|
---|
| 46 | .BitScanLoop:
|
---|
| 47 | shr ax, 1
|
---|
| 48 | jz SHORT .LastBitInCF
|
---|
[103] | 49 | adc cl, ch
|
---|
[41] | 50 | jmp SHORT .BitScanLoop
|
---|
| 51 | ALIGN JUMP_ALIGN
|
---|
| 52 | .LastBitInCF:
|
---|
[103] | 53 | adc cl, ch
|
---|
[41] | 54 |
|
---|
| 55 | pop ax
|
---|
| 56 | ret
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | ;--------------------------------------------------------------------
|
---|
| 60 | ; Bit_SetToDXAXfromIndexInCL
|
---|
| 61 | ; Parameters:
|
---|
| 62 | ; CL: Index of bit to set (0...31)
|
---|
| 63 | ; DX:AX: Destination DWORD with flag to be set
|
---|
| 64 | ; Returns:
|
---|
| 65 | ; DX:AX: DWORD with wanted bit set
|
---|
| 66 | ; Corrupts registers:
|
---|
| 67 | ; Nothing
|
---|
| 68 | ;--------------------------------------------------------------------
|
---|
| 69 | ALIGN JUMP_ALIGN
|
---|
| 70 | Bit_SetToDXAXfromIndexInCL:
|
---|
| 71 | cmp cl, 16
|
---|
| 72 | jb SHORT Bit_SetToAXfromIndexInCL
|
---|
| 73 |
|
---|
| 74 | sub cl, 16
|
---|
| 75 | xchg ax, dx
|
---|
| 76 | call Bit_SetToAXfromIndexInCL
|
---|
| 77 | xchg dx, ax
|
---|
| 78 | add cl, 16
|
---|
| 79 | ret
|
---|
| 80 |
|
---|
| 81 | ;--------------------------------------------------------------------
|
---|
| 82 | ; Bit_SetToAXfromIndexInCL
|
---|
| 83 | ; Parameters:
|
---|
| 84 | ; CL: Index of bit to set (0...15)
|
---|
| 85 | ; AX: Destination WORD with flag to be set
|
---|
| 86 | ; Returns:
|
---|
| 87 | ; AX: WORD with wanted bit set
|
---|
| 88 | ; Corrupts registers:
|
---|
| 89 | ; Nothing
|
---|
| 90 | ;--------------------------------------------------------------------
|
---|
| 91 | ALIGN JUMP_ALIGN
|
---|
| 92 | Bit_SetToAXfromIndexInCL:
|
---|
| 93 | push dx
|
---|
| 94 |
|
---|
| 95 | mov dx, 1
|
---|
| 96 | shl dx, cl
|
---|
| 97 | or ax, dx
|
---|
| 98 |
|
---|
| 99 | pop dx
|
---|
| 100 | ret
|
---|