Hello everyone. I read a couple of tutorials on x86 assembly a while ago. It was made clear in these that certain instructions need to be included at the end of a program to make it close properly. However, there was some inconsistency about how a program should be terminated. Could anyone tell me how a process should be closed on a win32 system and is this proceedure OS specific? Thanks.

Steven.

see this thred for example. It is specific to 16-bit MS-DOS 6.X and earlier. Can't run it in 32-bit applications because int 21 instruction not allowed unless running in ring 0 as super user (os)

MOV AH,4CH ; return control to DOS
INT 21H

Hello everyone. I read a couple of tutorials on x86 assembly a while ago. It was made clear in these that certain instructions need to be included at the end of a program to make it close properly. However, there was some inconsistency about how a program should be terminated. Could anyone tell me how a process should be closed on a win32 system and is this proceedure OS specific? Thanks.

Steven.

There are three (3) different means of process termination on a Win32 system and all three are "proper" or valid.

The first (most common) method is: any thread in the process can make a call to the ExitProcess function.

The second (should be avoided) method is that another process (e.g. application, process explorer) makes a call to the Terminate Process function passing as a parameter the process handle for the application being terminated.

The third (rare) method is when all the threads in a process simply die on their own {e.g. they all call the ExitThread function} leaving the process with no reason to exist so the OS kills the process. NOTE: Since every process has at least one thread....if you do not indulge in any multithreading code {i.e. make calls to CreateThread}, then ExitThread is synonimous with ExitProcess.

is this proceedure OS specific?

Always.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.