home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
spoc88
/
proasm
/
read.asm
< prev
Wrap
Assembly Source File
|
1988-06-09
|
4KB
|
111 lines
COMMENT * ------------------------------------------------------------
This program receives an integer on the stack that refers to
an open file. This number is called a file handle. The
Turbo Prolog program gets the file handle by calling the
assembly language predicate "open". The FileHANDLE,
itself, appears at offset 14 on the stack.
BOTTOM OF STACK
-------
| 15 |
| 14 | <--- 1st PARM (INPUT) FileHANDLE ( 2 bytes)
| 13 |
| 12 |
| 11 |
| 10 | <--- Address of 2nd PARM (OUTPUT) NumBYTESread
| 9 |
| 8 |
| 7 |
| 6 | <----Address of 3rd PARM (OUTPUT) DataBUF (4 byte pointer)
| 5 |
| 4 |
| 3 |
| 2 | <--RETURN ADDRESS
| 1 |
| 0 | <--BP
--------
TOP OF STACK
---------------------------------------------------------------------*
A_PROG SEGMENT BYTE
ASSUME CS: A_PROG
ASSUME DS: A_PROG
PUBLIC read_0
read_0 PROC FAR
MOV AH,3Fh ; AH = 3F means read file
INT 3 ; This causes program to halt
; under debug
PUSH BP ; Save base pointer on stack
MOV BP,SP ; Set BP to SP
MOV SI,DS ; Save Turbo Prolog program's
; data segment address
MOV CX,1 ; CX must contain number
; of bytes to read
; Set DS:DX to point to addrress DataBUF
MOV DS,[BP]+8 ;Put high word in DS
MOV DX,[BP]+6 ;Put low word in DX
MOV BX, [BP]+ 14 ; get file handle from stack
; Before calling INT 21, make sure these conditions
; are satisfied:
; AH = 3FH
; BX = file handle
; CX = number of bytes to read
; DS:DX point to the address of the input buffer
;
INT 21h
JC FAILURE ; If carry flag is set
; jump to FAILURE
; Zero out the hibyte of the DataBUF variable
MOV DI,DX ; DI -> lowbyte
INC DI ; Make DI point to hibyte
MOV BYTE PTR[DI],00h ; Move zero to hibyte
; AX shows the number of bytes read. So now we
; return this information to Prolog
LDS DI,DWORD PTR [BP] +10 ; Make DS:DI point to
; the NumBYTESread variable.
MOV [DI],AX ; Move AX to NumBYTESread
POP BP ; Restore the Base Pointer
MOV DS,SI ; Restore calling progs data
; data segment
RET 10 ; Pop the parms off the stack
; 4+4+2
FAILURE:
MOV AX,0FFh ; 0FFh is hex for -1
LDS DI,DWORD PTR [BP] + 10 ; Set NumBYTESread to -1
MOV [DI],AX ; To show read failure
POP BP ; Restore BP
MOV DS,SI ; Restore DS
RET 10 ; Pop the parms off the stack
; The 10 after RET is critical. Without it, the return to
; Turbo Prolog will be fouled up.
;
; We put 10 after RET here because we need to pop the parameters
; that were pushed on the stack when this routine was called.
; This routine receives 3 arguments on the stack:
; FileHANLE (2 bytes)
; NumBYTESread (4 byte pointer)
; DataBUFF (4 byte pointer)
; 2+4+4 = 10, hence the 10 after RET
read_0 ENDP
A_PROG ENDS
END