Author Topic: The smallest executable  (Read 38256 times)

nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: The smallest executable
« Reply #15 on: January 17, 2013, 12:10:02 PM »
Code: [Select]
/MERGE:.data=.textthe AV scanners will love this one   :lol:

Quote
Regarding the Text File Compressor and Scanner I'm collecting
the one thousand PROC I need,

hence the library then

Quote
if it is considered an impossible task it has to mean something

not impossible, but difficult -- if there is a will there is usually a way

Quote
the project is quite complex to manage in Assembly

true

Quote
I'm quite slow

perfection takes time  :P

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7542
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: The smallest executable
« Reply #16 on: January 17, 2013, 12:17:00 PM »
 :biggrin:

> Hutch barks at me every time - but, he probably likes you more than me

Yeah yeah, teach people bad habits so they write garbage.  :P (But HAY, it was really host stuff on an i386SX under MS-DOS)
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

frktons

  • Member
  • ***
  • Posts: 491
Re: The smallest executable
« Reply #17 on: January 17, 2013, 12:30:05 PM »
Code: [Select]
/MERGE:.data=.textthe AV scanners will love this one   :lol:

Quote
Regarding the Text File Compressor and Scanner I'm collecting
the one thousand PROC I need,

hence the library then

Quote
if it is considered an impossible task it has to mean something

not impossible, but difficult -- if there is a will there is usually a way

Quote
the project is quite complex to manage in Assembly

true

Quote
I'm quite slow

perfection takes time  :P


1] Yes
2] Yes
3] Yes
4] Yes
5] Yes

well I can say I couldn't agree more  :lol:

frktons

  • Member
  • ***
  • Posts: 491
Re: The smallest executable
« Reply #18 on: January 17, 2013, 12:50:55 PM »
Well, I tried Dave's suggestion, but something went wrong.
Code: [Select]
.data
    windowSize SMALL_RECT <0,79,0,24>
    bufferSize COORD      <80,25>
    startPoint COORD      <0,0>

so I got rid of these code:

Code: [Select]
    mov windowSize.Left, 0
    mov windowSize.Right, 79
    mov windowSize.Top, 0
    mov windowSize.Bottom, 24

   

    mov bufferSize.x, 80
    mov bufferSize.y, 25


    mov startPoint.x, 0
    mov startPoint.y, 0

But the console is displayed black, with nothing inside.  :icon_rolleyes:

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #19 on: January 17, 2013, 12:51:56 PM »
from the movie "Mission Impossible II"
Quote
This isn't Mission Difficult, it's Mission Impossible. "Difficult" should be a walk in the park for you.

the order for SMALL_RECT members is Left, Top, Right, Bottom   :P
Code: [Select]
windowSize SMALL_RECT <0,0,79,24>
put this one in uninitialized data - it will be filled with 0's
Code: [Select]
startPoint COORD      <>

frktons

  • Member
  • ***
  • Posts: 491
Re: The smallest executable
« Reply #20 on: January 17, 2013, 01:07:31 PM »
from the movie "Mission Impossible II"
Quote
This isn't Mission Difficult, it's Mission Impossible. "Difficult" should be a walk in the park for you.

the order for SMALL_RECT members is Left, Top, Right, Bottom   :P
Code: [Select]
windowSize SMALL_RECT <0,0,79,24>
put this one in uninitialized data - it will be filled with 0's
Code: [Select]
startPoint COORD      <>

I suspected it, about the walk in the park I mean  :lol:

Yes Master Dave, that's the correct order. Anyway, and I suspected it
as well, no gain at all in the exe size: still 2,560 bytes.
But at least it works again  :P

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #21 on: January 17, 2013, 01:13:14 PM »
well - each section is allocated in 512 byte chunks, as i recall
so, you have to get down to the next 512-byte step to notice an improvement

that line was from the character played by Anthony Hopkins
it wasn't the greatest movie, but he's always good
not as great of an actor as everyone may say - he's a bit one-dimensional, actually
i still like him
he made a good Hannibal - lol
« Last Edit: January 17, 2013, 05:29:55 PM by dedndave »

frktons

  • Member
  • ***
  • Posts: 491
Re: The smallest executable
« Reply #22 on: January 17, 2013, 01:16:10 PM »
well - you each section is allocated in 512 byte chunks, as i recall
so, you have to get down to the next 512-byte step to notice an improvement

that line was from the character played by Anthony Hopkins
it wasn't the greatest movie, but he's always good
not as great of an actor as everyone may say - he's a bit one-dimensional, actually
i still like him
he made a good Hannibal - lol

That was my suspect  ;)
I like Anthony Hopkins as well, a nice English styled actor  :t
and yes He is a bit one-dimensional

jj2007

  • Member
  • *****
  • Posts: 10547
  • Assembler is fun ;-)
    • MasmBasic
Re: The smallest executable
« Reply #23 on: January 17, 2013, 05:17:23 PM »
.data?
windowSize SMALL_RECT <>
windowRSize RECT <>
.code
   mov windowSize.Left, 127   ; 9
   m2m windowSize.Left, 127   ; 11
   add windowSize.Left, 127   ; 8

   mov windowRSize.left, 127   ; 10
   m2m windowRSize.left, 127   ; 8
   add windowRSize.left, 127   ; 7
 ;)

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #24 on: January 17, 2013, 05:32:10 PM »
Code: [Select]
    .data
windowSize SMALL_RECT <0,0,79,24>  ;8
bufferSize COORD      <80,25>      ;4

total clock cycles = 0

 ;)

sinsi

  • Guest
Re: The smallest executable
« Reply #25 on: January 17, 2013, 05:52:27 PM »
Code: [Select]
    .data
windowSize SMALL_RECT <0,0,79,24>  ;8
bufferSize COORD      <80,25>      ;4

total clock cycles = 0

 ;)
If they don't change then put them in .code
Of course, some APIs will expect to write to it...

frktons

  • Member
  • ***
  • Posts: 491
Re: The smallest executable
« Reply #26 on: January 17, 2013, 08:17:29 PM »
.data?
windowSize SMALL_RECT <>
windowRSize RECT <>
.code
   mov windowSize.Left, 127   ; 9
   m2m windowSize.Left, 127   ; 11
   add windowSize.Left, 127   ; 8

   mov windowRSize.left, 127   ; 10
   m2m windowRSize.left, 127   ; 8
   add windowRSize.left, 127   ; 7
 ;)

Thanks Jochen, good to know :t

Code: [Select]
    .data
windowSize SMALL_RECT <0,0,79,24>  ;8
bufferSize COORD      <80,25>      ;4

total clock cycles = 0

 ;)

Yes Dave, the most compact and fast should be like that.  :biggrin:


If they don't change then put them in .code
Of course, some APIs will expect to write to it...

Don't understand why to put them in .code.  ::)

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #27 on: January 17, 2013, 11:35:02 PM »
if you merge sections at link-time, the advantage of putting it in the code section is gone
but, the idea is to reduce one section so that the 512-byte step is met

if you spend time on the code, you can probably get the EXE down to 1.5 kb   :P

almost everything you had in the .DATA section (except for the string) could be an EQUate
Code: [Select]
.data

ConTitle  db " -----------   **  Extended ASCII chart displayable characters  **  ----------", 0
PtrConTitle DWORD ConTitle + 17  ; Points to "  Extended..." part of ConTitle

NewProcSize DWORD FromPoint - ToPoint

inpbyte   DWORD  1

;----------------------------------------------------------------------
; ASCII chars to draw a simple box
;----------------------------------------------------------------------

    TopLeft      db   218
    TopRight     db   191
    BottomLeft   db   192
    BottomRight  db   217
    HorizLine    db   196
    VerticLine   db   179

;----------------------------------------------------------------------

    Unit     BYTE One
    Ten      BYTE Space
    Hundred  BYTE Space
    EndOfTask  BYTE 0

    AsciiCode  DWORD 205F2000H  ; 4 bytes = 1 CHAR_INFO
                                ; char 1 White on Magenta Attribute

your string is not modified, as it exists in .DATA
so, you could take sinsi's suggestion....
put the string and the structures we mentioned in the .CODE section
that would eliminate the .DATA section, altogether
you cannot modify data that you place in the .CODE section
at least, not without changing the section attribute - probably not a good practice

the .DATA? section consumes no space in the EXE, other than the entries to create the section   :P

after that, there are several little things, here and there
look at the disassembled code to see how many bytes things use
Code: [Select]
    lea  eax, ConsoleScreen
    add  eax, TitleStartPoint
Code: [Select]
    mov     eax,offset ConsoleScreen+TitleStartPoint

frktons

  • Member
  • ***
  • Posts: 491
Re: The smallest executable
« Reply #28 on: January 18, 2013, 05:17:51 AM »
We are moving aside and far away from my first intention,
that was to know something about switches and parameters
used by assemblers/linkers to reduce the size of an executable.

When I created this small program a couple of years ago, it was
a challenge to reduce 12k size of a prog and its file, to something
less, and the result was a prog that can be assembled and linked
in 2.5K, which means about 80% less than the original.

But we are now in the compressor time so let's move forward and see
if we can shrink it from 2.5K to 2K or less.

Another nice deviation that stays inside the "compressing matter"
anyway.  :lol:

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #29 on: January 18, 2013, 05:43:38 AM »
still, these should be made into EQUates - no need for all that data
Code: [Select]
PtrConTitle DWORD ConTitle + 17  ; Points to "  Extended..." part of ConTitle

NewProcSize DWORD FromPoint - ToPoint

inpbyte   DWORD  1

;----------------------------------------------------------------------
; ASCII chars to draw a simple box
;----------------------------------------------------------------------

    TopLeft      db   218
    TopRight     db   191
    BottomLeft   db   192
    BottomRight  db   217
    HorizLine    db   196
    VerticLine   db   179

;----------------------------------------------------------------------

    Unit     BYTE One
    Ten      BYTE Space
    Hundred  BYTE Space
    EndOfTask  BYTE 0

    AsciiCode  DWORD 205F2000H  ; 4 bytes = 1 CHAR_INFO
                                ; char 1 White on Magenta Attribute
the first one, you have already done - you can probably get rid of it

it's also likely to reduce the code size
Code: [Select]
    mov     al,TopLeft
    mov     [edx],al
as an EQUate...
Code: [Select]
    mov byte ptr [edx],TopLeft