// file: array.isc // author: Robert Keller // purpose: adds up the values in an array, computes sum, and prints value // The array is initialized with 5 3 6 2 9, making the sum 25 // // Consider using the following stuff, up to the main program, verbatim // // define standard register usage first register return 0 // standard return address reg register result 1 // standard result register register arg1 2 // first argument register // define fixed locations used for i/o // (locations -1 to -4 are "wired-in" to the ISC for memory-mapped i/o) 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_address // reserve for input routine address use output_address // reserve for output routine address use jump_address // use to hold one-shot jump addresses // // The main program starts here // origin 0 // start loading instructions at location 0 // set up standard register contents lim zero 0 // constant 0 lim jump_address io_setup // initialize io jsub jump_address return use array use count use sum use zero use value use done use loop lim array array_loc // set up test array lim value 5 store array value aim array 1 lim value 3 store array value aim array 1 lim value 6 store array value aim array 1 lim value 2 store array value aim array 1 lim value 9 store array value lim array array_loc // initialize array base lim count 5 // initialize array count lim sum 0 // initialize sum lim zero 0 // comparison value lim done done_loc // address of instruction following lim loop loop_loc // address of next instruction label loop_loc jlte done count zero // jump if <= 0 load value array // load register next array value add sum value sum // add the next number to the sum aim array 1 // add 1 to the array address aim count -1 // add -1 to the count junc loop // go back and compare label done_loc copy arg1 sum jsub output_address return // put output value junc zero // // Consider using the following stuff verbatim // // // definitions of input/output registers // 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 trace 0 // // routine to set up registers for i/o once and for all // label io_setup lim output_word output_word_loc // memory-mapped output lim output_status output_status_loc // input status lim input_word input_word_loc // memory-mapped output lim input_status input_status_loc // input status lim input_address input // address of input routine lim output_address output // address of output routine junc return use temp // // input routine // returns result in register 'result' // label input lim jump_address input // set up to loop back store input_status zero // wait for input ready load temp input_status // get input status jlt zero temp zero // quit (jump to 0) on end-of-file load result input_word // load from input word jeq jump_address temp zero // loop back if previous input not done junc return // // output routine // outputs value in register arg1 // label output load temp output_status // get output status in temp lim jump_address output // set up loop address jeq jump_address temp zero // wait for output ready store output_word arg1 // set up for output of result store output_status zero // request output junc return label array_loc