Jump to content

How can I tell how large my program is?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
jcampos8782

jcampos8782

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
I am not sure this is the right spot to ask but I don't know which section to post in. I use objdump -d option and I get this:


Jason@Jason-Notebook ~/cs47/subfac

$ objdump -d subfac.o


subfac.o:     file format pe-i386



Disassembly of section .text:


00000000 <_subfac>:

   0:   55                      push   %ebp

   1:   89 e5                   mov    %esp,%ebp

   3:   31 d2                   xor    %edx,%edx

   5:   4a                      dec    %edx

   6:   31 c9                   xor    %ecx,%ecx

   8:   31 c0                   xor    %eax,%eax


0000000a <.start>:

   a:   f7 da                   neg    %edx

   c:   0f af c1                imul   %ecx,%eax

   f:   01 d0                   add    %edx,%eax

  11:   41                      inc    %ecx

  12:   3b 4d 08                cmp    0x8(%ebp),%ecx

  15:   7e f3                   jle    a <.start>

  17:   5d                      pop    %ebp

  18:   c3                      ret

  19:   90                      nop

  1a:   90                      nop

  1b:   90                      nop


Are the hex numbers to the left the size of the program thus size is 1b bytes? Also... this is a question I should ask in the ASM forum but I am guessing a few of you might be able to answer... how the heck can I get rid of those no operation instructions? Here is my ASM:


	.file	"subfac.c"

.globl _subfac

	.def	_mull;	.scl	2;	.type	32;	.endef

_subfac:

	push	%ebp

	movl	%esp, %ebp

	xorl	%edx, %edx					# (-1)^n

	decl	%edx

	xorl	%ecx, %ecx					# iterator

	xorl	%eax, %eax					# zero out the total


	.start:

		negl	%edx					# (-1)^n

		imul	%ecx, %eax				# n * subfac(n-1)

		addl	%edx, %eax				# [ (-1)^n + n*subfac(n-1)] 

		incl	%ecx					# increment ecx

		cmp		8(%ebp), %ecx			# i < n? 

		jle		.start


	pop %ebp

	ret




#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
The NOPs are used for aligning things, e.g. programs' sections to page boundaries. This makes it easier for the operating system to swap them out, so in most cases it'll actually make them faster. Try turning on optimizations for size and see if anything happens. Note that your program may suffer speed losses.
sudo rm -rf /

#3
jcampos8782

jcampos8782

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
Ah ok...

As far as optimizing size, this is a homework assignment and the teacher asked us to try to see how small we could make the program so using some sort of compiler optimization is off limits.

So the only question left to answer is, are the hex numbers to the side of the dump show the size? In other words, is my program (not including the nop) 0x18 bytes?

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
The hex numbers on the far left are the offset into the section; you need to take the length of the final instruction into account, so your program size is actually 0x19 bytes. If the last instruction were three bytes, then your program would be 0x1b bytes, and so on.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users