Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site unmvax.UUCP From: lee@unmvax.UUCP Newsgroups: net.sources Subject: TI 99 assembler, tests Message-ID: <376@unmvax.UUCP> Date: Sun, 22-Jul-84 13:17:37 EDT Article-I.D.: unmvax.376 Posted: Sun Jul 22 13:17:37 1984 Date-Received: Mon, 30-Jul-84 00:07:09 EDT Organization: Univ. of New Mexico, Albuquerque Lines: 205 To unarchive, remove the first line through and including the dashed line. Then type: % sh Don't forget to strip off the .signature at the end! ------------------------------------------- : Run this with sh NOT csh! echo extracting readint.a cat << //*FUNKYSTUFF*// > readint.a ; Read an Integer from the Terminal ; ; This program reads the decimal representation of a signed ; integer in its character representation from the terminal ; and stores its value (in 2's complement representation) ; in R1. If the values cannot be stored in 16 bits using ; 2's complement representation, an error message is written ; to the terminal. ; extern ER ; ; Initialize R0, R1, R2 and R15. CLR R0; R0 and R1 are used for multiplication CLR R1; LI R2,10; CLR R15; ; ; ; Read the first character. XOP R3,11; SWPB R3; Put character into low byte of R3. CI R3,'-'; JNE L1; INC R15; Set a flag. JMP LP; L1: CI R3,'+'; JNE CK; Jump into the main loop (sick!) ; ; ; Main loop--read a character, check it and update the value in R1. LP: XOP R3,11; SWPB R3; ; Check for a valid character. CK: CI R3,'0'; JLT DN; CI R3,'9'; JGT DN; ; Update R1. AI R3,-'0'; MOV R1,R0; MPY R2,R0; MOV R0,R0; JNE OV; MOV R1,R1; JLT OV; A R3,R1; CI R1,0x8000; JEQ LP; JNO LP; ; ; ; Overflow. OV: XOP ER,14; JMP RT; ; ; ; Done. We need to check for the minint case. Then we ; check for a negative value. DN: CI R1,0x8000; JNE OK; MOV R15,R15; JEQ OV; JMP RT; OK: MOV R15,R15; JEQ RT; NEG R1; RT: B 0x3000; ; ; ; DATA ER: .str "OVERFLOW\\r\\n" //*FUNKYSTUFF*// echo extracting bradd.a cat << //*FUNKYSTUFF*// > bradd.a ; This program implements a recursive version of ; addition using the BLWP instruction. ; ; In addition, this program overlays work spaces ; in an effort to save space. ; ; Initialize the original Workspace and branch to ; the main program. ; LWPI 0x7E0; B MN; ; ; The addition function implements the following ; Pascal function: ; (Arguments are passed by value and available in ; the callee's R10 and R11. The result is placed ; in the callers R12.) ; ; function F1 (A1, A2: integer): integer; ; begin ; if A1 = 0 then ; F1 := A2 ; else ; F1 := F1(A1-1,A2) + 1; ; end; F1: MOV R10,R10; A1 = 0 ? JNE EL; MOV R11,24[R13]; F1 := A2 JMP FI; EL: STWP R1; Set up for recursive call. AI R1,-12; Allocate registers for callee. CI R1,LA; Check for stack overflow. JLT OV; MOV R10,20[R1]; DEC 20[R1]; A1-1 MOV R11,22[R1]; A2 LI R2,F1; BLWP R1; F1(A1-1,A2) INC R12; F1(A1-1,A2) + 1 MOV R12,24[R13]; FI: RTWP; Return ; ; ; ; MAIN PROGRAM MN: XOP NL,14; XOP R0,9; .data EN; .data EN; XOP NL,14; XOP R1,9; .data EN; .data EN; STWP R2; AI R2,-32; MOV R0,20[R2]; MOV R1,22[R2]; LI R3,F1; BLWP R2; XOP NL,14; XOP R12,10; XOP NL,14; JMP MN; EN: B 0x3000; OV: XOP SO,14 XOP NL,14 B 0x3000 SO: .str "STACK OVERFLOW\\n\\r"; NL: .data 0x0A0D .word LA: //*FUNKYSTUFF*// echo extracting add.a cat << //*FUNKYSTUFF*// > add.a ; Implementing the function using the BLWP instruction: ; ; function sum (v1, v2, v3 : integer) : integer; ; begin ; sum := v1 + v2 + v3; ; end; ; ; This file illustrates four techniques for passing ; arguments using the assembly language of the TM 990. ; In all cases, the result is stored in the caller's R0. ; ; B MN; BRANCH TO MAIN PROGRAM. ; ; ; First, we expect to get the values of the arguments ; in R1, R2, R3. ; ; Allocation of registers and the procedure vector. W1: .word 32; Allocate space for 16 Registers P1: .data W1; Procedure Vector for F1. .data F1; ; ; Argument Names. ;R1 EQU 1; ;R2 EQU 2; ;R3 EQU 3; ; Body of the first implementation. F1: MOV R1,(R13); A R2,(R13); A R3,(R13); RTWP; RETURN //*FUNKYSTUFF*// -- --Lee (Ward) {ucbvax,convex,gatech,pur-ee}!unmvax!lee