Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question regarding disassembly output

Tags:

assembly

sparc

I have a very simple test routine:

void test()
{

  int a = 15;
  int b = 17;
  int c, d;


  c = a + b;
  d = a | c;
  printf("%d", d);
}

I generate then the object file and then I disassemly the object file to see the instruction word for the ADD and OR operations as follows:

 sparc-elf-objdump -d test.o 

The resulting disassemly looks as follows:

test.o:     file format elf32-sparc

Disassembly of section .text:

00000000 <test>:
   0:   11 00 00 00     sethi  %hi(0), %o0
   4:   90 12 20 00     mov  %o0, %o0   ! 0 <test>
   8:   92 10 20 2f     mov  0x2f, %o1
   c:   82 13 c0 00     mov  %o7, %g1
  10:   40 00 00 00     call  10 <test+0x10>
  14:   9e 10 40 00     mov  %g1, %o7
  18:   01 00 00 00     nop 

As you can see, their is neither an ADD instruction nor an OR instruction to find. Anyeone an idea why this is the case? Quite confusing...

Many thanks, Jim

like image 402
Jim Avatar asked Apr 12 '26 16:04

Jim


1 Answers

The compiler has optimized your code away -- only d is needed, and its value can be calculated at compile time.

like image 163
tgdavies Avatar answered Apr 15 '26 04:04

tgdavies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!