Post Reply 
(42S) CARDIAC
10-11-2014, 08:54 PM (This post was last modified: 07-31-2022 10:11 AM by Thomas Klemm.)
Post: #1
(42S) CARDIAC
Quote:The acronym CARDIAC stands for "CARDboard Interactive Aid to Computation." It was developed by David Hagelbarger at Bell Labs as a tool for teaching how computers work in a time when access to real computers was extremely limited. The CARDIAC kit consists of a folded cardboard "computer" and an instruction manual. In July 1969, the Bell Laboratories Record contained an article describing the system and the materials being made available to teachers for working with it.
-- Brian L. Stuart, A discription of the CARDIAC

This program is a CARDIAC-simulator. It allows to run programs written for CARDIAC on your HP-42S.
In order to work properly we need registers 00-99. Thus you have to set the size accordingly:

SIZE 100

The simulator allows to load a CARDIAC-program (deck of cards) into the memory of the HP-42S. These cards have to be stored in a matrix. This is an example of a program that counts to 10.

Program Listing:
Code:
04     009     n      DATA    009
05     000     cntr   DATA    000
                              
10     100            CLA     00      Initialize the counter
11     605            STO     cntr    
12     104     loop   CLA     n       If n < 0, exit
13     322            TAC     exit
14     505            OUT     cntr    Output a card
15     105            CLA     cntr    Increment the card
16     200            ADD     00
17     605            STO     cntr
18     104            CLA     n       Decrement n
19     700            SUB     00
20     605            STO     n
21     812            JMP     loop
22     900     exit   HRS     00

Create a 1×2 Matrix and set it to GROW:

1 ENTER 2
MATRIX.NEW
EDIT
GROW

Now enter all the numbers of the listing:
Code:
[
  2, 800,
 10, 100,
 11, 605,
 12, 104,
 13, 322,
 14, 505,
 15, 105,
 16, 200,
 17, 605,
 18, 104,
 19, 700,
 20, 604,
 21, 812,
 22, 900,
  4,   9,
  2, 810,
]

STO "COUNT"

The first row [2, 800] is just the boot-loader program.
At the end we write n = 9 into register 4 [4, 9] and then we jump to line 10 to start the program [2, 810].

This loads the program from the matrix into the memory and runs it:

RCL "COUNT"
XEQ "CARDIAC"

Make sure to set flag 21 when using Free42 or it will run too fast to notice anything.
Alternatively you may add a PSE in the implementation of OUT (LBL 05).

If everything is correct you should see:

R05=1
R05=2
R05=3
R05=4
R05=5
R05=6
R05=7
R05=8
R05=9
R05=10


The program is still loaded in the memory of the HP-42S. Let's assume we want to count to 100 instead:

99 STO 04
10 XEQ 99


R05=1
R05=2
R05=3
R05=4
(...)
R05=97
R05=98
R05=99
R05=100


Implementation details
The registers 00-99 are used as memory. The accumulator acc and the program-counter pc are kept on the stack.
The instruction register ir consists of two parts: the code and the address addr. Furthermore the address consists of the left and the right digit. They are used in the "shift accumulator" operator.

Here's an example:

ir = 835
code = 8
addr = 35
left = 3
right = 5


Links

Listing
Code:
;---------------------;------------------
{ 207-Byte Prgm }     ;
LBL "CARDIAC"         ;
;------- INIT --------;------------------
EDIT                  ; 1:1=2
←                     ; n:2=0
CF 00                 ;
CLRG                  ;
1                     ; 1
STO 00                ; 1
CLST                  ; 0 0
;---- MAIN LOOP ------;------------------
LBL 99                ; acc pc
RCL IND ST X          ; acc pc ir
X<>Y                  ; acc ir pc
1                     ; acc ir pc 1
+                     ; acc acc ir pc'
X<>Y                  ; acc acc pc' ir
1E2                   ; acc pc' ir 100
÷                     ; acc acc pc' code.addr
FP                    ; acc acc pc' .addr
XEQ IND ST L          ; acc acc pc' .addr
FC? 00                ; acc acc pc' .addr
GTO 99                ; acc acc pc' .addr
;---------------------;------------------
EXITALL               ;
CF 00                 ;
CLST                  ;
RTN                   ;
;------- INP ---------;------------------
LBL 00                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
OLD                   ; acc pc addr card
→                     ; acc pc addr card'
STO IND ST Y          ; acc pc addr card'
RDN                   ; card' acc pc addr
RDN                   ; addr card' acc pc
RTN                   ; acc addr
;------- CLA ---------;------------------
LBL 01                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
X<>Y                  ; acc acc addr pc
RCL IND ST Y          ; acc addr pc acc'
X<>Y                  ; acc addr acc' pc
RTN                   ; acc' pc
;------- ADD ---------;------------------
LBL 02                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
X<> ST Z              ; acc addr pc acc
RCL+ IND ST Z         ; acc addr pc acc'
X<>Y                  ; acc addr acc' pc
RTN                   ; acc' pc
;------- TAC ---------;------------------
LBL 03                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
R↑                    ; acc pc addr acc
X<0?                  ; acc pc addr acc
GTO 10                ; acc pc addr acc
RCL ST Z              ; pc addr acc pc
RTN                   ; acc pc
LBL 10                ; acc pc addr acc
X<>Y                  ; acc pc acc addr
RTN                   ; acc addr
;------- SFT ---------;------------------
LBL 04                ; acc pc .addr
10                    ; acc pc .addr 10
×                     ; acc acc pc left.right
ENTER                 ; acc pc left.right left.right
IP                    ; acc pc left.right left
10↑X                  ; acc pc left.right 10↑left
R↑                    ; pc left.right 10↑left acc
×                     ; pc pc left.right acc'
1E4                   ; pc left.right acc' 10000
÷                     ; pc pc left.right .acc'
LASTX                 ; pc left.right .acc' 10000
X<>Y                  ; pc left.right 1000 .acc'
FP                    ; pc left.right 1000 .acc'
×                     ; pc pc left.right acc"
X<>Y                  ; pc pc acc" left.right
FP                    ; pc pc acc" .right
10                    ; pc acc" .right 10
×                     ; pc pc acc" right
10↑X                  ; pc pc acc" 10↑right
÷                     ; pc pc pc acc~
IP                    ; pc pc pc acc`
X<>Y                  ; pc pc acc` pc
RTN                   ; acc` pc
;------- OUT ---------;------------------
LBL 05                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
VIEW IND ST X         ; acc acc pc addr
RDN                   ; addr acc acc pc END 
RTN                   ; acc pc
;------- STO ---------;------------------
LBL 06                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
X<> ST Z              ; acc addr pc acc
STO IND ST Z          ; acc addr pc acc
1E3                   ; addr pc acc 1000
÷                     ; addr addr pc .acc
LASTX                 ; addr pc .acc 1000
X<>Y                  ; addr pc 1000 .acc
FP                    ; addr pc 1000 .acc'
×                     ; addr addr pc acc'
X<> IND ST Z          ; addr addr pc acc
X<>Y                  ; addr addr acc pc
RTN                   ; addr pc
;------- SUB ---------;------------------
LBL 07                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
X<> ST Z              ; acc addr pc acc
RCL- IND ST Z         ; acc addr pc acc'
X<>Y                  ; acc addr acc' pc
RTN                   ; acc' pc
;------- JMP ---------;------------------
LBL 08                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
X<>Y                  ; acc acc addr pc
8E2                   ; acc addr pc 800
+                     ; acc acc addr pc'
STO 99                ; acc acc addr pc'
RDN                   ; pc' acc acc addr
RTN                   ; acc addr
;------- HRS ---------;------------------
LBL 09                ; acc pc .addr
1E2                   ; acc pc .addr 100
×                     ; acc acc pc addr
X<>Y                  ; acc acc addr pc
RDN                   ; pc acc acc addr
SF 00                 ; pc acc acc addr
END                   ; acc addr
;---------------------;------------------

Attachment
Code:
Archive:  cardiac.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     5504  10-11-2014 22:42   cardiac.txt
      210  10-11-2014 22:42   cardiac.raw
     2206  10-11-2014 22:43   cardiac.py
---------                     -------
     7920                     3 files


Attached File(s)
.zip  cardiac.zip (Size: 2.06 KB / Downloads: 4)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(42S) CARDIAC - Thomas Klemm - 10-11-2014 08:54 PM
RE: (HP-42S) CARDIAC - Thomas Klemm - 10-12-2014, 06:15 PM
RE: (HP-42S) CARDIAC - Dave Britten - 10-13-2014, 07:30 PM
RE: (HP-42S) CARDIAC - Thomas Klemm - 10-13-2014, 09:06 PM
RE: (HP-42S) CARDIAC - Dave Britten - 10-13-2014, 09:27 PM
RE: (HP-42S) CARDIAC - Thomas Klemm - 10-16-2014, 09:49 PM



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