INT 21h AH=30h returns the DOS version: the major number in AL, the minor in AH. The minor part is the two decimal digits after the point, stored as a binary number, so MS-DOS 6.22 returns AL = 6 and AH = 22 (16h), and DOS 3.3 returns AL = 3 and AH = 30 (1Eh). DOS 1 did not have the function and leaves AL = 0, which is an answer too.
MOV AX, 3000h ; DOS: get the version; AL = 0: OEM number in BHINT 21h ; AL = major, AH = minorPUSH AXMOV DX, OFFSET MSG1MOV AH, 09h ; DOS: print the string at DS:DXINT 21hPOP AXPUSH AXXOR AH, AH ; AX = the major numberCALL PDEC1MOV DL, "."MOV AH, 02h ; DOS: print the character in DLINT 21hPOP AXMOV AL, AH ; the minor number: always two digitsCALL P2D1MSG1 DB "DOS $"PDEC1 PROC NEAR ; print AX in decimalMOV BX, 10XOR CX, CX ; digits so farPD1:XOR DX, DXDIV BX ; AX = AX / 10, DX = the last digitPUSH DXINC CXTEST AX, AXJNZ PD1PD2:POP DX ; the digits come back first to lastADD DL, "0"MOV AH, 02hINT 21hLOOP PD2RETPDEC1 ENDPP2D1 PROC NEAR ; print AL (0-99) as two digitsAAM ; AH = AL / 10, AL = AL mod 10ADD AX, 3030h ; both digits to charactersPUSH AXMOV DL, AH ; the tensMOV AH, 02hINT 21hPOP DX ; DL = the unitsMOV AH, 02hINT 21hRETP2D1 ENDP
Programs check the version before using functions a version introduced: handles and directories need 2.0, the extended error code 3.0, many network and code page functions 3.3. A check compares the major numbers first and the minor ones only when the majors are equal; swapping the halves lets one word comparison do both:
MOV AH, 30h ; DOS: get the versionINT 21hXCHG AL, AH ; AH = major, AL = minorCMP AX, 0314h ; at least 3.20? (20 = 14h)JB TOOOLD1
Without the XCHG, AX holds minor:major, and 5.00 (AX = 0005h) would look older than 3.30 (AX = 1E03h).
What it does not tell
The number can be a polite fiction. SETVER makes DOS report a chosen version to a chosen program, Windows 95 reports 7, and the DOS box of Windows NT reports 5.0. DOS 5 and later have function 33h with AL = 06h (MOV AX, 3306h), which returns the true version in BL and BH and which SETVER does not change. BH tells the maker: FFh for Microsoft, 00h for IBM PC DOS.
DOSBox-X reports 5.0 unless told otherwise, by the ver setting in its configuration or by the VER SET command (VER SET 6 22), and returns BH = FFh with a serial number of 0. Its built-in DOS has the functions of a later DOS regardless of the number it reports.