How can we access a DOS function only by using it's name,without the hexadecimal number associated with it?

Viewed 78

I am going through MS-DOS 1.25 source code MSDOS.ASM, here i found MS-DOS inbuilt functions introduced by there names, as given below. as we can see implementation of system standard function "RENAME",this function is system call 23, but value 23 is used nowhere.

; Standard Functions

DISPATCH DW ABORT ;0 
               DW CONIN 
               DW CONOUT 
               DW READER 
               DW PUNCH 
               DW LIST ;5 
               DW RAWIO 
               DW RAWINP
               DW RENAME

RENAME:     ;System call 23 
CALL MOVNAME 
JC ERRET 
ADD SI,5 
MOV DI,OFFSET DOSGROUP:NAME2 
CALL LODNAME 
JC ERRET 
CALL FINDNAME 
JC ERRET 
OR BH,BH ;Check if I/O device name 
JS ERRET ;If so, can't rename it 
MOV SI,OFFSET DOSGROUP:NAME1 
MOV DI,OFFSET DOSGROUP:NAME3 
MOV CX,6
REP MOVSW

My confusion is that how system will recognise RENAME function, because this same function might have different names in different modules and no decimal or hexadecimal value is attached with it. As we can see that RENAME function is system call 23 but this value is nowhere used in the code. And by only using RENAME variable name we can't access to it's code. I got surprised when I see that only names are used some places with colon (:) sign. Like I find that only

 CONIN:
 

Is used some places. In this condition how the desire code will execute, because by writing only "CONIN". We can't access to desire code.

1 Answers

If you look more carefully at the DISPATCH table, you'll see that dw RENAME is in fact its 23rd element (counting from zero).

And if you look at COMMAND, which is where the INT 21h vector points, you will see here that it takes the value in AH and uses it as an index into the DISPATCH array, then calls this address:

        MOV     BL,AH
        MOV     BH,0
        SHL     BX,1
        ;; skip a couple lines
        CALL    CS:[BX+DISPATCH]

So the fact that RENAME is syscall 23, i.e. is accessed by invoking INT 21h with AH=23, is encoded in the layout of the DISPATCH table. The symbol RENAME is only used within the DOS source code itself and isn't available to user programs. Indeed, if you didn't have the source code to look at, you'd never know the name of that label at all.

A lookup table is a typical way for an operating system to dispatch system calls. The only way you would otherwise need to actually use the system call number 23 is if you had a long string of compares and conditional jumps to test all possible syscall numbers and branch to their entry points accordingly, which would be much less efficient than the lookup table.

Related