// file: array_io.isc // author: keller // purpose: demonstrate array input and output in the isc // // RCS: $Id: array_io.isc,v 1.3 1995/04/17 18:23:21 keller Exp $ // // description: // label array_base at the very end of this code is used as // the address of the first location of an array (of longs) // numbers are read from the input device (the standard input) // and stored into this array. When end-of-file is reached, // the numbers are output to the output device. define max_size 4000 // limit on array size for this program // test with: random N | isc array_io.isc // where N is a number not more than max_size above // This program sets the input routine to jump the address in // register end_of_file on end of file. // repeats until end-of-file // accept a input number // store the number in an array // output the array // Convention: specific register assignments will be used for all subroutines register return 0 // standard return address reg register result 1 // standard result register register arg1 2 // first argument register // Other arbitrary register uses use jump_target // use to hold jump target addresses use zero // use to hold 0 use end_of_file // use to hold address of where to go on eof use in_el // pointer to array location for input use out_el // pointer to array location for output use top_el // pointer to top possible element origin 0 // start loading instructions at location 0 // set up standard register contents lim zero 0 // constant 0 lim jump_target io_setup // initialize io jsub jump_target return // // input phase // lim end_of_file eof // set up end-of-file address lim in_el array_base // initialize array element pointer aim in_el -1 // always points to last element input lim top_el array_base // pointer to last possible array element aim top_el max_size aim top_el -1 label in_loop jgt zero in_el top_el // immediate exit if array is full lim jump_target input // load address of input routine jsub jump_target return // get input value aim in_el 1 // point to next location in array store in_el result // put value from result into array lim jump_target in_loop junc jump_target // go back for more input label eof // come here on end of input file // // output phase // lim out_el array_base // initialize array element pointer aim out_el -1 // always points to previous element output label out_loop jgte zero out_el in_el // stop when previous element output was last aim out_el 1 // increment pointer load arg1 out_el // get value from array into arg1 lim jump_target output // load address of output routine jsub jump_target return // put output value lim jump_target out_loop junc jump_target // go back for more output // i/o routines define input_word_loc -1 // fixed location for input word define input_status_loc -2 // fixed location for input status define output_word_loc -3 // fixed location for output word define output_status_loc -4 // fixed location for output status use input_word // register to hold input_word use input_status // register to hold input_status use output_word // register to hold output_word use output_status // register to hold input_status label io_setup // setup registers for i/o lim input_word input_word_loc // memory-mapped input lim input_status input_status_loc // input status lim output_word output_word_loc // memory-mapped output lim output_status output_status_loc // input status junc return label input // input routine, returns result in register 'result' use temp // temporary register lim jump_target input // set up to loop back store input_status zero // wait for input ready load temp input_status // get input status jlt end_of_file temp zero // jump on end-of-file load result input_word // load from input word jeq jump_target temp zero // loop back if previous input not done junc return release temp label output // output routine, outputs word in register 'arg1' use temp // temporary register load temp output_status // get output status in temp lim jump_target output // set up loop address jeq jump_target temp zero // wait for output ready store output_word arg1 // set up for output of result store output_status zero // request output junc return release temp label array_base // the array will be stored starting here