سؤال

I'm trying to compare 2 different char in assembly(calling assembly function in C program). One of the char belongs to a struct and the other is passed in when calling the function.

struct node {
    void   *previous;       
    void   *next;   
    unsigned int num;       
    unsigned int A;     
    unsigned int B;
}

node something;
something.A = 'C'; //assume everything else is correct

char A = 'C';
int func( char A ){ }:
find_course:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $28, %esp
    movl    8(%ebp), %ebx
    movl    10(%ebp), %ecx
    movl    16(%ebp), %edx
    movl    something, %edi
    cmpl    10(%edi), %ebx

.END:
    leave
    ret

when I debug with gdb, %ebx is 83 whereas 10(%edi) is 21315. If I print them out as characters, both appear to be 'C'. Is there any way that I can convert 21315 to 83?

هل كانت مفيدة؟

المحلول

Yes: you want to use movb 10(%edi), %al instead.

نصائح أخرى

You're just having some data-interpretation problems. Check out the hex values of the numbers you're dealing with:

 Base 10      Base 16
   83           53
  21315        5343

As you can see, the first byte there is 53 in both cases. You just are happening to read more than just one byte everywhere - that's what the l suffixes on your instructions mean. You probably want to read less than than that.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top