News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

The smallest executable

Started by frktons, January 17, 2013, 09:29:34 AM

Previous topic - Next topic

Vortex

Creating small executables is interesting also while working with HLLs.

Gunther

Quote from: Vortex on January 18, 2013, 06:14:16 AM
Creating small executables is interesting also while working with HLLs.

But the EXE files generated by compilers are not so small.

Gunther
You have to know the facts before you can distort them.

jj2007

Quote from: Gunther on January 18, 2013, 07:36:05 AM
But the EXE files generated by compilers are not so small.

Erol is a genius, he can produce a 1.5k C executable. The problem with such tiny programs is that a) they can't fill a hard drive sector (4k) and b) they don't do anything useful (but wait until Alex logs in :lol:)

frktons

I've done some refinement to the code, and got rid of about
20 instructions, sparing some 50-60 bytes, but still not sufficient
to reduce the size to 2K. It's actually fixed at 2,5K.

I've seen that there is a lot of space for size reduction, so the 2K
goal is quite feasible.

Attached the shrinked version 0.4.

Frank
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

frktons

In order to get rid of the .data section altogether, I need
to transform this line of .data:

ConTitle  db " -----------   **  Extended ASCII chart displayable characters  **  ----------", 0


in a line of LOCAL to put inside the PROC that uses it.

I have no clue how to do it. Any help is welcome.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

it doesn't need to be local
what you want is to put it in the code section

if you did want it to be local, you could push it onto the stack in reverse order - very clumsy

frktons

Quote from: dedndave on January 18, 2013, 05:01:21 PM
it doesn't need to be local
what you want is to put it in the code section

if you did want it to be local, you could push it onto the stack in reverse order - very clumsy

I want to put it in the .code section, but I don't know how.
How I define it, where I put these bytes?
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

stick it any place you like, really - someplace where it won't be executed   :P
DisplaySequence ENDP

ConTitle  db " -----------   **  Extended ASCII chart displayable characters  **  ----------", 0

; -------------------------------------------------------------------------
; Writes the Screen Title with enhanced color attribute White on Magenta
;--------------------------------------------------------------------------

WriteScreenTitle PROC


as a matter of practice, i try to define things earlier in the source than where i use them
that isn't always practical

frktons

Quote from: dedndave on January 18, 2013, 05:18:22 PM
stick it any place you like, really - someplace where it won't be executed   :P
DisplaySequence ENDP

ConTitle  db " -----------   **  Extended ASCII chart displayable characters  **  ----------", 0

; -------------------------------------------------------------------------
; Writes the Screen Title with enhanced color attribute White on Magenta
;--------------------------------------------------------------------------

WriteScreenTitle PROC


as a matter of practice, i try to define things earlier in the source than where i use them
that isn't always practical

In this way the .data section is not created? Because this is my goal here.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

if there is nothing left in the .DATA section, don't use .DATA and it won't be created

frktons

Quote from: dedndave on January 18, 2013, 05:24:53 PM
if there is nothing left in the .DATA section, don't use .DATA and it won't be created

OK, good.  :t My .data section is empty and deleted from the program,
but nothing changes in the size of the prog. 2,560 bytes  ::)
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

frktons

The prog without the .data section attached. Anyone can see where I can
save some other bytes?

There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

jj2007

DisplayFmt PROC szFmtName:DWORD
LOCAL rc:SMALL_RECT
  movlps xmm0, windowSize        ; make a copy
  movlps rc, xmm0
  INVOKE WriteConsoleOutput, wHnd, szFmtName, DWORD PTR bufferSize,
  DWORD PTR startPoint, addr rc                ; offset windowSize crashes the app
  ret
DisplayFmt ENDP

sinsi

Quote from: sinsi on January 17, 2013, 05:52:27 PM
If they don't change then put them in .code
Of course, some APIs will expect to write to it...

Quote from: jj2007 on January 18, 2013, 08:03:05 PMoffset windowSize crashes the app

Quote from: MSDNlpWriteRegion [in, out]
A pointer to a SMALL_RECT structure. On input, the structure members specify the upper-left and lower-right coordinates of the console screen buffer rectangle to write to. On output, the structure members specify the actual rectangle that was used.

🍺🍺🍺

jj2007

Quote from: sinsi on January 18, 2013, 09:15:50 PMOn output,

Indeed, see movlps above. Strange that it apparently did not crash on Frank's machine.