Post Reply 
TI-58/59 SBR question
06-10-2024, 11:54 AM (This post was last modified: 06-10-2024 12:11 PM by Maximilian Hohmann.)
Post: #8
RE: TI-58/59 SBR question
Hello!

(06-10-2024 11:35 AM)Gene Wrote:  My emulator example is flawed !

I also had to try this out. Few people may know, but a person called Philippe Tiwolle created a compiler for the Ti 58/59. For input it takes a subset of C (that he calls "T" for Texas instruments) and generates ready-to-use programs for the calculator: https://ti59compiler.wixsite.com/ti59 (*)

So I made a tiny tiny little program that calls two different subroutines as the result of a branch:

Code:

// A test for calling subroutines after a conditional test
#include <math.h>
#include <stdio.h>
#include <unistd.h>

#include "printerEmulator.c"

#define input(identifier, stop)         printf("? ");         scanf("%lf", &identifier)
#define inputKey(identifier, key, stop) printf("%s ? ", key); scanf("%lf", &identifier)
#define display(expression)             printf("%lf\n", expression)
#define pause(expression, duration)     printf("%lf\n", expression); sleep(duration)

double g; // g is a global variable

// This procedure stores 1 in variable a
void procedure1(double *a)
{
        *a=1;
}

// This procedure stores 2 in variable a
void procedure2(double *a)
{
        *a=2;
}


// Main module
void main()
{    
    double a; // a is a local variable

    g=1;

    if (g == 0) {
        procedure1(&a);
    }
    else {
        procedure2(&a);
    }
}

The compiler translates it to some kind of metacode first:
Code:

SBR R/S
R/S
RST

// A test for calling subroutines after a conditional test
// g is a global variable

// This procedure stores 1 in variable a
2nd Lbl -
    1 STO 2nd Ind 01
    INV SBR

// This procedure stores 2 in variable a
2nd Lbl (
    2 STO 2nd Ind 02
    INV SBR

// Main module
2nd Lbl R/S
    // a and b are local variables
    1 STO 00
    RCL 00 x><t
    0 INV 2nd x=t )             
        3 STO 01 SBR -
        GTO .
    2nd Lbl )
        3 STO 02 SBR (
    2nd Lbl .
    INV SBR

and finally to a sequence of keystrokes:
Code:

000 71 SBR
001 91 R/S
002 91 R/S
003 81 RST
004 76 2nd Lbl
005 75 -
006 01 1
007 72 STO 2nd Ind
008 01 01
009 92 INV SBR
010 76 2nd Lbl
011 53 (
012 02 2
013 72 STO 2nd Ind
014 02 02
015 92 INV SBR
016 76 2nd Lbl
017 91 R/S
018 01 1
019 42 STO
020 00 00
021 43 RCL
022 00 00
023 32 x><t
024 00 0
025 22 INV
026 67 2nd x=t
027 54 )
028 03 3
029 42 STO
030 01 01
031 71 SBR
032 75 -
033 61 GTO
034 93 .
035 76 2nd Lbl
036 54 )
037 03 3
038 42 STO
039 02 02
040 71 SBR
041 53 (
042 76 2nd Lbl
043 93 .
044 92 INV SBR

It works by replacing the call to the subroutine with the call to a label from where the subroutine is called. I am not sure if this will work in all circumstances...

Regads
Max


(*) For those who want to try it for themselves: in order to work on MacOS, after downloading and unzipping, the following change has to be made in the makefile: Replace -lfl with -ll in two places and rename the resulting programs ti59 and ti59b to ti59.exe and ti59b.exe (or otherwise modifiy the "compile.sh").

NB: This is not the only compiler written for the Ti 59. Google finds a master's thesis (> 600 pages!) about a "cross compiler and virtual memory management system for the Ti 59" here: https://archive.org/details/designndimpl...8/mode/2up
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
TI-58/59 SBR question - Namir - 06-09-2024, 10:53 PM
RE: TI-58/59 SBR question - toml_12953 - 06-10-2024, 12:49 AM
RE: TI-58/59 SBR question - Namir - 06-10-2024, 03:29 AM
RE: TI-58/59 SBR question - Gene - 06-10-2024, 01:53 AM
RE: TI-58/59 SBR question - Namir - 06-10-2024, 11:31 AM
RE: TI-58/59 SBR question - Gene - 06-10-2024, 11:35 AM
RE: TI-58/59 SBR question - Maximilian Hohmann - 06-10-2024 11:54 AM
RE: TI-58/59 SBR question - toml_12953 - 06-14-2024, 02:34 PM
RE: TI-58/59 SBR question - Pierre - 06-16-2024, 02:06 PM
RE: TI-58/59 SBR question - Pierre - 06-16-2024, 03:22 PM
RE: TI-58/59 SBR question - Thomas Okken - 06-15-2024, 09:13 AM
RE: TI-58/59 SBR question - Namir - 06-17-2024, 06:20 AM
RE: TI-58/59 SBR question - Pierre - 06-17-2024, 07:55 AM



User(s) browsing this thread: 1 Guest(s)