-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMACROS_CMP.inc
More file actions
139 lines (108 loc) · 4.58 KB
/
MACROS_CMP.inc
File metadata and controls
139 lines (108 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
;--------------------------------------------------------------------------------------------
.macro CMPEQ v1 v2 addr ; OK Compare and jump to addr if v1 = v2 (Equal)
MOV v2 tmpB
v1 tmpB
JMP0 tmpB addr
.endm
;--------------------------------------------------------------------------------------------
.macro CMPNE v1 v2 addr ; OK Compare and jump to addr if v1 != v2 (Not Equal)
CMPEQ v1 v2 @done
JMP addr
@done:
.endm
;--------------------------------------------------------------------------------------------
; bool is_less_(int8_t i1, int8_t i2) { // Handle direct comparison cases based on sign
; if (i1 < 0 && i2 >= 0) return true; // Negative i1 is always less than or equal to positive i2
; if (i1 >= 0 && i2 < 0) return false; // Positive i1 is always greater than negative i2
; int8_t diff = i2 - i1; // If both are of the same sign, perform subtraction
; // If both numbers are non-negative or both are negative, return true if diff > 0
; return diff > 0;
; }
.macro CMPLE v1 v2 addr ; Compare and jump to addr if v1 < v2 (Less than)
JMPGE0 v1 @notPos1Neg2
JMPL0 v2 @notPos1Neg2
JMP addr
@notPos1Neg2:
JMPL0 v1 @notNeg1Pos2
JMPGE0 v2 @notNeg1Pos2
JMP @done
@notNeg1Pos2:
MOV v2 tmpB
SUB v1 tmpB
JMPG0 tmpB addr
@done:
.endm
;--------------------------------------------------------------------------------------------
; bool is_less_or_equal(int8_t i1, int8_t i2) { // Handle direct comparison cases based on sign
; if (i1 < 0 && i2 >= 0) return true; // Negative i1 is always less than or equal to positive i2
; if (i1 >= 0 && i2 < 0) return false; // Positive i1 is always greater than negative i2
; int8_t diff = i2 - i1; // If both are of the same sign, perform subtraction
; // If both numbers are non-negative or both are negative, return true if diff >= 0
; return diff >= 0;
; }
.macro CMPLEQ v1 v2 addr ; Compare and jump to addr if v1 <= v2 (Less than or equal)
JMPGE0 v1 @notPos1Neg2
JMPL0 v2 @notPos1Neg2
JMP addr
@notPos1Neg2:
JMPL0 v1 @notNeg1Pos2
JMPGE0 v2 @notNeg1Pos2
JMP @done
@notNeg1Pos2:
MOV v2 tmpB
SUB v1 tmpB
JMPGE0 tmpB addr
@done:
.endm
;--------------------------------------------------------------------------------------------
; bool is_greater(int8_t i1, int8_t i2) { // Handle direct comparison cases based on sign
; if (i1 >= 0 && i2 < 0) return true; // Positive i1 is always greater than negative i2
; if (i1 < 0 && i2 >= 0) return false; // Negative i1 is always less than or equal to positive i2
; int8_t diff = i1 - i2; // If both are of the same sign, perform subtraction
; // If both numbers are non-negative or both are negative, return true if diff > 0
; return diff > 0;
; }
.macro CMPGE v1 v2 addr ; Compare and jump to addr if v1 > v2 (Greater than)
JMPL0 v1 @notPos1Neg2
JMPGE0 v2 @notPos1Neg2
JMP addr
@notPos1Neg2:
JMPGE0 v1 @notNeg1Pos2
JMPL0 v2 @notNeg1Pos2
JMP @done
@notNeg1Pos2:
MOV v1 tmpB
SUB v2 tmpB
JMPG0 tmpB addr
@done:
.endm
;--------------------------------------------------------------------------------------------
; bool is_greater_or_equal(int8_t i1, int8_t i2) { // Handle direct comparison cases based on sign
; if (i1 >= 0 && i2 < 0) return true; // Positive i1 is always greater than or equal to negative i2
; if (i1 < 0 && i2 >= 0) return false; // Negative i1 is always less than positive i2
; int8_t diff = i1 - i2; // If both are of the same sign, perform subtraction
; // If both numbers are non-negative or both are negative, return true if diff >= 0
; return diff >= 0;
; }
.macro CMPGEQ v1 v2 addr ; Compare and jump to addr if v1 >= v2 (Greater than or equal)
JMPL0 v1 @notPos1Neg2
JMPGE0 v2 @notPos1Neg2
JMP addr
@notPos1Neg2:
JMPGE0 v1 @notNeg1Pos2
JMPL0 v2 @notNeg1Pos2
JMP @done
@notNeg1Pos2:
MOV v1 tmpB
SUB v2 tmpB
JMPGE0 tmpB addr
@done:
.endm
;--------------------------------------------------------------------------------------------
.macro JBETWEEN val A B addr ; Jump to addr if val is between A and B (inclusive)
CMPLE val A @done
CMPGE val B @done
JMP addr
@done:
.endm
;--------------------------------------------------------------------------------------------