Search code examples
assemblyx86att

Assembler get value of pointer


At the moment I play a bit with assembler but I have one question to pointers. In my assembler program I have a String which I put in the registers EAX and I want to get the third character from the string. This works great with this code:

movl  $3, %esi

movl  $.STR1, %eax
movl  (%esi, %eax), %ecx

My problem is that I get an address to the chacrter with this command and not the ASCII value of the character. How can I access the value of the referenced pointer?


Solution

  • That looks about right, except characters are 1 byte each, so you should either movb (%esi, %eax), %cl or movzbl (%esi, %eax), %ecx. Note you didn't get the address, you got the first 4 characters from your string packed into %ecx. Of course for constants you can directly do movb .STR1+3, %cl.