// ascii.iml (c) 1997 - 2000 Kari Laitinen // This program calls "print_register_a_in_decimal_form" // to print the ascii code of the character typed in // from the keyboard. beginning_of_main_program: call_subroutine read_and_echo_a_character call_subroutine print_space call_subroutine print_register_a_in_decimal_form end_of_main_program: stop_processing // Subroutine "read_and_echo_a_character" waits until the // user of the program has hit some key on the keyboard. // Echoing means that the read character is displayed on // the screen as well. The subroutine brings the ascii-code // the character to the calling program in register A. read_and_echo_a_character: jump_if_input_not_ready read_and_echo_a_character input_byte_to_register_a output_byte_from_register_a return_to_calling_program // Subroutine "print_space" prints a space on the screen without // loosing the contents of register A. print_space: push_register_a_to_stack load_register_a_with_value ' ' output_byte_from_register_a pop_register_a_from_stack return_to_calling_program print_register_a_in_decimal_form: // First we zero all the data-areas used by this subroutine. load_register_b_with_value 0 set_memory_pointer hundreds_in_byte store_register_b_to_memory set_memory_pointer tens_in_byte store_register_b_to_memory set_memory_pointer ones_in_byte store_register_b_to_memory find_hundreds_in_byte: load_register_b_with_value 100 jump_if_register_a_smaller_than_b find_tens_in_byte subtract_register_b_from_a set_memory_pointer hundreds_in_byte load_register_b_from_memory increment_register_b store_register_b_to_memory jump_to_address find_hundreds_in_byte find_tens_in_byte: load_register_b_with_value 10 jump_if_register_a_smaller_than_b find_ones_in_byte subtract_register_b_from_a set_memory_pointer tens_in_byte load_register_b_from_memory increment_register_b store_register_b_to_memory jump_to_address find_tens_in_byte find_ones_in_byte: set_memory_pointer ones_in_byte store_register_a_to_memory print_hundreds_tens_and_ones: set_memory_pointer hundreds_in_byte load_register_a_from_memory add_value_to_register_a '0' output_byte_from_register_a set_memory_pointer tens_in_byte load_register_a_from_memory add_value_to_register_a '0' output_byte_from_register_a set_memory_pointer ones_in_byte load_register_a_from_memory add_value_to_register_a '0' output_byte_from_register_a end_of_print_register_a_in_decimal_form: return_to_calling_program // The following are the "local data" of subroutine // print_register_a_in_decimal_form. This data is local because // only this subroutine uses them. hundreds_in_byte: DATA 1 tens_in_byte: DATA 1 ones_in_byte: DATA 1