🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #2672

TopSpeed and assembler

#2672
From: Marco van de Voort
Date: Tue, 01 Aug 1995 22:49
141 lines
5675 bytes
Hallo David!

Friday June 30 1995 02:29, David Mann wrote to All:

 DM> Does anyone out there know how to put assembler into a modula-2 program?
 DM> (I'm using the TopSpeed modula2 compiler in DOS..version 3.1 I think)

I'm currently doing this, with the same compiler.
(Hint zero : look in manual, but should be obvious)
First hint : look at the file ademo.a, for documented examples with pragma's
Second hint : Look at the RTL assembler sources (specially asmlib.A)
Third hint  : get a good book about assembler.
4th hint : use the profiler to look what routines need more speed, or the map
file to look which procedures are the biggest.(e.g. for TSR's)


Try to do your routines in Modula2, compile it, disassemble it using

TSDA <Module name> <disaasembly file name>

DO THIS FOR SEVERAL MEMORYMODELS, specially in the beginning!

rewrite/optimize it by hand using a layout as in ADEMO.A.

Third hint : Ask questions to me or (more chance on success) others in this
area.

I started 4 weeks ago with ts assembler, and had never programmed 80x86 code before(but I DID know the 6510, and thus the asm fundamentals by heart), and will help whereever I can.

I already wrote a complete Crt unit (like in TP, even better). Crc32 routines, some simple string routines (difficulty level comparable with routines like Str.Delete). So if you know assembler's principles, and a little bit of the
PC's architecture (get a interruptlist!) you could learn it very fast.

Just to get started, here is a part of my Crt module. The procedure GotoXY(see help Window). Sets the cursor to X,Y and stores X,Y in the global variables
CurX,CurY.

DEFINITION MODULE Crt;

VAR CurX,CurY:CARDINAL;

PROCEDURE GotoXY(X,Y:CARDINAL);

END Crt.

(* Here starts the implementation part, filename Crt.A *)

include "corelib.inc" (* Used for memorymodel dependant constant like
                          Ret0@ RetX@ and frame *)

module CoreCrt


(*%T SameDS *)            (* Memory model # (is not) XLarge or equivalent *)
     segment _BSS(BSS,00028H)
(*%E *)
(*%F SameDS *)            (* Mem model =     "     "         "   *)
     segment CoreCrt_BSS(FAR_DATA,028H)
(*%E*)

(* VAR statements *)

public CoreCrt@CurX       :    org 00002H
public CoreCrt@CurY       :    org 00002H

(*%T SameDS *)
segment _CONST(DATA,00028H)
(*%E *)
(*%F SameDS *)
segment _INIT_DATA_CONST(FAR_DATA,028H)
(*%E*)

public CoreCrt$:                    (* Dependancy list *)

(*%F NearCall*)                     (* Far calls *)
      dd $5                         (* initialization label goes here (far) *)
(*%E NearCall FALSE *)
(*%T NearCall*)                     (* Near Calls *)
      dw $5
(*%E NearCall TRUE  *)
  dw -1                               (* Terminates list *)


(* Such a segmentdeclarationblock as follows makes it possible for the linker to link only the objects (PROCEDURES, VAR, CONST, own tables, whatever) when those are used in the program *)

(*%F NearCall *)
segment CoreCrt_TEXT(CODE,048H)
(*%E NearCall *)

(*%T NearCall *)
segment _TEXT(CODE,048H)
(*%E NearCall TRUE  *)

                            $5:   (* Init Procedure *)
                              db Ret0@ (* Return independant of NearCall
                                  If NearCall=TRUE then this becomes RET 0
                                   ELSE RET FAR 0 *)



(*%F NearCall *)
segment CoreCrt_TEXT(CODE,048H)
(*%E NearCall *)

(*%T NearCall *)
segment _TEXT(CODE,048H)
(*%E NearCall TRUE  *)

public CoreCrt$GotoXY:        push  dx            (* Always save registers
                                                     di,si,ds,St0,bp and St1;
                                                   and AX..DX when not used
                                                     as an argument *)
                              push  cx
                              mov   cx,ax
                              (*%F SameDS *)     (* XLarge? *)
                                (* Then load segment CurX *)
                               mov   ax,seg CoreCrt@CurX
                               mov   es,ax
                               mov   es:[CoreCrt@CurX],cx
                               mov   es:[CoreCrt@CurY],bx
                              (*%E SameDS FALSE *)
                              (*%T SameDS *)
                               mov   [CoreCrt@CurX],cx
                               mov   [CoreCrt@CurY],bx
                              (*%E SameDS TRUE *)
                              mov   dh,bl
                              mov   dl,al
                              mov   ah,0FH  (* Get current videopage *)
                              int   10H
                              mov   ah,02H  (* Call SetCursor routine *)
                              int   10H
                              pop   cx      (* Recall saved registers *)
                              pop   dx
                              db Ret0@      (* See intialisation code comment*)


end

( Please reply to me in this area, I probably won't read my E-Mail until September! )

It's enough Modula-2 related I think, since it's interfacing with Modula-2. Anyway, the current CS-1, CS-2 discussion is FAR more offtopic.

Marco  (M.W.T.J.v.d.Voort@stud.tue.nl or MarcoV@stack.urc.tue.nl)
Technical Details
Message-ID: <807534257.AA00866@puddle.fidonet.org>
Path: arc1-ca.pugleaf.net!news.sprintlink.net!psgrain!puddle!internet

Show Full Headers
Complete Article Headers
From: Marco.van.de.Voort@p18.f402.n284.z2.fidonet.org (Marco van de Voort)
Path: arc1-ca.pugleaf.net!news.sprintlink.net!psgrain!puddle!internet
Newsgroups: comp.lang.modula2
Subject: TopSpeed and assembler
Message-ID: <807534257.AA00866@puddle.fidonet.org>
Date: Tue, 01 Aug 1995 14:49:00 -0800
X-FTN-To: David Mann