home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
- Cardiac
-
- Copyright (c) 1987 by Cyrus M. Patel
-
- Permission is granted for CPCUG and other not-for-profit
- oganizations to publish the source and executable
- portions of my program.
-
-
-
- Cardiac is written in Turbo Pascal 3.00 or above. It
- requires a minimum of 1 disk drive, 196K, and a monitor.
-
- Cardiac is a language developed to teach beginning computer
- users/programmers how the computer "thinks". It shows the
- beginner how the computer does a simple instruction, as in BASIC
- and converts it to simpler instructions, for example X = 2 + 3,
- would be converted to load the accumulator with 2, then add 2 to
- it, placing the result back into the accumulator, and finally
- storing the contents of the accumulator into the location X.
- Cardiac, created with that in mind, contains only 100 storage
- locations (0 through 99) used for both instructions, and data,
- which can be inter-mixed.
-
- The basic structure of a Cardiac is the following:
-
- 1234567890 <-- Column numbers (for reference), please
- note that anything after column 9 is
- used as a comment (upto column 79).
- 666666666 <-- This tells the compiler that
- instructions follow.
- II CLL <-- II is the location number where
- the instruction is placed (starts
- at 01).
- C is the command (0 through 9).
- LL is usually the location number
- that the command has to be done
- with.
- 777777777 <-- The tells the compiler that data
- follows and the instructions are
- done with.
- PNNN <-- -NNN is the data, the P is optional
- as it indicates a positive (+) or
- negative (-) number. NNN is the number
- (0 through 9).
- 888888888 <-- Tells the compiler that data is finished.
- 999999999 <-- Tells the compiler that the program is
- finished.
-
-
-
-
-
-
-
-
- Cardiac - Copyright (c) 1987 Cyrus M. Patel
-
-
-
-
-
-
-
-
-
-
- The following is a list of the commands:
-
- Command What it does.
- ------- -----------------------------------------------
- 0LL Reads a number from the data, and places
- contents at location LL.
- 1LL Load a number into the accumulator, from
- location LL.
- 2LL Add contents of accumulator to location
- LL, and place result into accumulator.
- 3LL Branch on Negative (BON), if contents of
- accumulator is negative, then branch to
- location LL.
- 4LR Shift, this instructions shifts the contents
- of the accumulator L places Left, then R
- places Right. For example to clear the
- accumulator (put a zero there), you would
- just give the instruction 499, meaning
- shift the accumulator 9 places left, then
- 9 places right.
- 5LL Print the contents of location LL.
- 6LL Store the accumulator into the location LL.
- 7LL Subtract accumulator - location LL.
- 8LL Jump (goto) location LL, and do that
- instruction.
- 9LL Stop program, halt, LL may be anything.
-
- The following are idiosyncrasy of the Cardiac compiler.
-
- 1) The location 00 is reserved for the number 01, and
- can not be change, but it can be used in calculations.
-
- 2) The location 99 is reserved for the location of the
- of the instruction following the last jump (goto)
- instruction + 800, so if the statement was:
-
- 05 897 Goto location 90.
- .
- .
- .
- 97 080 Read the next data statement and place it
- 98 180 in location 80, then load it into the acc.
- 777777777 End of instructions, beginning of data.
-
- Please note, that you do NOT specify location 99, the
- compiler will automatically do so. It may be used as
- a return statement from a subroutine.
-
-
-
-
-
-
-
-
- Cardiac - Copyright (c) 1987 Cyrus M. Patel
-
-
-
-
-
-
-
-
-
-
-
- 3) The compiler will only execute 500 statements, so that
- if the users is in an infinite loop, it will stop
- and tell the user that the program has stopped due to
- too many statements executed. The maximum number of
- statements can be changed in the source code.
-
- 4) The accumulator's minimum number is -9999, and maximum
- is 9999. But the storage location's [0 - 99] minimum
- is -999, and maximum is 999. When placing the
- accumulator's contents into a storage location, if
- the accumulator is greater than 999, or less than -999,
- Cardiac will automatically truncate the number, then
- inform the user of this.
-
-
- To run a Cardiac program you must first place the source
- code into a separate text file (I'll call it TEST.HRT). Then at
- the DOS prompt typing 'HRT TEST' (without the quotes), which will
- load Cardiac and then instruct it to load and run the file called
- TEST.HRT, and place the results into a file called TEST.OUT.
-
- After compiling Cardiac will execute the program and display
- the results. Then it will ask you if you want a profile. A
- profile is a list of what statements were executed, how many
- times they were executed, what the memory locations look like
- after the program stopped executing, and the data list.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Cardiac - Copyright (c) 1987 Cyrus M. Patel
-
-
-
-
-
-
-
-
-
-
-
- The following is a run able Cardiac program that adds two
- numbers, then subtracts the two numbers, and repeats this until
- a number < 0 is read in as the first number.
-
- This program is also on the disk in a file called TEST-1.HRT.
-
-
- 666666666 Start of program.
- 01 499 clear accumulator (not necessary, but nice)
- 02 050 read 1st # into 50
- 03 150 load 1st # into accumulator
- 04 320 if accumulator <0 then goto 20 BON (branch on neg.)
- 05 051 read 2nd # into 51
- 06 251 add 2nd # to accumulator.
- 07 655 store sum in 55
- 08 150 load 1st # into accumulator
- 09 751 subtract 2nd # from accumulator
- 10 656 store difference. in 56
- 11 550 print 1st #
- 12 551 print 2nd #
- 13 555 print sum
- 14 556 print difference
- 15 801 goto do all over again...
- 20 999 end...
- 50 000 storage for 1st # these statements are not necessary,
- 51 000 storage for 2nd # but they help to keep track of storage
- 55 000 storage for sum locations used for data...
- 56 000 storage for difference
- 777777777 End of program, beginning of data
- 002 first number
- 003 second number
- -999 tells Cardiac that the program is done
- 888888888 End of data
- 999999999 End of source code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Cardiac - Copyright (c) 1987 Cyrus M. Patel
-
-
-
-
-
-
-
-
-
-
-
- The following is a run able Cardiac program that multiplies
- two numbers. It also shows how the "subroutine" process works in
- Cardiac.
-
- This program is also on the disk in a file called TEST-2.HRT.
-
-
- 666666666 Start of program
- 01 050 First number to multiply by
- 02 051 second number, please note both numbers must be positive
- 03 875 Jump to location 75, and do routine
- 04 550 Print 1st number
- 05 551 Print 2nd number
- 06 552 Print 1st * 2nd number
- 07 999 All done.
- 75 150 Load first number
- 76 700 Subtract 1 from it (location 00 always contains 1)
- 77 655 Store it at the temporary location
- 78 151 Load the second number, and
- 79 656 store it at the temporary location
- 80 199 Load return statement and store it for safe keeping.
- 81 697 at location 97.
- 82 155 Load the temporary number.
- 83 700 Subtract 1 from it (location 00 always contains 1)
- 84 395 If negative then done, goto 95
- 85 655 otherwise store it back again.
- 86 156 Load the second number, and
- 87 251 add the contents of the original number,
- 88 656 and store it back at location 56
- 89 882 Go back to 82 and do it until done
- 95 156 Load the answer,
- 96 652 and store it at location 52.
- 97 000 And this is the return statement.
- 50 000 Location of 1st number
- 51 000 Location of 2nd number
- 52 000 Location of 1st number * 2nd number
- 55 000 Temp storage for 1st number
- 56 000 Temp storage for 2nd number
- 777777777 Done with instructions, now for the data
- 009
- 007
- -999
- 888888888 Done with data.
- 999999999 Done with program.
-
-
-
-
-
-
-
-
-
-
- Cardiac - Copyright (c) 1987 Cyrus M. Patel
-
-
-
-
-