Announcement

Collapse
No announcement yet.

Calling ASM Routines

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling ASM Routines

    I have recently purchased PB35 for DOS to evaluate it in order to migrate to PB CC or PB dll
    in the near future.
    Currently I use PDS 7.0 and Masm6.1 in PWB environment and have so for many years.
    Some of my assembly programs are 100's of Kb in size.

    Can somebody tell me:
    1. What is wrong with the attached program and why is the
    assembly routine considered invalid.

    2. How do I assemble a source file that is not in-line without using
    microsoft MASM

    I know this example is easier to code inline, but it is merely a test to compare the
    pb compiler to see how much of my code I have to change.


    '---------------------------------------------------------------------------------------------------------------------------
    ' The Basic File
    '---------------------------------------------------------------------------------------------------------------------------
    DECLARE FUNCTION DOSTIME& (A&)
    COMMON STARTIME&
    COMMON ESC$
    $LINK "D:\MASM61\ASM.DEV\DOSTIME.OBJ"

    ESC$ = CHR$(&H1B)
    STARTIME& = Dostime&(0)
    DO
    K$=UCASE$(INKEY$)
    If K$ = ESC$ THEN End
    LOCATE 1,1: PRINT USING "######.##";(DOSTIME&(0)-STARTIME&)/18.2;
    LOOP
    end

    '---------------------------------------------------------------------------------------------------------------------------
    Now the assembly function
    '---------------------------------------------------------------------------------------------------------------------------
    ;*****************************************************************************
    ; DOSTIME.ASM IS A FUNCTION FOR READING DOS TIME IN 1/18.2 SECS.
    ; IT RETURNS THE RESULT IN DX:AX
    ;*****************************************************************************
    .DOSSEG
    .MODEL MEDIUM
    .386
    .CODE
    PUBLIC DOSTIME
    ORG 100H
    DOSTIME PROC FAR
    PUSH BP
    MOV BP,SP
    ;******************************
    MOV AH,00H ;get dos time count
    INT 1AH ;which returns a value in cx:dx
    MOV AX,DX ;but qbasic wants DX as hi word
    MOV DX,CX ;and AX as lo word
    ;******************************
    POP BP
    RETF 2
    DOSTIME ENDP
    END



    ------------------

  • #2
    PB needs the Objects to be compiled in the Large Memory Model in order
    for you to be able to LINK to it.


    ------------------
    Scott Slater
    Summit Computer Networks
    www.summitcn.com

    [This message has been edited by Scott Slater (edited February 03, 2002).]
    Scott Slater
    Summit Computer Networks, Inc.
    www.summitcn.com

    Comment


    • #3
      Have tried that and still get error 507
      Have tried commenting out the Dosseg and other directives to no avail.

      Regards

      Originally posted by Jan van de Poll:
      I have recently purchased PB35 for DOS to evaluate it in order to migrate to PB CC or PB dll
      in the near future.
      Currently I use PDS 7.0 and Masm6.1 in PWB environment and have so for many years.
      Some of my assembly programs are 100's of Kb in size.

      Can somebody tell me:
      1. What is wrong with the attached program and why is the
      assembly routine considered invalid.

      2. How do I assemble a source file that is not in-line without using
      microsoft MASM

      I know this example is easier to code inline, but it is merely a test to compare the
      pb compiler to see how much of my code I have to change.


      '


      ------------------

      Comment


      • #4
        The following is apparently MASM code, probably for MASM 5.1. Can you assemble this into an OBJ and link it? If so, it should hopefully give you the framework you need to wrap you own ASM code.

        Code:
        ; IsNetBIOS by Dave Navarro, Jr.
        ; Last Revision: February 19, 1995
        ; Returns true (-1) if NetBIOS services are available, otherwise it
        ; returns false (0).
        
        Code    Segment Byte
                Assume  CS: Code
        
                Public  IsNetBIOS
        
        IsNetBIOS Proc Far
                push    DS                      ;
        
                mov     AX, 0B800h              ; function B8h, subfunction 00h
                int     2Fh                     ; through multiplexor
                xor     BX, BX                  ; assume not installed
                or      AL, AL                  ; does AL = 0?
                jz      Exit                    ; yes, exit
                dec     BX                      ; no, return true (-1)
        Exit:
                mov     AX, BX                  ;
                pop     DS                      ;
                retf                            ;
        IsNetBIOS EndP
        Code    EndS
                End

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Jan,

          The main differences are that you can't use MASM 6.1 simplified
          directives and that you can only have one data segment per OBJ.

          I haven't MASM installed in my computer so I can't made a test,
          but your routine can be translated as:

          Code:
          MyCode SEGMENT PARA PUBLIC 'CODE'
          ASSUME CS: MyCode
          
          PUBLIC DosTime
          PROC DosTime FAR
          
             Push BP
             Mov  BP, SP
             '**********************
             '**********************
             Pop BP
             Ret
          
          DosTime ENDP
          MyCode  ENDS
          END
          And you will call the routine as: StartTime& = DosTime&

          If you pass parameters to the routine you have to access them
          via BP, e.g. Mov AX, [BP+06h], and clear the stack with
          RET [Number of parameters] * 4 (Power Basic always pushes 4 bytes
          per parameter into the stack, this is also a major difference
          with Microsoft Basic, that pushes 2 bytes if you pass an integer
          and 4 bytes if you push a long).

          If you use or import data in your ASM routine you must use:

          DATA SEGMENT PARA PUBLIC 'DATA'

          Your data [e.g. Descrip DD ?]
          Your imported data [e.g. EXTRN VideoMode:BYTE]

          DATA ENDS
          ASSUME DS: DATA

          Regards

          P.S.Basic always uses the medium model, but you must not use the
          .MODEL directive or any other simplified directive, neither ORG.
          Also, when assembling with MASM 6.1, you must use MASM 5.1
          compatibility (sorry but don't remember the switches).
          ------------------




          [This message has been edited by JOSE ROCA (edited February 03, 2002).]

          Comment


          • #6
            JOSE

            Thanks for that, will try it.
            PS I am on West Australian Time so cannot respond while you are awake.

            REgards



            ------------------

            Comment


            • #7

              After reviewing the changes that I have to make to my Assembly
              code, I wonder if there are any benifits to changing to PB.

              I have used simplified directives for more then 20 years, and
              to go back to something that I have filed in the irrelative
              drawer is going to be painful.

              You are right about the ORG statement, it is a left over from the
              .com files days.

              When I pass parameters to basic, I usually pass the variable's
              address, unless there is only one value then I am inclined to use
              the stack so the following is a typical declaration.

              DECLARE SUB CombCalc(HBin&,Cmnd&,Value&,CalcArray,WtArray)

              As the purpose of this email was to evaluate the possibility of
              changing to PB Dll or CC can somebody tell me if these have the
              same problem as Pb for DOS.

              I have already dismissed PureBasic as a contender in this area,
              but Assembly language forms a large part of my real time code.

              Regards and thanks for your help.


              ------------------

              Comment


              • #8
                The simplified directives are handy but, really, they do almost nothing.
                They're basically simple macros. You could readily replace them with
                macros of your own.

                If your goal is to move to Windows, though, you're looking at a whole
                new ballgame: 32-bit flat-mode assembly language. While this is much,
                much more convenient than 16-bit segmented mode in any number of ways,
                your old asm code will need to be heavily rewritten.

                Some of the advantages? Relative jumps can span +/- 32 Kb, 32-bit
                addressing (you never touch segment registers), and more nearly orthogonal
                register support (e.g., any register can act as an index register).


                ------------------
                Tom Hanlin
                PowerBASIC Staff

                Comment

                Working...
                X