News:

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

Main Menu

Making Sure Code is Self Contained

Started by Evan, November 28, 2013, 03:04:11 PM

Previous topic - Next topic

Evan

What is the difference between
"end start"
and
"exit"
?

I assume I need them both.

dedndave

"end" tells the assembler where the end of code text is
"end start" also tells the assembler/linker where the program entry point is

"exit" is a macro that actually terminates the program at run-time
it generates code similar to
    INVOKE  ExitProcess,0

Evan

"end start" also tells the assembler/linker where the program entry point is
I don't understand. Why do we report the entry point at the end?
Is it so the computer is back where it started before the program was started?



masm32\tutorial\console\demo1\hello.asm
end start                       ; Tell MASM where the program ends

jj2007

Quote from: Evan on November 28, 2013, 04:20:00 PM
I don't understand. Why do we report the entry point at the end?

You have to press the Start button to shutdown your system. It's Microsoft logic 8)

Jokes apart: You don't have to use "start:". For example, this is valid, too:

.code
start:
  MsgBox 0, "You won't see me, hehe", "Oh no..", MB_OK
MyMain proc
  nop
  invoke ExitProcess, 0
MyMain endp
end MyMain


Guess what happens if you replace end MyMain with end start?

hutch--

Evan,

There is probably a bit of terminology wander here. An assembler is not trying to be smart, they are in fact incredibly dumb and need to be told exactly where to start and finish the code section. As long as you don't forward reference some things, MASM ready data, constants and code from top to bottom of a source file so you need to tell it where the start and finish of the code section are.

Now as Dave has mentioned, you can use any name you like as long as its not a reserve word but "start:" is the ordinary convention. When MASM finds the first label in the section marked ".CODE" it then proceeds to add the content to the binary code of the module, it keeps going until it finds notification that the code is to end, thus "end start". What you will find is that after the "end start" MASM ignores anything else.

dedndave

it's simple, really

the END directive tells the assembler that it has reached the end of valid assembly language text
anything after that should be ignored
some older versions of MASM may not have ignored text that followed the END directive, though - lol
(that was a bug in version 3, i think)

the END directive may also be used to tell the assembler and linker where code execution is to begin
the program may not start at the first line of code when it is executed, as Jochen demonstrated
this option is only valid for programs
for some assembler files, the END directive will have no entry point label
for example, if you write an object module that has PROC's and/or DATA
there is no entry point, as the code is executed by use of a specified CALL label

i can understand the confusion...
why put the execution entry point in the END directive ?
well - they didn't really have to do it that way
they could have provided some other directive for the programmer to name the entry label
but, that's how it was done with MASM   :biggrin:

hamper

Hi Evan, and welcome to the forum.

.code

This is a segment directive to the assembler. It tells the assembler where the start of the executable code segment of the program begins. The very next line in your source code should consist only of a label, and the following one is traditional...

start:

The label start: signifies the starting point of the program. A label is mandatory, but it doesn't have to be called start: You can call it whatever you wish, but start: is traditional, and most example programs you will see all use it.

Thus, so far you have told the assembler where the code segment begins (.code), and where the start of the actual program begins (start:).

...
Now you write all of your program code
...

end start

A mandatory end statement signifies the end of the program, and also provides as its argument the starting address (starting point) of the program, i.e. the label start. Note that a label has a colon on the end when it is used to simply indicate a position within your code, but does not have a trailing colon when that name is actually called. The end start statement must be the very last statement of the program - only comments can follow. Everything after end start is ignored by the assembler (comments are only for your use anyway).

Hope that helps



Magnum

Welcome.

Tasm code did things a little differently.

Andy


; life.asm Originally written by Vladislav Kaipetsky and Tenie Remmel
;          Saturday, August 17, 2013 Modification ideas by Gunther,Steve,
.model small
.586
.stack 200h

.data

Vesa_Err db "Can not set Vesa mode !",0

.code

Start:     

SETUP101:       ; Initialize for mode 101, 640 x 480 x 256 colors

mov      ax,@data
mov      ds,ax

MOV     AH,4FH          ; VESA functions
MOV     AL,2            ; Set Video mode
MOV     BX,101h      ; = video mode
INT     10H
                 
End Start

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

MichaelW

While specifying the entry point with the END directive is probably the easiest method and probably the method that Microsoft intended you use, there are alternatives. One is to define a suitable label, make it visible to the linker with the PUBLIC directive, then specify it as the entry point on the linker command line with the Entry option.

\masm32\bin\link /ENTRY:start ...


include \masm32\include\masm32rt.inc
.code
public start
start:
    push 5000
    call Sleep
    push 0
    call ExitProcess
end

Well Microsoft, here's another nice mess you've gotten us into.

hutch--

I have split this topic so that the new member was not going to be confused with the range of debate over a number of technical issues. The split topic is in the Workshop.

TWell

Is Code Self Contained if there is line ?include \masm32\include\masm32rt.inc

Magnum

Masm32rt.inc saves you a lot of typing by containing most includes and libraries that you generally need.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org