• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

MinGW 4.7.1 GDB disassembly output

2 posts in this topic

Hello all, quick question for those that are intimately familiar with disassembling c++ programs (I for one am not, though would like to be)

I wrote a few simple programs to test gdb and its disassemble command and noticed that for one of programs the output seemed a bit verbose. Here is the two programs with assembly output attached.

#include <iostream>
#include "math.hpp"
int main(int, char**)
std::cout << math::sign(1) << std::endl;
return 0;

Dump of assembler code for function main(int, char**):
0x0000000000401500 <+0>: push %rbp
0x0000000000401501 <+1>: push %r15
0x0000000000401503 <+3>: push %r14
0x0000000000401505 <+5>: push %r13
0x0000000000401507 <+7>: push %r12
0x0000000000401509 <+9>: push %rdi
0x000000000040150a <+10>: push %rsi
0x000000000040150b <+11>: push %rbx
0x000000000040150c <+12>: sub $0x148,%rsp
0x0000000000401513 <+19>: lea 0x80(%rsp),%rbp
0x000000000040151b <+27>: movaps %xmm6,0x20(%rbp)
0x000000000040151f <+31>: movaps %xmm7,0x30(%rbp)
0x0000000000401523 <+35>: movaps %xmm8,0x40(%rbp)
0x0000000000401528 <+40>: movaps %xmm9,0x50(%rbp)
0x000000000040152d <+45>: movaps %xmm10,0x60(%rbp)
0x0000000000401532 <+50>: movaps %xmm11,0x70(%rbp)
0x0000000000401537 <+55>: movaps %xmm12,0x80(%rbp)
0x000000000040153f <+63>: movaps %xmm13,0x90(%rbp)
0x0000000000401547 <+71>: movaps %xmm14,0xa0(%rbp)
0x000000000040154f <+79>: movaps %xmm15,0xb0(%rbp)
0x0000000000401557 <+87>: mov %ecx,0x110(%rbp)
0x000000000040155d <+93>: mov %rdx,0x118(%rbp)
0x0000000000401564 <+100>: lea 0x1b15(%rip),%rax # 0x403080 <__gxx_personality_sj0>
0x000000000040156b <+107>: mov %rax,-0x30(%rbp)
0x000000000040156f <+111>: lea 0x9faa(%rip),%rax # 0x40b520 <___DTOR_LIST__+16>
0x0000000000401576 <+118>: mov %rax,-0x28(%rbp)
0x000000000040157a <+122>: lea -0x20(%rbp),%rax
0x000000000040157e <+126>: lea 0x20(%rbp),%rdx
0x0000000000401582 <+130>: mov %rdx,(%rax)
0x0000000000401585 <+133>: lea 0x5a(%rip),%rdx # 0x4015e6 <__fu0__ZSt4cout+34>
0x000000000040158c <+140>: mov %rdx,0x8(%rax)
0x0000000000401590 <+144>: mov %rsp,0x10(%rax)
0x0000000000401594 <+148>: lea -0x60(%rbp),%rax
0x0000000000401598 <+152>: mov %rax,%rcx
0x000000000040159b <+155>: callq 0x404880 <_Unwind_SjLj_Register>
0x00000000004015a0 <+160>: callq 0x4042f0 <__main>
0x00000000004015a5 <+165>: movl $0x1,0x1c(%rbp)
0x00000000004015ac <+172>: lea 0x1c(%rbp),%rax
0x00000000004015b0 <+176>: mov %rax,%rcx
0x00000000004015b3 <+179>: callq 0x409ad0 <math::sign<int>(int const&)>
0x00000000004015b8 <+184>: movl $0x1,-0x58(%rbp)
0x00000000004015bf <+191>: mov %eax,%edx
0x00000000004015c1 <+193>: lea 0x110cc(%rip),%rcx # 0x412694 <__imp__ZSt4cout>
0x00000000004015c8 <+4>: callq 0x403090 <_ZNSolsEi>
0x00000000004015cd <+9>: lea 0x1ab4(%rip),%rdx # 0x403088 <_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_>
0x00000000004015d4 <+16>: mov %rax,%rcx
0x00000000004015d7 <+19>: callq 0x403098 <_ZNSolsEPFRSoS_E>
0x00000000004015dc <+24>: mov $0x0,%eax
0x00000000004015e1 <+29>: mov %eax,0xc(%rbp)
0x00000000004015e4 <+32>: jmp 0x4015fd <__fu0__ZSt4cout+57>
0x00000000004015e6 <+34>: lea -0x20(%rbp),%rbp
0x00000000004015ea <+38>: mov -0x50(%rbp),%rax
0x00000000004015ee <+42>: movl $0xffffffff,-0x58(%rbp)
0x00000000004015f5 <+49>: mov %rax,%rcx
0x00000000004015f8 <+52>: callq 0x404c40 <_Unwind_SjLj_Resume>
0x00000000004015fd <+57>: lea -0x60(%rbp),%rax
0x0000000000401601 <+61>: mov %rax,%rcx
0x0000000000401604 <+64>: callq 0x4048e0 <_Unwind_SjLj_Unregister>
0x0000000000401609 <+69>: mov 0xc(%rbp),%eax
0x000000000040160c <+72>: movaps 0x20(%rbp),%xmm6
0x0000000000401610 <+76>: movaps 0x30(%rbp),%xmm7
0x0000000000401614 <+80>: movaps 0x40(%rbp),%xmm8
0x0000000000401619 <+85>: movaps 0x50(%rbp),%xmm9
0x000000000040161e <+90>: movaps 0x60(%rbp),%xmm10
0x0000000000401623 <+95>: movaps 0x70(%rbp),%xmm11
0x0000000000401628 <+100>: movaps 0x80(%rbp),%xmm12
0x0000000000401630 <+108>: movaps 0x90(%rbp),%xmm13
0x0000000000401638 <+116>: movaps 0xa0(%rbp),%xmm14
0x0000000000401640 <+124>: movaps 0xb0(%rbp),%xmm15
0x0000000000401648 <+132>: add $0x148,%rsp
0x000000000040164f <+139>: pop %rbx
0x0000000000401650 <+140>: pop %rsi
0x0000000000401651 <+141>: pop %rdi
0x0000000000401652 <+142>: pop %r12
0x0000000000401654 <+144>: pop %r13
0x0000000000401656 <+146>: pop %r14
0x0000000000401658 <+148>: pop %r15
0x000000000040165a <+150>: pop %rbp
0x000000000040165b <+151>: retq
End of assembler dump.

#include <iostream>
#include "math.hpp"
int main(int, char**)
int x = math::sign(1);
std::cout << x << std::endl;
return 0;
Dump of assembler code for function main(int, char**):
0x0000000000401500 <+0>: push %rbp
0x0000000000401501 <+1>: mov %rsp,%rbp
0x0000000000401504 <+4>: sub $0x30,%rsp
0x0000000000401508 <+8>: mov %ecx,0x10(%rbp)
0x000000000040150b <+11>: mov %rdx,0x18(%rbp)
0x000000000040150f <+15>: callq 0x4041e0 <__main>
0x0000000000401514 <+20>: movl $0x1,-0x8(%rbp)
0x000000000040151b <+27>: lea -0x8(%rbp),%rax
0x000000000040151f <+31>: mov %rax,%rcx
0x0000000000401522 <+34>: callq 0x4099c0 <math::sign<int>(int const&)>
0x0000000000401527 <+39>: mov %eax,-0x4(%rbp)
0x000000000040152a <+42>: mov -0x4(%rbp),%eax
0x000000000040152d <+45>: mov %eax,%edx
0x000000000040152f <+47>: lea 0x1115e(%rip),%rcx # 0x412694 <__imp__ZSt4cout>
0x0000000000401536 <+4>: callq 0x402f78 <_ZNSolsEi>
0x000000000040153b <+9>: lea 0x1a2e(%rip),%rdx # 0x402f70 <_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_>
0x0000000000401542 <+16>: mov %rax,%rcx
0x0000000000401545 <+19>: callq 0x402f80 <_ZNSolsEPFRSoS_E>
0x000000000040154a <+24>: mov $0x0,%eax
0x000000000040154f <+29>: add $0x30,%rsp
0x0000000000401553 <+33>: pop %rbp
0x0000000000401554 <+34>: retq
End of assembler dump.

So basically I am confused as to why using a temporary variable in this case produces less assembly code?
If any more information is needed please don't hesitate to ask :)


Share this post

Link to post
Share on other sites
Are you sure the optimization settings are the same? For some reason it seems to "back up" all the registers to the stack and then restore them at the end in the first version.

Edit: in the first not the second version... Edited by japro

Share this post

Link to post
Share on other sites
Both programs are built with the same flags:
[quote]gcc test/test1.cpp -o bin/test1.exe -I include -Wall -Wextra -g -std=c++11 -lstdc++[/quote]

No "explicit" optimization is being done, and I am passing the -g flag for debug symbols. One moment I will try compiling with optimization for both programs.

both programs with the flag -g removed and the flag -Os (or -O1) produce the same assembly, so this is probably something to do with the debugging flag? -g it also reduces the assembly down to like 3~4 lines.

EDIT2: just checked without optimization and the debugging flag, its a similar story to the OP. Edited by roadysix

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0