"; $text .= dechex($line_num)." : "; if ($opcode == "LOAD"){ //Load the data into ACC. $text .= "10"; $text1 = decbin($address); for ($i = 8-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "LOADM"){ //Load the contents of data memory at location X into the accumulator [ACC]. $text .= "00000"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "STORM"){ //Move the contents of ACC to data memory location X. $text .= "00001"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "JUMPM"){ //Take the next instruction from instruction memory location X. $text .= "00010"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "JUMP_MQ"){ //Take the next instruction from instruction memory location X, if the number in MQ is non-negative. $text .= "00011"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "JUMP_C"){ //Take the next instruction from instruction memory location X, if the carry flag is set. $text .= "00100"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "JUMP_OF"){ //Take the next instruction from instruction memory location X, if the overflow/underflow flag is set. $text .= "00101"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "ADD"){ //Add the contents of data memory location X to ACC; put the result in ACC. Set flags as appropriate for the events carry/shift out, and overflow/underflow. $text .= "00110"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "AND"){ //AND the contents of ACC and the contents of data memory location X. $text .= "00111"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "STOR_IO"){ //Write the value in ACC to an I/O output port. $text .= "01000"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "LOAD_IO"){ //Load a value from an I/O device (DIP switches) into the ACC. $text .= "01001"; $text1 = decbin($address); for ($i = 5-strlen($text1); $i > 0; $i--) $text .="0"; $text .= $text1." ;"; fwrite($handle2, "$text\r\n"); } else if ($opcode == "INC"){ //Increment ACC, set flag for overflow/underflow. $text .= "1100100000 ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "DEC"){ //Decrement ACC, set flag for overflow/underflow. $text .= "1101000000 ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "LSH"){ //Shift the contents of ACC left by one bit, set flags for carry out. $text .= "1101100000 ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "RSH"){ //Shift the contents of ACC right by one bit, set flags for carry out. $text .= "1110000000 ;"; $text1 = decbin($address); fwrite($handle2, "$text\r\n"); }else if ($opcode == "INV"){ //Invert the contents of ACC. $text .= "1110100000 ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "SWAP"){ //Swap the contents of MQ and ACC. $text .= "1111000000 ;"; fwrite($handle2, "$text\r\n"); }else if ($opcode == "LOAD_MMQ"){ //Load the contents of memory at the location specified by the value in MQ into ACC. $text .= "1111100000 ;"; fwrite($handle2, "$text\r\n"); } ++$line_num; } for ($j = $line_num ; $j < 32; $j ++) $add_text .= dechex($j)." : 0000000000 ;\r\n"; fwrite($handle2, "$add_text \r\nEND;"); fclose($handle); fclose($handle2); ?>