What are DI, EI, and UP instructions(?) in original MS-DOS source code?

Viewed 317

I am going through a assembly language project for OS. For this i am getting knowledge through initial OSs. In the process i try to understand MS-DOS 1.25. But when I run this file IO.ASM then i got four errors from code of some lines as given below, here i marked the lines with "<-----this" sign. Please guide me.

INIT:
XOR BP,BP       ; Set up 
;stack just below I/O 
;system.
MOV SS,BP
MOV SP,BIOSSEG*16

IF  INTINP-1
MOV AL,0FFH     ; Mask all 
;interrupts.
OUTB BASE+3 <------this
ENDIF

IF  INTINP
DI  ; Set up <------ this
;keyboard interrupt vector.
MOV [BP+64H],KBINT
MOV [BP+66H],CS
EI <-----this
ENDIF

MOV [BP+4*38H],PRNFCB
MOV [BP+4*38H+2],CS
PUSH CS
POP DS
;
; Initialize time-of-day 
;clock.
;
MOV SI,STCTAB
MOV CX,4        ;Initialize 
;4 registers
UP  <------this
INITSTC:
LODB
OUT STCCOM      ;Select 
;register to initialize
LODB
OUT STCDATA
LODB
OUT STCDATA
LOOP    INITSTC

IF  SERIAL
MOV CX,4

I know that above given errors are obvious. But please tell me how should I modify my code. Thanks in advance.

2 Answers

The MS-DOS code was originally a port of the Seattle Computer Products 86-DOS. IO.ASM needs to be assembled with the 86-DOS's Assembler (ASM.COM). The code for the assembler is in ASM.ASM but it needs to be assembled using itself. There are compiled versions of the 86-DOS assembler produced in the 1970s and 1980s that are still available online1. 86-DOS's assembler has roots in the Z80/8080 assemblers of the era like Digital Research's assembler for CP/M.

86-DOS assembler uses instruction mnemonics and syntax that are a bit different than MASM in some cases:

  • EI is Enable Interrupts. Same as STI in MASM
  • DI is Disable Interrupts. Same as CLI in MASM
  • UP is Direction Up (Forward) for string operations. Same as CLD in MASM
  • DOWN is Direction Down (Backward) for string operations. Same as STD in MASM

With regards to the IN and OUT instructions where AL/AX as source and destination operands are the only valid choices, the 86-DOS Assembler doesn't expect them to be present.

  • OUTB imm is equivalent to MASM's OUT imm, al
  • OUTW imm is equivalent to MASM's OUT imm, ax
  • INB imm is equivalent to MASM's IN al, imm
  • INW imm is equivalent to MASM's IN ax, imm

Other Information

1You can get a prebuilt ASM.COM from the links in this article. There is a build disk that can be used in emulators and virtual machine like QEMU/DOSBox/BOCHS/VirtualBox with all that is needed to build the main components of MS-DOS v1.25.

Some caveats developers should be aware of is that all the files on GitHub are in Unix text format. The 86-DOS assembler chokes on Unix end of line markers. You can use unix2dos to convert files like IO.ASM to DOS format. Text files processed with the 86-DOS assembler need to end with a Control-Z end of file marker (0x1A), otherwise the assembler will never find the end of the file.

IO.ASM, TRANS.ASM, ASM.ASM, HEX2BIN.ASM are the only files in the MS-DOS 1.25 repository that require the 86-DOS assembler to process them.

  • IO.ASM assembles to IBMBIO.COM/IO.SYS and contains the default device driver code and device initialization code.
  • ASM.ASM is the 86-DOS Assembler
  • TRANS.ASM is a translation tool to help migrate 8080 assembly code to 8086 assembly code
  • HEX2BIN.ASM is a tool that converts HEX files output by the 86-DOS Assembler to DOS COM files.

The other files in the MS-DOS v1.25 repository that assemble with MASM are:

  • STDDOS.ASM that simply sets target information then includes (MSDOS.ASM) which is used to produce IBMDOS.COM/MSDOS.SYS . This is effectively the DOS Kernel
  • COMMAND.ASM is assembled to produce COMMAND.COM the command processor (effectively the DOS command prompt and program loader)

As noted by the the other answer, by itself these files can't simply be put on a disk. You need to create a bootloader to go in the first sector of the floppy disk image. The bootloaders are different for the different OEMs like IBM/Zenith/Compaq/SCP etc. Generally though the bootloader will read IBMBIO.COM/IO.SYS (or whatever name is used by the OEM) and IBMDOS.COM/MSDOS.SYS (or whatever name is used by the OEM). The bootloader will then usually jump to the instructions in IBMBIO.COM/IO.SYS to install and initialize the default DOS device drivers. The initialization code in IBMDOS.COM/MSDOS.SYS is then called to set up the DOS Kernel and the DOS interrupts. As the final step COMMAND.COM is loaded into memory and launched to provide the DOS command prompt.

The IO.ASM file that is included in the source code is for the 8086/8088 based SCP S-100 bus systems that were not IBM-PC compatible. Each OEM has to produce their own IO.ASM that is tailored to the operating environment and hardware their version of DOS will run on.

This process may differ from OEM to OEM. Some take short cuts, some don't. As DOS evolved so did the process of loading the DOS kernel and ultimately the command processor. If you were to disassemble the bootloaders for DOS you'd find OEMs doing things differently and they'd change it as newer versions of DOS were released.

This site states that Microsoft released only the source code of MSDOS, not the linking information nor the boot sector; also the code is not intended for current PCs. So it makes no sense trying to build this code. It is just for reading/analyzing the the source code.

Related