0

I'm struggling with a problem with some AT&T assembly syntax.

Im using the "as" compiler on linux x86.

Im making a password program but it needs to be case insensitive. To clarify, it should evaluate true regardless of the case of any given character.

I have the normal evaluation process working correctly and i have it set up to iterate through a string.

#Comparison Routine

    movl $Password, %ebx     #Move the entire hardcoded password into ebx
    movl $buffer_data, %edx  #Move the entire input password into edx
    movl $Password_len, %ecx #Move the length of the input password into ecx

0:  
    movb (%ebx), %al         #Move one byte of the hardcoded password into al
    xorb (%edx), %al         #Compare one byte of the input password to one byte of the hardedcoded
    jz SkipCase              #If they match, jump to SkipCase

##### 

    andb $32, %al   # 
    xorb (%edx), %al

    jz SkipCase
    jnz IncorrectOutput #   

SkipCase:
    inc %ebx                #Iterate through the
    inc %edx                #strings and decrease
    dec %ecx                #the length variable
    jnz 0b                  #if we're not finished, continue
    jmp CorrectOutput       #If all is good, goto CorrectOutput

This is the section im struggling with, i can't figure out how to actually convert the character between cases. I'm aware i need to add or subtract 32 from it but something is amiss. Any comments or suggestions would be very helpful. Thanks.

andb $32, %al   # 
xorb (%edx), %al

This is the section for coverting the case, i have tried add, sub, and and or and i just cant get it to work. i realise the jz SkipCase after this is not nessessary.

The comparison routine is largely based off another question on here that i'll link if nessessary.

Apologies for layout and excessive hashes, bad commenting style i know.

Martin
  • 37,119
  • 15
  • 73
  • 82
TheoVate
  • 11
  • 2
  • The title of your question is somewhat misleading, as your problem is clearly not the syntax – Gunther Piez Dec 11 '11 at 15:18
  • The issue is that i dont know what syntax to use. I think the logic of the program is fine, i just need clarification of what code to use where. – TheoVate Dec 11 '11 at 15:53
  • Well, I would recommend using _cmp_ instead of _sub_ or even _xor_. It has the advantage it doesn't change the operands (like sub does). For the transformation from lower to upper case I recommend `sub $20h` instead of `xor $20h`, unless you want to obfuscate your code. But all this has nothing to do with AT&T syntax. – Gunther Piez Dec 11 '11 at 16:00

1 Answers1

1

I see that you first try to match the characters 'strictly' and when that fails you proceed with a case insensitive match.

andb $32, %al     # this 'and' operation only leaves the $32 bit if it is 
                  # present in al, all other bits are set to 0

# al is now either 0 (for a lower case character)
# or $32 (for an upper case character)

xorb (%edx), %al  # so this operation will become zero if the upper case 
                  # bit ($32) is set in the hardcoded password character

What you instead need to do is something like this:

xorb $32, %al     # invert case of the character by toggling the upper case bit
cmp (%edx), %al   # try to match again
je SkipCase

Hope that helps, I find it really difficult to explain bit operations in a short post like this. :)


Also, I presume this is either homework or some sort of excercise because a real password routine would have to be more clever - e.g. only perform the case insensitive check for letters, never digits or other characters.

Martin
  • 37,119
  • 15
  • 73
  • 82
  • Thank you very much, this works perfectly, exactally what i was looking for. Yeah instead of it being a usable product its more for the sake of demonstrating the use of assembly. I wonder if i could be cheeky and ask you to have a quick look at this one also http://stackoverflow.com/questions/8182165/att-assembly-masked-input which involves a problem i encountered between the difference between AT&T and intel assembly. Thanks for the perfect reply. – TheoVate Dec 11 '11 at 15:59
  • @TheoVate sorry that other question seems related to DOS syscalls which I don't know anything about – Martin Dec 14 '11 at 16:16