I looked in the instruction reference for cmova, and it says that it moves if the carry flag and the zero flag are both zero, but I don't understand what does it mean "above" in this context.
We were given an example to find a minimum in a linked list:
int t1 = 0;
Node *t2 = head;
if(t2)
t1 = t2->data;
while (t2) {
if(t1 > t2->data) {
t1 = t2->data;
}
t2 = t2->next;
}
where Node
was:
typedef struct _Node {
int data;
int id;
struct _Node *next;
} Node;
And the asm code was:
.global _start
.section .data
head: .quad A
A: .int 4 # int data
.int 1 # int id
.quad B # Node *next
B: .int 6
.int 2
.quad C
C: .int -5
.int 3
.quad D
D: .int 1
.int 4
.quad 0
.section .text
_start:
movq head(%rip), %rdi
movl $0, %eax
testq %rdi, %rdi
je end
movl (%rdi), %eax
.L3:
movl (%rdi), %ecx
cmpl %ecx, %eax
cmovg %ecx, %eax
movq 8(%rdi), %rdi
testq %rdi, %rdi
jne .L3
end:
This followed by the question: say we change cmovg %ecx, %eax
to cmova %ecx, %eax
, what would change? I ran the code, and this time it returned 1 instead of -5, so I understood it that the comparison would be unsigned, but I am not sure whether I got it right.
I would appreciate it if someone could clarify me what does it mean to "move if above/below."