Added machine language routines

This commit is contained in:
2020-10-13 17:40:52 +02:00
parent 2e45a338d1
commit 1bd37dbffb
5 changed files with 117 additions and 99 deletions

View File

@@ -1,7 +1,7 @@
(****************************************************************************
* File name: CSTRINGS.D
* Created On: Fri 02 Oct 2020 07:27:00 PM CEST
* Last Modified: Sat 03 Oct 2020 01:59:46 PM CEST
* Last Modified: Tue 13 Oct 2020 05:15:30 PM CEST
* Author: Jali <jali@orca-central.de>
****************************************************************************
* Header file for an implementation of C-Like strings
@@ -51,18 +51,6 @@ PROCEDURE Compare(strA, strB : CString) : CompareResult;
*)
PROCEDURE Concat(strA, strB : CString) : CString;
(*
* Checks if *subString* is contained in *string*, and returns the result.
*
* # Parameters:
* - string: The string to compare to
* - subString: The substring to search
*
* # Returns:
* TRUE, if subString is part of string, else false.
*)
PROCEDURE Contains(string, subString : CString) : BOOLEAN;
(*
* Checks, if the CString is NIL or the the string only contains a NULL char.
*
@@ -74,18 +62,6 @@ PROCEDURE Contains(string, subString : CString) : BOOLEAN;
*)
PROCEDURE IsNilOrEmpty(string : CString) : BOOLEAN;
(*
* Checks, if the CString is NIL or the the string only contains a white space
* characters.
*
* # Parameters:
* - string: The string to check
*
* # Returns:
* TRUE, if the CString is NIL, or only contains a white space character
*)
PROCEDURE IsNilOrWhiteSpace(string : CString) : BOOLEAN;
(*
* Returns the length of the string stored in
* the CString.
@@ -105,4 +81,4 @@ PROCEDURE ToArray(string : CString) : ARRAY OF CHAR;
END CStrings;
(* vim: set filetype=modula2: set nospell: *)
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)

View File

@@ -1,69 +1,111 @@
(****************************************************************************
* File name: CSTRINGS.I
* Created On: Sat 03 Oct 2020 03:18:19 PM CEST
* Last Modified: Sun 04 Oct 2020 04:34:02 PM CEST
* Author: Jali <jali@orca-central.de>
****************************************************************************
* Implementation for handling C-Like strings
****************************************************************************)
IMPLEMENTATION MODULE CStrings;
FROM Storage IMPORT ALLOCATE;
PROCEDURE Compare(strA : CString, strB : CString) : CompareResult
(* $L- *)
BEGIN
ASSEMBLER
MOVE.L -(A3),A1 ; Read strB from the stack
MOVE.L -(A3),A0 ; Read strA from the stack
MOVE.W 1,D2 ; Preset the return value to CompareResult.Equal
Loop:
MOVE.S D0,(A0)+ ; Read a byte from strA into D0, and increase the pointer
CMP.S 0,D0 ; Check if the value is NULL
BEQ Return ; Reached the end of the first string; break
MOVE.S D1,(A1)+ ; Read a byte from strB into S1 and increase the pointer
CMP.S 0,D0 ; Check if the byte is NULL
BEQ Return ; Reached the end of the second string; break
CMP.S D0,D1 ; Compare the two values for equality
BEQ Loop ; If equal, continue with the next bytes.
MOVE.W 2,D2 ; Set the result register to ComepareResult.After
BHI Return ; Break and retrun result
MOVE.W 0,D2 ; Set the result register to CompareResult.Before
Return:
MOVE D2,(A3)+ ; Push the result to the stack
END;
(* $L+ *)
END Compare;
PROCEDURE CopyMem(tgt, src : CString)
p : POINTER TO CHAR;
BEGIN
p := tgt;
WHILE src^ <> NULL DO
p^ := src^;
p += 1;
src += 1;
END;
END CopyStr;
PROCEDURE Concat(strA, strB : CString) : CString
VAR
r : POINTER TO CHAR;
len : LONGCARD;
BEGIN
len := Length(strA) + Length(strB);
ALLOCATE(r, lenA + lenB);
CopyMem(r, strA);
CopyMem(r, strB);
(r + len)^ := NULL;
END Concat;
PROCEDURE Contains
BEGIN
END Contains;
END CStrings;
(* vim: set filetype=modula2: *)
(****************************************************************************
* File name: CSTRINGS.I
* Created On: Sat 03 Oct 2020 03:18:19 PM CEST
* Last Modified: Tue 13 Oct 2020 05:40:24 PM CEST
* Author: Jali <jali@orca-central.de>
****************************************************************************
* Implementation for handling C-Like strings
****************************************************************************)
IMPLEMENTATION MODULE CStrings;
FROM Storage IMPORT ALLOCATE;
PROCEDURE Compare(strA, strB : CString) : CompareResult
BEGIN
(* $L- *)
ASSEMBLER
MOVE.L -(A3),A1 ; Read strB from the stack
MOVE.L -(A3),A0 ; Read strA from the stack
MOVE.W #1,D2 ; Preset the return value to CompareResult.Equal
Loop:
MOVE.B (A0)+,D0 ; Read a byte from strA into D0, and increase the pointer
CMP.B #0,D0 ; Check if the value is NULL
BEQ Return ; Reached the end of the first string; break
MOVE.B (A1)+,D1 ; Read a byte from strB into S1 and increase the pointer
CMP.B #0,D0 ; Check if the byte is NULL
BEQ Return ; Reached the end of the second string; break
CMP.B D0,D1 ; Compare the two values for equality
BEQ Loop ; If equal, continue with the next bytes.
MOVE.W #2,D2 ; Set the result register to ComepareResult.After
BHI Return ; Break and retrun result
MOVE.W #0,D2 ; Set the result register to CompareResult.Before
Return:
MOVE.W D2,(A3)+ ; Push the result to the stack
END;
(* $L+ *)
END Compare;
PROCEDURE CopyMem(src, tgt : CString, len : CARDINAL)
BEGIN
(* $L- *)
ASSEMBLER
MOVE.W -(A3),D1 ; Read the len parameter
MOVE.L -(A3),A1 ; Read tgt from the stack
MOVE.L -(A3),A0 ; Read src from the stack
BRA Entry ; Forces the loop condition to be checked before
; anything else. Cheaper than decrementing D1
Loop:
MOVE.B (A0)+,D0 ; Read a byte from src into D0, and increase the pointer
MOVE.B D0,(A1)+ ; Copy the byte into the target buffer
Entry:
DBF D1,Loop ; Decrement the counter and branch to loop, until done
END;
(* $L+ *)
END CopyStr;
PROCEDURE Concat(strA, strB : CString) : CString
VAR
r : POINTER TO CHAR;
lenA : LONGCARD;
lenB : LONGCARD;
BEGIN
lenA := Length(strA);
lenB := Length(strB);
ALLOCATE(r, lenA + lenB + 1);
CopyMem(r, strA, lenA);
CopyMem(r + lenA, strB, lenB);
CopyMem(r + lenA + lenB, ASC(0), 1);
RETURN r;
END Concat;
PROCEDURE IsNilOrEmpty(string : CString) : BOOLEAN
BEGIN
(* $L- *)
ASSEMBLER
MOVE.L -(A3),A0 ; Get the parameter
MOVE.W #0,D1 ; Set the result value to false
CMP.L #0,A0 ; Is address == NULL?
BEQ IsNil ; We have to return TRUE here
CMP.B #0,(A0) ; Is the value of the parameter also NULL?
BEQ IsNil ; Set the return value to TRUE
BRA End ; Otherwise, return FALSE
IsNil:
MOVE.W #1,D1 ; Set result TRUE
End:
MOVE.W D1,(A3)+
END;
(* $L+ *)
END IsNilOrEmpty;
PROCEDURE Length(string : CString) : LONGCARD
BEGIN
(* $L- *)
ASSEMBLER
MOVE.L -(A3),A0 ; Get the address of the string
MOVE.L #0,D1 ; Set the return value to 0
Loop:
MOVE.B (A0)+,D0 ; Load the value from (A0)
CMP.B #0,D0 ; Check if D0 is NULL
BEQ End ; Jump to the end, when end of string is reached
ADDI #1,D1 ; Increase the result value
BRA Loop ; Continue the loop
End:
MOVE.L D1,(A3)+ ; Push the result onto the stack
END
(* $L+ *)
END Length;
END CStrings;
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)

View File

@@ -11,4 +11,4 @@ BEGIN
Read(exit);
END Telnet.
(* vim: set filetype=modula2: *)
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)

View File

@@ -1,7 +1,7 @@
(****************************************************************************
* File name: TRANSPRT.D
* Created On: Fri 02 Oct 2020 07:27:00 PM CEST
* Last Modified: Fri 02 Oct 2020 07:27:23 PM CEST
* Last Modified: Tue 13 Oct 2020 12:43:09 PM CEST
* Author: Jali <jali@orca-central.de>
****************************************************************************
* Header file for all STinG releated source files
@@ -35,4 +35,4 @@ TYPE
END Transport.
(* vim: set filetype=modula2: *)
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)

View File

@@ -1,2 +1,2 @@
(* vim: set filetype=modula2: *)
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)