
Please I would appreciate some input, Far pointer from C++ to asm
// Hi, Hi Assembly
// I have a problem using a far pointer to an array of word in memory. I
would appreciate
// any input one might have on where and what i'm doing wrong here.
// The array is currently set at 0xC0000
#define BASE 0xC0000
#define BASE_LSB BASE
The function prototype
extern "C" int ReadSensors ( WORD _far *SAMPLES, WORD *BUFFER, WORD
NUMSMPL );
// This is called in an interrupt handler
LastSampleBuffer = (WORD _far*)BASE_LSB;
ReadSensors ( LastSampleBuffer, (WORD *)&LSWBuf, LCInit.NbC );
// LSWBuf is an array to a W,W,DW,W struct, this pointer does not seems to
be the problem since
// I use it in the other functions with success
// I have other functions in this asm module which transfer information
between
// buffers so it seems that my problem is comming from that far pointer
// I've tried using an array and it worked so it has to be about accessing
memory between 640K and 1M
s_WorkingBuffer LSWBuf[XNumOfSensors];
// Part of the ASM module
; Called from main program in NEWLC.CPP
; Assemble with ML /c BUFFERS.ASM
.MODEL large, c
.386
ReadSensors PROTO C SAMPLES:FAR PTR WORD, BUFFER:PTR WORD, NUMSMPL:WORD
UpdateWBuffer PROTO C DSTBuf:PTR WORD, SRCBuf:PTR WORD, NUMSMPL:WORD
UpdateWBuffer10 PROTO C DSTBuf:PTR WORD, SRCBuf:PTR WORD, NUMSMPL:WORD
.CODE
ReadSensors PROC FAR C SAMPLES:FAR PTR WORD, BUFFER:PTR WORD, NUMSMPL:WORD
PUSHF
MOV CX, NUMSMPL
JCXZ Done1
PUSH ES
PUSH DS
PUSH SI
PUSH DI
PUSH EAX
PUSH EBX
LDS SI, SAMPLES
LES DI, BUFFER
CLD
ReadLoop:
LODSW ; LastSample in AX
MOV BX, WORD PTR[DI]
CMP AX, BX ; Compare to Buffer.Max
JBE NoHi ; Is it higher
MOV WORD PTR[DI], AX ; Yes, update buffer
NoHi: ; No, continue
ADD DI, 2
MOV BX, WORD PTR[DI]
CMP AX, BX ; Compare to Buffer.Min
JAE NoLo ; Is it lower
MOV WORD PTR[DI], AX ; Yes, update buffer
NoLo: ; No, continue
ADD DI, 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
PUSH EAX
CWDE
MOV EBX, DWORD PTR[DI] ; Move Buffer.Total to BX
ADD EAX, EBX ; Add sample to buffer
MOV DWORD PTR[DI], EAX ; Update buffer
POP EAX ; Restore EAX
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
ADD DI, 4
MOV BX, WORD PTR[DI] ; Move Buffer.NumSample to BX
INC BX ; Increment BX
MOV WORD PTR[DI], BX ; Move back to buffer
ADD DI, 2
LOOP ReadLoop ; Next sample
POP EBX
POP EAX
POP DI
POP SI
POP DS
POP ES
Done1:
POPF
RET
ReadSensors ENDP