Overall, I am trying to compare the value of the first element of an array passed into my assembly function from a c++ program with a constant value and preform a jump if they are equal.
I can view the value of %rdi
in gdb with x /c $rdi
and it outputs 0x7fffffffde80: 97 'a'
I would expect that cmp $97, %rdi
and then preforming a jump if they are equal would work, but alas the comparison fails as if these two values are not equal.
I've built a small test program demonstrating what I am attempting to do. The program should get stuck in an infinite loop if the first element of the array being passed in is not an 'a', otherwise it should exit normally. when ran though, I get stuck in an infinite loop regardless of the values passed in the array.
Any insight onto what is going on here would be very much appreciated.
In my driver cpp:
#include <iostream>
#include <stdio.h>
extern int _asmTest(char c[]) __asm__("_asmTest");
int main()
{
char arr[2] = {'a','b'};
int test = _asmTest(arr);
std::cout << "First element was 'a'" << std::endl;
return 0;
}
In my asm:
.global _asmTest
.text
_asmTest:
push %rbp
mov %rsp, %rbp
# Go to infinite loop if arg1's first element is not 'a'
loop:
cmp $97, %rdi
je continue
jmp loop
continue:
mov %rbp, %rsp
pop %rbp
ret