This is Turbo Pascal’s Write(File) function. It takes one parameter:
SYS043B: MOV BX,SP
Use BX to address items on the stack. Upon entry into this subroutine, the stack looks as follows:
Index | Contents |
---|---|
BX | Return Address (OFFSET) |
BX+02 | Return Address (SEGMENT) |
BX+04 | Pointer to File/Text Record Data (OFFSET) |
BX+06 | Pointer to File/Text Record Data (SEGMENT) |
SYS043D: PUSH DS
Save DS.
SYS043E: SS:
SYS043F: LES DI,[BX+04]
Loads the pointer to the File into ES:DI.
SYS0442: ES:
SYS0443: LDS DX,[DI:BufPtr]
Loads the pointer to buffer (BufPtr) in File into DS:DX.
SYS0446: XOR CX,CX
SYS0448: ES:
SYS0449: XCHG CX,[DI:BufPos]
Get number of bytes to write from the File’s BufPos.
SYS044C: ES:
SYS044D: MOV BX,[DI:Handle]
SYS044F: MOV AH,40
SYS0451: INT 21
Write CX bytes to File/Device using DOS Write to a File or Device INT 21h AH = 40h with parameters:
SYS0453: JB 045C
On error, return with error code in AX.
SYS0455: SUB AX,CX
SYS0457: JZ 045C
Verify if actual number of bytes written in AX (returned after call to DOS INT 21h AH = 40h service) is equal to what was expected (in CX).
SYS0459: MOV AX,0065
If these do not match return with an code 65h/101: Disk write error.
SYS045C: POP DS
Restore DS.
SYS045D: RETF 0004
Return to caller with error code in AX, later to be stored in InOutRes. Pop-off FAR PTR parameter from the stack (4 bytes).
See also: SYS:0460 Write Function, or go back