Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The END directive in assembly language

I am new to assembly language and wrote this code:

main PROC

    mov eax,10000h          ; Eax=10000h
    add eax,40000h          ; Eax=50000h
    sub eax,20000h          ; Eax=30000h
    call DumpRegs

    exit
    main ENDP
END main

I wanted to know why do you really need to put "main ENDP" and "end main" twice over? I am only using one procedure but seem to be ending this procedure twice.

Is there a better way to write this if you are only using one procedure?

like image 655
user3307068 Avatar asked Mar 18 '14 17:03

user3307068


2 Answers

The END main marks the end of the file, specifying an entry point for your program (this is optional). The main ENDP denotes the end of your procedure.

I am not aware of a way to merge the two.

like image 189
Jester Avatar answered Oct 03 '22 11:10

Jester


The Assembler needs

END ____

directive for END OF FILE command. That's END OF FILE. Here as you are using "main", you have to end it with

END MAIN

Simply know that the Assembler needs END directive to end the file. END can be written without Main. just end the file with END.

Now, ENDP denotes END OF PROCEDURE. here procedure id "main". So, before ending the file,End the "main" procedure. You have to end the procedure!

To answer the last part of answer,it looks to you that you are doing same thing twice Because you are ending file and procedure with "main". MAIN is the Procedure name and

Main ENDP
  End
is totally fine.
like image 21
Bhartendu Kumar Avatar answered Oct 03 '22 10:10

Bhartendu Kumar