Advertisement
Guest User

uint16 gcc 5.1 bug?

a guest
Jul 7th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. // gcc -O0 -m32 -march=i586 -mtune=i586 -o foo foo.c
  2.  
  3. #include <stdint.h>
  4.  
  5. static volatile uint16_t foo = 6;
  6. static uint16_t start = 4;
  7.  
  8. uint16_t get_foo(void)
  9. {
  10.   return foo;
  11. }
  12.  
  13. int main(void)
  14. {
  15.   uint16_t diff = (get_foo() - start) + 1;
  16.  
  17.   return 0;
  18. }
  19.  
  20.  
  21.  
  22.  
  23. // objdump -d foo
  24. 080483cb <get_foo>:
  25.  80483cb:   55                      push   %ebp
  26.  80483cc:   89 e5                   mov    %esp,%ebp
  27.  80483ce:   66 a1 a8 96 04 08       mov    0x80496a8,%ax
  28.  80483d4:   5d                      pop    %ebp
  29.  80483d5:   c3                      ret    
  30.  
  31. 080483d6 <main>:
  32.  80483d6:   55                      push   %ebp
  33.  80483d7:   89 e5                   mov    %esp,%ebp
  34.  80483d9:   83 ec 10                sub    $0x10,%esp
  35.  80483dc:   e8 ea ff ff ff          call   80483cb <get_foo>
  36.  80483e1:   89 c2                   mov    %eax,%edx
  37.  80483e3:   66 a1 aa 96 04 08       mov    0x80496aa,%ax
  38.  80483e9:   29 c2                   sub    %eax,%edx
  39.  80483eb:   89 d0                   mov    %edx,%eax
  40.  80483ed:   40                      inc    %eax
  41.  80483ee:   66 89 45 fe             mov    %ax,-0x2(%ebp)
  42.  80483f2:   b8 00 00 00 00          mov    $0x0,%eax
  43.  80483f7:   c9                      leave  
  44.  80483f8:   c3                      ret    
  45.  80483f9:   66 90                   xchg   %ax,%ax
  46.  80483fb:   66 90                   xchg   %ax,%ax
  47.  80483fd:   66 90                   xchg   %ax,%ax
  48.  80483ff:   90                      nop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement