Clever Geek Handbook
📜 ⬆️ ⬇️

.COM

.COM ( English command ) - file extension , used in some operating systems for various purposes.

Executable file DOS, CP / M
Expansion
MIME type
Format typebinary executable
Developed in.EXE

Content

Structure

On DOS systems and in 8-bit CP / M, a COM file is a simple type of executable file , when executed, the data, code and stack are in the same 16-bit segment . Therefore, the file size cannot exceed 65280 bytes (which is 256 bytes less than the segment size - 2 16 bytes ). DOS COM files can be run on some versions of Windows , as well as on emulators .

In addition to COM files, DOS supports EXE files with a more complex structure. The file type is determined at startup automatically (in the EXE format, there is a special signature at the beginning of the file), regardless of the extension.

Examples

An example of a simple program in .COM format (for FASM assembler ):

  1 use16 ; Generate 16-bit code
 2 org 100 h ; The program starts at address 100h
 3 
 4 mov dx , hello ; The DX address of the string.
 5 mov ah , 9 ; DOS function number.
 6 int 21 h ; Access to the DOS function.
 7 
 8 mov ax , 4 C00h ; In the register AH we put 4Ch, in AL - 00h.
 9 int 21 h ; Program Termination
 10 ; ------------------------------------------------ -------
 11 hello db ' Hello , world !  $ '

The “use 16” directive tells the assembler to generate 16-bit code. The “org 100h” directive means that the first command will be located at 100h, and the first 256 bytes (addresses 0000h - 00FFh) must be skipped (the operating system places the program segment prefix, PSP at these addresses). Next come the teams. The first command in the DX register is the address of the string hello. Then the DOS int 21h interrupt is called with function 9, which displays the string on the screen. Using the 4Ch function of the same interrupt, the program terminates (although you can also use the ret command here). The hello line ends with the character '$', which is not displayed on the screen, but signals the end of the line for function 9 of the interrupt int 21h [2] .

Compatibility

.COM format programs are not supported by 64-bit versions of Windows . In this case, you can use a DOS emulator to launch them, for example, DOSBox [2] .

Work with memory

.COM is one of the simplest executable file formats for x86 family processors . A program loaded into memory for execution is an exact copy of a file on disk [2] .

The launch of the COM-program in MS-DOS is as follows [3] :

  1. The system allocates a free memory segment and enters its address in all segment registers (CS, DS, ES and SS).
  2. The first 256 bytes of this segment are written PSP .
  3. Directly after it, the contents of the COM file are loaded without changes.
  4. The stack pointer (SP register) is set to the end of the segment.
  5. On the stack, 0000h is written (return address for the ret command).
  6. Control is transferred to the address CS: 0100h, where the first byte of the executable file is located.

The memory model used by COM programs, when the program code, all its data, PSP and the stack are located in the same segment, high-level language compilers are called TINY ( English tiny - tiny).

Usage

COM programs are usually small applications, system utilities, or small resident programs [4] .

See also

  • Assembly language
  • Machine code

Notes

  1. ↑ https://github.com/file/file/blob/FILE5_37/magic/Magdir/msdos#L556 - 2019.
  2. ↑ 1 2 3 File formats for programs on FASM under Windows (Russian) . Date of appeal September 17, 2018.
  3. ↑ Frolov A., Frolov G. MS-DOS for the programmer. - M, 1995 .-- T. 18.
  4. ↑ Bank of lectures Siblec.ru - Electronic Engineering, Radio Engineering and Communications. Formal, technical, natural, social, humanitarian, and other sciences. 5.8. EXE and COM programs. Computers, systems and networks (Russian) . siblec.ru. Date of appeal September 17, 2018.


Source - https://ru.wikipedia.org/w/index.php?title=.COM&oldid=101348007


More articles:

  • Ostracon
  • Kun, Franz Felix Adalbert
  • Friedman, George
  • Hyoscyamine
  • GLUT
  • Linor Lens
  • Generation X
  • Riots in Cincinnati (2001)
  • Monchalovsky, Osip Andreevich
  • Obukhov, Pavel Matveyevich

All articles

Clever Geek | 2019