// simplesum.iml (c) 1997 - 2000 Kari Laitinen // The following program displays twice the text // " + ", and expects the user of the imaginary computer // to use the keyboard and type in two single-digit numbers. // The program calculates the sum of the numbers the user // typed and displays it on the screen after the sign =. // When the program is executed with numbers 7 and 9 // the screen should show + 7 + 9 = 16 beginning_of_program: set_memory_pointer text_for_number_input call_subroutine display_text first_number_not_given: jump_if_input_not_ready first_number_not_given input_byte_to_register_a output_byte_from_register_a // Echo the number to screen subtract_value_from_register_a '0' move_content_of_register_a_to_b set_memory_pointer text_for_number_input call_subroutine display_text second_number_not_given: jump_if_input_not_ready second_number_not_given input_byte_to_register_a output_byte_from_register_a // Echo the number to screen subtract_value_from_register_a '0' add_register_b_to_a push_register_a_to_stack // Save the result of adding set_memory_pointer text_for_result call_subroutine display_text pop_register_a_from_stack // the result back to a load_register_b_with_value 9 jump_if_register_a_greater_than_b display_two_numbers display_one_number: add_value_to_register_a '0' output_byte_from_register_a jump_to_address end_of_program display_two_numbers: // The result is more than 9, but it cannot be more than 18. load_register_b_with_value '1' output_byte_from_register_b subtract_value_from_register_a 10 add_value_to_register_a '0' output_byte_from_register_a end_of_program: stop_processing display_text: load_register_a_from_memory jump_if_register_a_zero end_of_display_text output_byte_from_register_a increment_memory_pointer jump_to_address display_text end_of_display_text: return_to_calling_program text_for_number_input: STRING " + " text_for_result: STRING " = "