The GNU Assembler "test" instruction

Stuck with a problem in your code? Seek help here.

The GNU Assembler "test" instruction

Postby evansste » February 1st, 2016, 4:41 pm

I'm learning how to write assembly language programs and have run into a little snag.

I'm trying to get the "test" instruction to work with memory addressing. Along the way, I've found something that seems a bit strange.

When I try to compile this program:
Code: Select all
.section .data
A:
    .int 0xE7C6E069, 0x09AA3796
.section .text
.globl _start
_start:   
   movl $A, %eax   
   and $0x0000007F, (%eax)
   and $0x00000080, (%eax)
   test $0x0000007F, (%eax)
   test $0x00000080, (%eax)


I receive the following error messages:
Code: Select all
evansste@evansste-desktop:~$ as -o test.o test.s
test.s: Assembler messages:
test.s:9: Error: no instruction mnemonic suffix given and no register operands; can't size instruction
test.s:10: Error: no instruction mnemonic suffix given and no register operands; can't size instruction
test.s:11: Error: no instruction mnemonic suffix given and no register operands; can't size instruction


Why won't the "test" operation work? As you can see, the "and" operation works, but only with the $0x0000007F value (no error on line 8).

Based on the book I've been reading, the "and" and "test" operations work in exactly the same manner. The only difference is that the "test" operator doesn't store a result in the destination. It leaves the value unchanged. So why does the "and" operator give no error message, when evaluating $0x0000007F, but the "test'" operation gives an error message regardless of either value?

Because $0x0000007F is = 127, I'm guessing the error, with the "and" operation, has something to do with a limitation when 128 is evaluated. But why would there be a problem? Doesn't the "and" operator perform a bit-wise calculation against the source and destination values? If so, no sort of overflow should apply.

If anyone has experience with the GNU Assembler, and is familiar with assembly language, then I'd greatly value your input.

Thanks for your time.
evansste
 
Posts: 98
Joined: October 8th, 2014, 8:19 am

Re: The GNU Assembler "test" instruction

Postby evansste » February 1st, 2016, 4:54 pm

Never mind. I just found out what I was doing wrong.

Apparently, you have to give the length of the data that you're using, when using "and" and "test" instructions.

For instance, The program should look like this:
Code: Select all
.section .data
A:
   .int 0xE7C6E069, 0x09AA3796
.section .text
.globl _start
_start:   
   movl $A, %eax   
   andl $0x0000007F, (%eax)
   andl $0x00000080, (%eax)
   testl $0x0000007F, (%eax)
   testl $0x00000080, (%eax)


Notce the "l" at the end of each instruction (andl instead of and).

The book, that I'm reading, uses this in different examples, but never when using the "and" and "test" instructions. For instance, he uses it with "movl", but never with the logical operations.

Anyway, I just found this solution after posting my question. In any case, thanks for your attention.
evansste
 
Posts: 98
Joined: October 8th, 2014, 8:19 am


Return to Help Me! Software

Who is online

Users browsing this forum: No registered users and 1 guest