[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Math related macros.
|
---|
| 3 | %ifndef MATH_INC
|
---|
| 4 | %define MATH_INC
|
---|
| 5 |
|
---|
| 6 | FALSE EQU 0
|
---|
| 7 | TRUE EQU 1
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | ;--------------------------------------------------------------------
|
---|
| 11 | ; MIN_U Unsigned comparison
|
---|
| 12 | ; MIN_S Signed comparison
|
---|
| 13 | ; Parameters:
|
---|
| 14 | ; %1: Operand 1
|
---|
| 15 | ; %2: Operand 2
|
---|
| 16 | ; Returns:
|
---|
| 17 | ; %1: Lesser operand
|
---|
| 18 | ; Corrupts registers:
|
---|
| 19 | ; Nothing
|
---|
| 20 | ;--------------------------------------------------------------------
|
---|
| 21 | %macro MIN_U 2
|
---|
| 22 | cmp %1, %2 ; Is %1 smaller?
|
---|
| 23 | jb %%Return ; If so, return
|
---|
| 24 | mov %1, %2 ; Copy %2 to %1
|
---|
| 25 | ALIGN JUMP_ALIGN
|
---|
| 26 | %%Return:
|
---|
| 27 | %endmacro
|
---|
| 28 |
|
---|
| 29 | %macro MIN_S 2
|
---|
| 30 | cmp %1, %2 ; Is %1 smaller?
|
---|
| 31 | jl %%Return ; If so, return
|
---|
| 32 | mov %1, %2 ; Copy %2 to %1
|
---|
| 33 | ALIGN JUMP_ALIGN
|
---|
| 34 | %%Return:
|
---|
| 35 | %endmacro
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | ;--------------------------------------------------------------------
|
---|
| 39 | ; MAX_U Unsigned comparison
|
---|
| 40 | ; MAX_S Signed comparison
|
---|
| 41 | ; Parameters:
|
---|
| 42 | ; %1: Operand 1
|
---|
| 43 | ; %2: Operand 2
|
---|
| 44 | ; Returns:
|
---|
[181] | 45 | ; %1: Greater operand
|
---|
[41] | 46 | ; Corrupts registers:
|
---|
| 47 | ; Nothing
|
---|
| 48 | ;--------------------------------------------------------------------
|
---|
| 49 | %macro MAX_U 2
|
---|
| 50 | cmp %1, %2 ; Is %1 greater?
|
---|
| 51 | ja %%Return ; If so, return
|
---|
| 52 | mov %1, %2 ; Copy %2 to %1
|
---|
| 53 | ALIGN JUMP_ALIGN
|
---|
| 54 | %%Return:
|
---|
| 55 | %endmacro
|
---|
| 56 |
|
---|
| 57 | %macro MAX_S 2
|
---|
| 58 | cmp %1, %2 ; Is %1 greater?
|
---|
| 59 | jg %%Return ; If so, return
|
---|
| 60 | mov %1, %2 ; Copy %2 to %1
|
---|
| 61 | ALIGN JUMP_ALIGN
|
---|
| 62 | %%Return:
|
---|
| 63 | %endmacro
|
---|
| 64 |
|
---|
| 65 |
|
---|
[172] | 66 | ;--------------------------------------------------------------------
|
---|
[287] | 67 | ; SHL_DXAX
|
---|
| 68 | ; Parameters:
|
---|
| 69 | ; %1: Number of bits to shift
|
---|
| 70 | ; Returns:
|
---|
| 71 | ; DX:AX Shifted value
|
---|
| 72 | ; Corrupts registers:
|
---|
| 73 | ; CX
|
---|
| 74 | ;--------------------------------------------------------------------
|
---|
| 75 | %macro SHL_DXAX 1
|
---|
| 76 | %ifnidni %1, cx
|
---|
| 77 | mov cx, %1
|
---|
| 78 | %endif
|
---|
| 79 | ALIGN JUMP_ALIGN
|
---|
| 80 | .ShiftNextBit:
|
---|
[445] | 81 | eSHL_IM ax, 1
|
---|
[287] | 82 | rcl dx, 1
|
---|
| 83 | loop .ShiftNextBit
|
---|
| 84 | %endmacro
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | ;--------------------------------------------------------------------
|
---|
[172] | 88 | ; SHR_DXAX
|
---|
| 89 | ; Parameters:
|
---|
| 90 | ; %1: Number of bits to shift
|
---|
| 91 | ; Returns:
|
---|
| 92 | ; DX:AX Shifted value
|
---|
| 93 | ; Corrupts registers:
|
---|
| 94 | ; CX
|
---|
| 95 | ;--------------------------------------------------------------------
|
---|
| 96 | %macro SHR_DXAX 1
|
---|
| 97 | %ifnidni %1, cx
|
---|
| 98 | mov cx, %1
|
---|
| 99 | %endif
|
---|
| 100 | ALIGN JUMP_ALIGN
|
---|
| 101 | .ShiftNextBit:
|
---|
| 102 | shr dx, 1
|
---|
| 103 | rcr ax, 1
|
---|
| 104 | loop .ShiftNextBit
|
---|
| 105 | %endmacro
|
---|
| 106 |
|
---|
| 107 |
|
---|
[41] | 108 | %endif ; MATH_INC
|
---|