`testl` eax against eax?

maxpenguin picture maxpenguin · Sep 29, 2008 · Viewed 80.5k times · Source

I am trying to understand some assembly.

The assembly as follows, I am interested in the testl line:

000319df  8b4508        movl   0x08(%ebp), %eax  
000319e2  8b4004        movl   0x04(%eax), %eax  
000319e5  85c0          testl  %eax, %eax  
000319e7  7407          je     0x000319f0  

I am trying to understand that point of testl between %eax and %eax? I think the specifics of what this code isn't important, I am just trying to understand the test with itself - wouldn't the value always be true?

Answer

Chris Jester-Young picture Chris Jester-Young · Sep 29, 2008

It tests whether eax is 0, or above, or below. In this case, the jump is taken if eax is 0.