I coded a program in nasm assembly that swaps lowercase characters with uppercase characters and viceversa. I am trying now to program the same with gas assembly, but I am having trouble with the syntax for the comparisons of the bytes.
So far the programs loads the user input in ESI register and the length of it (it was defined at maximum 100 bytes) in the ECX register.
After that, it starts by comparing the last byte at the right to check if its between the values 0x61 and 0x7A (Between 'a' and 'z'), if the value of the bit is above that, it should display an error that 'an invalid character has been inserted'.
If the value of the bit does match in the range, it will substract 0x20 to make it an Uppercase character.
If the value of the bit is lower, it will then check if the value of the bit is between the values 0x41 and 0x5A (Between 'A' and 'Z'). If the value is above that, it will give the error message (Because it has already confirmed that its not between 'a' and 'z').
If the value of the bit does match in the A-Z range, it will add 0x20 to make it an lowercase character.
If the value of the bit is lower than 'A', it will then check if the character value matches 0x20 (The ' ' character).
After these comparisons, the register value in ECX is decreased by one and the loop continues until the value is 0.
The thing is, I don't know how to write the comparison in GAS syntax. In NASM, the block that checks the lowercase range is the following:
mov ecx, 100
mov esi, userMsg
dec rsi
jmp _checkLowercase
_checkLowercase:
cmp byte [esi+ecx],0x61 ;checks value of byte with 'a'
jb _checkUppercase ;if its below the value 'a', it goes to check for uppercase
cmp byte [esi+ecx],0x7A ;checks value of byte with 'z'
ja _errorMsg ;if its above 'z', it goes to this subrutine that prints an error message
sub byte [esi+ecx],0x20 ;I substract 32 to make it uppercase
jmp _nextChar ;This subroutine decreases the value at ecx by one and returns to _checkLowercase
I know that by doing [esi+ecx] I can select a specific byte in the character string to compare
If I am not mistaken (I have checked some GAS sources, but I can't find Anything concrete), this is what I should have in GAS (It's supposed to be the same subroutine as the one above):
mov $100, %ecx
mov $userMsg, %esi
dec %esi
jmp _checkLowercase
_checkLowercase:
cmpb $0x61, %ecx(%esi) #These are the lines I am having trouble with
jb _checkUppercase
cmpb $0x7A, %ecx(%esi) #Is this really the equivalent of [esi+ecx]?
ja _errorMsg
subb $0x20, %ecx(%esi)
jmp _nextChar
I am getting errors with the lines that have the comparisons, and is this one:
"Error: junk `(%esi)' after register"
Long Story short: How do I write cmp value, [esi+ecx]
in GAS?