1 | ; File name : Math.inc
|
---|
2 | ; Project name : Assembly Library
|
---|
3 | ; Created date : 12.8.2010
|
---|
4 | ; Last update : 12.8.2010
|
---|
5 | ; Author : Tomi Tilli
|
---|
6 | ; Description : Math related macros.
|
---|
7 | %ifndef MATH_INC
|
---|
8 | %define MATH_INC
|
---|
9 |
|
---|
10 | FALSE EQU 0
|
---|
11 | TRUE EQU 1
|
---|
12 |
|
---|
13 |
|
---|
14 | ;--------------------------------------------------------------------
|
---|
15 | ; MIN_U Unsigned comparison
|
---|
16 | ; MIN_S Signed comparison
|
---|
17 | ; Parameters:
|
---|
18 | ; %1: Operand 1
|
---|
19 | ; %2: Operand 2
|
---|
20 | ; Returns:
|
---|
21 | ; %1: Lesser operand
|
---|
22 | ; Corrupts registers:
|
---|
23 | ; Nothing
|
---|
24 | ;--------------------------------------------------------------------
|
---|
25 | %macro MIN_U 2
|
---|
26 | cmp %1, %2 ; Is %1 smaller?
|
---|
27 | jb %%Return ; If so, return
|
---|
28 | mov %1, %2 ; Copy %2 to %1
|
---|
29 | ALIGN JUMP_ALIGN
|
---|
30 | %%Return:
|
---|
31 | %endmacro
|
---|
32 |
|
---|
33 | %macro MIN_S 2
|
---|
34 | cmp %1, %2 ; Is %1 smaller?
|
---|
35 | jl %%Return ; If so, return
|
---|
36 | mov %1, %2 ; Copy %2 to %1
|
---|
37 | ALIGN JUMP_ALIGN
|
---|
38 | %%Return:
|
---|
39 | %endmacro
|
---|
40 |
|
---|
41 |
|
---|
42 | ;--------------------------------------------------------------------
|
---|
43 | ; MAX_U Unsigned comparison
|
---|
44 | ; MAX_S Signed comparison
|
---|
45 | ; Parameters:
|
---|
46 | ; %1: Operand 1
|
---|
47 | ; %2: Operand 2
|
---|
48 | ; Returns:
|
---|
49 | ; %1: Lesser operand
|
---|
50 | ; Corrupts registers:
|
---|
51 | ; Nothing
|
---|
52 | ;--------------------------------------------------------------------
|
---|
53 | %macro MAX_U 2
|
---|
54 | cmp %1, %2 ; Is %1 greater?
|
---|
55 | ja %%Return ; If so, return
|
---|
56 | mov %1, %2 ; Copy %2 to %1
|
---|
57 | ALIGN JUMP_ALIGN
|
---|
58 | %%Return:
|
---|
59 | %endmacro
|
---|
60 |
|
---|
61 | %macro MAX_S 2
|
---|
62 | cmp %1, %2 ; Is %1 greater?
|
---|
63 | jg %%Return ; If so, return
|
---|
64 | mov %1, %2 ; Copy %2 to %1
|
---|
65 | ALIGN JUMP_ALIGN
|
---|
66 | %%Return:
|
---|
67 | %endmacro
|
---|
68 |
|
---|
69 |
|
---|
70 | %endif ; MATH_INC
|
---|