\chapter{Top Algorithm of the Two C Programs} \section{Algorithm of the Original C Program} \dspaceoff \begin{verbatim} Begin read in file and store in the oggin memory initialise the main components of the cpu set endofprogram to false LOOP for each instruction cycle read cycle to get an instruction value decode and decide the opcode group switch opcode group case group 1 : do group 1 further decode opcode of group 1 execute the opcode instruction case group 2 : do group 2 further decode opcode of group 2 execute the opcode instruction case group 3 : do group 3 further decode opcode of group 3 execute the opcode instruction output the one-line results and the stack (if any) and update pc UNTIL endofprogram is true End. \end{verbatim} \newpage \section{Algorithm of the Revised C Program} \begin{verbatim} Begin make sure only one input data file supplied show title of the machine show introduction messages and instructions show one line of registers names read in file and store in the newogg memory create 15 windows and 1 pad initialise the main components of the cpu loop for each instruction cycle End \end{verbatim} \subsection{Algorithm of the Instruction Cycle} \begin{verbatim} Begin set endofprogram to false LOOP for each instruction cycle if pc not equal to 0 show the previous assembly language mnemonics in assl_win read cycle to get an instruction value decode and decide the opcode group move the basic information of the instruction to expl_win save the previous opcode group switch opcode group case group 1 : decode and execute group 1 opcode,and display results. case group 2 : decode and execute group 2 opcode,and display results. case group 3 : decode and execute group 3 opcode,and display results. lookahead (decode next instruction without executing it and move its assembly language form below the current one) refresh all the window to show the screen display read in a character (ch) if (ch is q) stop the program clear the windows and turn off the highlight functions for next instruction cycle save value of acc UNTIL endofprogram is true End \end{verbatim} The source of the main procedures for decoding and executing the opcodes are held in files newg1.c, newg2.c and newg3.c for groups 1, 2 and 3 respectively.