Oct 30, 2011

A problem; what is the difference between signed and unsigned ?

I was looking at the disassembled code of 2 programs compiled with gcc. In one program I initialised an unsigned variable and in the next program I initialised the same variable as signed.
That is the only difference between the two programs. But when I disassembled its object files there is no difference. Why it is so. Here is the two code files and its disassembled files.
unsigned.c
int main ( void )
{
  unsigned int a = -20;
  return 0;
}

signed.c

int main ( void )
{
  signed int a = -20;
  return 0;
}

And I compiled both gcc -o unsigned.o -c unsigned.c and gcc -o signed.o -c signed.c. After disassembling the two object files I got (objdump -d unsigned signed).

unsigned:     file format elf32-i386

Disassembly of section .text:

00000000
:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 10                sub    $0x10,%esp
   6:   c7 45 fc ec ff ff ff    movl   $0xffffffec,-0x4(%ebp)
   d:   83 45 fc 0a             addl   $0xa,-0x4(%ebp)
  11:   b8 00 00 00 00          mov    $0x0,%eax
  16:   c9                      leave
  17:   c3                      ret

signed:     file format elf32-i386

Disassembly of section .text:

00000000
:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 10                sub    $0x10,%esp
   6:   c7 45 fc ec ff ff ff    movl   $0xffffffec,-0x4(%ebp)
   d:   83 45 fc 0a             addl   $0xa,-0x4(%ebp)
  11:   b8 00 00 00 00          mov    $0x0,%eax
  16:   c9                      leave
  17:   c3                      ret

But even though in unsigned.c the variable is initialised as unsigned and in signed.c that is initialised as signed the disassembled code shows no difference. Then what is the point in initialising signed and unsigned. May be my perception is wrong. Any help appreciated.

For Web Developer

  open -a "Google Chrome" --args --disable-web-security