This is Turbo Pascal’s Assign(File, Name) function. It takes two parameters:
Upon calling this routine, this is how the stack looks like:
Index | Contents |
---|---|
SP | Return Address (OFFSET) |
SP+02 | Return Address (SEGMENT) |
SP+04 | Pointer to name (OFFSET ) |
SP+06 | Pointer to name (SEGMENT) |
SP+08 | Pointer to File/Text Record Data (OFFSET) |
SP+0A | Pointer to File/Text Record Data (SEGMENT) |
SYS02E6: XOR DX,DX
Set name length 0.
SYS02E8: MOV BX,SP
Sets up BX to address data on the stack. SYS:02E8 is a possible entry point if a non-zero length string were to be assigned to File.
SYS02EA: PUSH DS
Save DS because it will be modified later.
SYS02EB: SS:
SYS02EC: LES DI,[BX+08]
Loads the pointer to the Text File/Record data into ES:DI.
SYS02EF: SS:
SYS02F0: LDS SI,[BX+04]
Loads the pointer to the Name string into DS:SI.
SYS02F3: CLD
Set copy direction to forward (DF = 0).
SYS02F4: XOR AX,AX
SYS02F6: STOSW
Initialize Handle to 0.
SYS02F7: MOV AX,fmClosed
SYS02FA: STOSW
SYS02FB: MOV AX,0080
SYS02FE: STOSW
Set BufSize to 128 (80h) bytes.
SYS02FF: XOR AX,AX
SYS0301: STOSW
SYS0302: STOSW
SYS0303: STOSW
Does the following in order:
SYS0304: LEA AX,[DI+74]
SYS0307: STOSW
Loads the offset location of TextBuf into AX, then sets the offset part of BufPtr.
SYS0308: MOV AX,ES
SYS030A: STOSW
Copies ES which is the SEGMENT location of TextBuf into AX, then sets the segment part of BufPtr.
SYS030B: MOV AX,0499
SYS030E: STOSW
SYS030F: MOV AX,SYS
SYS0312: STOSW
Sets this File’s OpenFunc pointer to SYS:0499 Open Function.
SYS0313: XOR AX,AX
SYS0315: MOV CX,000E
SYS0318: REPZ
SYS0319: STOSW
Clears the following:
SYS031A: MOV CX,004F
SYS031D: OR DX,DX
SYS031F: JNZ 032A
Check if there are bytes to copy (up to CX = 79/4Fh).
SYS0321: LODSB
SYS0322: CMP CL,AL
SYS0324: JBE 032A
Check if the string (filename) in DS:SI is 79 characters or less then copy it to this Files’s Name.
SYS0326: MOV CL,AL
SYS0328: JCXZ 0332
If greater than 79 bytes, i.e. CL > AL, modify the loop counter in CX. This may be used to copy Pascal strings whose first byte stores the string length (up to 255). If CX = 0, then return immediately because there are no bytes to copy.
SYS032A: LODSB
SYS032B: OR AL,AL
SYS032D: JZ 0332
SYS032F: STOSB
SYS0330: LOOP 032A
This does the actual copying of the name in DS:SI to Name. Exit loop immediately if a NULL (00h) byte from the source is encountered.
SYS0332: XOR AL,AL
SYS0334: STOSB
NULL (00h) terminates the Name string (or the destination string if not a File).
SYS0335: POP DS
SYS0336: RETF 0008
Return and pop-off the two FAR PTR parameters (8 bytes) from the stack.
See also: SYS:0499 Open Function or go back