Please I would appreciate some input, Far pointer from C++ to asm 
Author Message
 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



Mon, 08 Jan 2001 03:00:00 GMT  
 Please I would appreciate some input, Far pointer from C++ to asm


Quote:
> // 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.
>    MOV  WORD PTR[DI], AX       ; Yes, update buffer
>   NoLo:                         ; No, continue
>   ADD  DI, 2

the problem may be that you're treating the pointers here as near
pointers... I.E. the ADD DI,2 line above doesn't take into account for a
16bit wraparound, you need to replace all of these with far pointer
adds.... something like this would work...

ADD     DI,2
MOV     AX,ES
MOV     BX,DI
SHR     BX,4
ADD     AX,BX
MOV     ES,AX
AND     DI,0FH

regards
Tony



Tue, 09 Jan 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Watcom C/C++ & far pointers

2. Appreciate Some "InPut"..(or feedback).

3. newbie would appreciate input examples

4. Pointers Appreciated (Semantic Nets)

5. Please help, any response is greatly appreciated

6. Far Pointers and String Instructions

7. far pointer in assembler question

8. NASM: How to declare a far pointer?

9. les, far pointer on linux

10. CallDLL and Long Far Pointer Return

11. Creating a FAR pointer in MS fortran

12. Passing arguments from C++ to ASM with Borland C++

 

 
Powered by phpBB® Forum Software