I am using inline C assembly and I does not understand why does not work cmp command same for this 2 cases.
I have C function:
int array_max(const int input_array[], const int array_size);
In the main I created array and passed it in to the function
int input_array[] = {50,10,3,70,5};
printf("%d\n", array_max(input_array, 5));
Function definition is writed in assembly
__asm__
(
"array_max:;"
" xor %rdx, %rdx;"
" movq $70, %rax;"
" movq $50, %rbx;"
" cmp %rbx, %rax;"
" jge gr_eq;"
" movq %rbx, %rax;"
"gr_eq:;"
" ret"
);
In this case is return value 70
__asm__
(
"array_max:;"
" xor %rdx, %rdx;"
" movq $70, %rax;"
" movq (%rdi,%rdx,4), %rbx;" // input_array[0] == 50
" cmp %rbx, %rax;"
" jge gr_eq;"
" movq %rbx, %rax;"
"gr_eq:;"
" ret"
);
But it this case 50...
Can sameone help me how can I compare passed array values to value in the register? And explain me why this implementation does not work?