home *** CD-ROM | disk | FTP | other *** search
/ Complete Bookshop / CompleteWorkshop.iso / compute / cardiac / hrt.doc next >
Encoding:
Text File  |  1987-06-30  |  10.7 KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.                                        Cardiac
  6.  
  7.                          Copyright (c) 1987 by Cyrus M. Patel
  8.  
  9.                Permission is granted for CPCUG and other not-for-profit
  10.                   oganizations to publish the source and executable 
  11.                                portions of my program.
  12.  
  13.  
  14.  
  15.              Cardiac  is  written  in Turbo Pascal  3.00  or  above.   It 
  16.         requires a minimum of 1 disk drive, 196K, and a monitor.
  17.  
  18.              Cardiac  is a language developed to teach beginning computer 
  19.         users/programmers  how  the  computer  "thinks".   It  shows  the 
  20.         beginner how the computer does a simple instruction,  as in BASIC 
  21.         and converts it to simpler instructions,  for example X = 2 +  3, 
  22.         would be converted to load the accumulator with 2,  then add 2 to 
  23.         it,  placing  the result back into the accumulator,  and  finally 
  24.         storing  the  contents  of the accumulator into the  location  X.  
  25.         Cardiac,  created  with that in mind,  contains only 100  storage 
  26.         locations  (0 through 99) used for both instructions,  and  data, 
  27.         which can be inter-mixed.
  28.  
  29.              The basic structure of a Cardiac is the following:
  30.  
  31.                   1234567890  <-- Column numbers (for reference), please
  32.                                   note that anything after column 9 is
  33.                                   used as a comment (upto column 79).
  34.                   666666666   <-- This tells the compiler that
  35.                                   instructions follow.
  36.                    II   CLL   <-- II is the location number where
  37.                                   the instruction is placed (starts
  38.                                   at 01).
  39.                                   C is the command (0 through 9).
  40.                                   LL is usually the location number
  41.                                   that the command has to be done
  42.                                   with.
  43.                   777777777   <-- The tells the compiler that data
  44.                                   follows and the instructions are
  45.                                   done with.
  46.                     PNNN      <-- -NNN is the data, the P is optional
  47.                                   as it indicates a positive (+) or 
  48.                                   negative (-) number. NNN is the number
  49.                                   (0 through 9).
  50.                   888888888   <-- Tells the compiler that data is finished.
  51.                   999999999   <-- Tells the compiler that the program is
  52.                                   finished.
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.                     Cardiac  -  Copyright (c) 1987  Cyrus M. Patel
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.              The following is a list of the commands:
  73.  
  74.                   Command   What it does.
  75.                   -------  -----------------------------------------------
  76.                     0LL    Reads a number from the data, and places 
  77.                             contents at location LL.
  78.                     1LL    Load a number into the accumulator, from
  79.                             location LL.
  80.                     2LL    Add contents of accumulator to location
  81.                             LL, and place result into accumulator.
  82.                     3LL    Branch on Negative (BON), if contents of
  83.                             accumulator is negative, then branch to
  84.                             location LL.
  85.                     4LR    Shift, this instructions shifts the contents
  86.                             of the accumulator L places Left, then R
  87.                             places Right.  For example to clear the
  88.                             accumulator (put a zero there), you would
  89.                             just give the instruction 499, meaning
  90.                             shift the accumulator 9 places left, then
  91.                             9 places right.
  92.                     5LL    Print the contents of location LL.
  93.                     6LL    Store the accumulator into the location LL.
  94.                     7LL    Subtract accumulator - location LL.
  95.                     8LL    Jump (goto) location LL, and do that
  96.                             instruction.
  97.                     9LL    Stop program, halt, LL may be anything.
  98.  
  99.              The following are idiosyncrasy of the Cardiac compiler.
  100.  
  101.              1) The location 00 is reserved for the number 01, and
  102.                   can not be change, but it can be used in calculations.
  103.  
  104.              2) The location 99 is reserved for the location of the
  105.                   of the instruction following the last jump (goto)
  106.                   instruction + 800, so if the statement was:
  107.  
  108.                   05   897   Goto location 90.
  109.                      .
  110.                      .
  111.                      .
  112.                   97   080   Read the next data statement and place it
  113.                   98   180   in location 80, then load it into the acc.
  114.                  777777777  End of instructions, beginning of data.
  115.  
  116.                   Please note, that you do NOT specify location 99, the
  117.                   compiler will automatically do so.  It may be used as
  118.                   a return statement from a subroutine.
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.                     Cardiac  -  Copyright (c) 1987  Cyrus M. Patel
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.              3) The compiler will only execute 500 statements, so that
  140.                   if the users is in an infinite loop, it will stop
  141.                   and tell the user that the program has stopped due to
  142.                   too many statements executed.  The maximum number of
  143.                   statements can be changed in the source code. 
  144.  
  145.              4) The accumulator's minimum number is -9999, and maximum
  146.                   is 9999.  But the storage location's [0 - 99] minimum
  147.                   is -999, and maximum is 999.  When placing the
  148.                   accumulator's contents into a storage location, if
  149.                   the accumulator is greater than 999, or less than -999,
  150.                   Cardiac will automatically truncate the number, then
  151.                   inform the user of this.
  152.  
  153.  
  154.              To  run  a Cardiac program you must first place  the  source 
  155.         code into a separate text file (I'll call it TEST.HRT).   Then at 
  156.         the DOS prompt typing 'HRT TEST' (without the quotes), which will 
  157.         load Cardiac and then instruct it to load and run the file called 
  158.         TEST.HRT, and place the results into a file called TEST.OUT.
  159.  
  160.              After compiling Cardiac will execute the program and display 
  161.         the  results.   Then  it will ask you if you want a  profile.   A 
  162.         profile  is  a list of what statements were  executed,  how  many 
  163.         times  they were executed,  what the memory locations  look  like 
  164.         after the program stopped executing, and the data list.
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.                     Cardiac  -  Copyright (c) 1987  Cyrus M. Patel
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.              The following is a run able Cardiac program that adds two
  206.         numbers, then subtracts the two numbers, and repeats this until
  207.         a number < 0 is read in as the first number.
  208.  
  209.           This program is also on the disk in a file called TEST-1.HRT. 
  210.  
  211.  
  212.         666666666   Start of program.
  213.          01   499   clear accumulator  (not necessary, but nice)
  214.          02   050   read 1st # into 50
  215.          03   150   load 1st # into accumulator
  216.          04   320   if accumulator <0 then goto 20  BON (branch on neg.)
  217.          05   051   read 2nd # into 51
  218.          06   251   add 2nd # to accumulator.
  219.          07   655   store sum in 55
  220.          08   150   load 1st # into accumulator
  221.          09   751   subtract 2nd # from accumulator
  222.          10   656   store difference. in 56
  223.          11   550   print 1st #
  224.          12   551   print 2nd #
  225.          13   555   print sum
  226.          14   556   print difference
  227.          15   801   goto do all over again...
  228.          20   999   end...
  229.          50   000   storage for 1st #   these statements are not necessary,
  230.          51   000   storage for 2nd #   but they help to keep track of storage
  231.          55   000   storage for sum     locations used for data...
  232.          56   000   storage for difference
  233.         777777777   End of program, beginning of data
  234.            002      first number
  235.            003      second number
  236.           -999      tells Cardiac that the program is done
  237.         888888888   End of data
  238.         999999999   End of source code
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.                     Cardiac  -  Copyright (c) 1987  Cyrus M. Patel
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.              The following is a run able Cardiac program that multiplies
  272.         two numbers.  It also shows how the "subroutine" process works in
  273.         Cardiac.
  274.  
  275.           This program is also on the disk in a file called TEST-2.HRT. 
  276.  
  277.  
  278.         666666666   Start of program
  279.          01   050   First number to multiply by
  280.          02   051    second number, please note both numbers must be positive
  281.          03   875   Jump to location 75, and do routine
  282.          04   550   Print 1st number
  283.          05   551   Print 2nd number
  284.          06   552   Print 1st * 2nd number
  285.          07   999   All done.
  286.          75   150   Load first number
  287.          76   700   Subtract 1 from it (location 00 always contains 1)
  288.          77   655   Store it at the temporary location
  289.          78   151   Load the second number, and
  290.          79   656    store it at the temporary location
  291.          80   199   Load return statement and store it for safe keeping.
  292.          81   697    at location 97.
  293.          82   155   Load the temporary number.
  294.          83   700   Subtract 1 from it (location 00 always contains 1)
  295.          84   395   If negative then done, goto 95
  296.          85   655   otherwise store it back again.
  297.          86   156   Load the second number, and
  298.          87   251    add the contents of the original number,
  299.          88   656    and store it back at location 56
  300.          89   882   Go back to 82 and do it until done
  301.          95   156   Load the answer,
  302.          96   652    and store it at location 52.
  303.          97   000   And this is the return statement.
  304.          50   000   Location of 1st number
  305.          51   000   Location of 2nd number
  306.          52   000   Location of 1st number * 2nd number
  307.          55   000   Temp storage for 1st number
  308.          56   000   Temp storage for 2nd number
  309.         777777777 Done with instructions, now for the data
  310.            009
  311.            007
  312.           -999
  313.         888888888 Done with data.
  314.         999999999 Done with program.
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.                     Cardiac  -  Copyright (c) 1987  Cyrus M. Patel
  326.  
  327.  
  328.  
  329.  
  330.  
  331.