Write a TOM program that reads a number from the keyboard, subtracts 1 and displays the result.

Authors Avatar

TOM1

  1. Write a TOM program that reads a number from the keyboard, subtracts 1 and displays the

        result.

To improve legibility the comments are displayed to the right of every TOM line of code, and not in the standard style.

        read        keyin                Reads data inputted by keyboard and stores in the store location keyin         

        load        keyin                Loads data from the store location keyin in to the accumulator

        sub                minus                Subtracts the store location minus from the accumulator

        store        display                Stores value in accumulator in the store location display

         print        display                Displays contents of the store location display on the screen

         stop                                Stops program execution

minus        data        1                Initialises a store location minus with the value 1 in it

keyin        data        0                Initialises a store location keyin with the value 0 in it

display                data        0                Initialises a store location display with the value 0 in it

 

2.        Write a TOM program that reads a number from the keyboard, multiplies it by 2, reads another number b from the keyboard, multiplies it by 3, and then displays the result. In other words, evaluate 2*a+3*b.

        read        keyin1                Reads data inputted by keyboard and stores in the store location  keyin1

        load        keyin1                Loads data from the store location keyin1 in to the accumulator

        mult        val1                Multiplies the accumulator by the store location val1

        store        display                Stores value in accumulator in the store location display

        read        keyin2                Reads data inputted by keyboard and stores in the store location  keyin2

        load         keyin2                Loads data from the store location keyin2 in to the accumulator

        mult        val2                Multiplies the accumulator by the store location val2

        add                display                Adds the store location display to the accumulator

        store        total                Stores value in accumulator in the store location total

        print        total                Displays contents of the store location total on the screen

        stop                                Stops program execution

val1        data        2                Initialises a store location val1 with the value 2 in it

val2        data        3                Initialises a store location val2 with the value 3 in it

keyin1        data        0                Initialises a store location keyin1 with the value 0 in it

keyin2        data        0                Initialises a store location keyin2 with the value 0 in it

display        data        0                Initialises a store location display with the value 0 in it

total        data        0                Initialises a store location total with the value 0 in it

3.        Write a TOM program that displays two numbers, entered from the keyboard, in descending numerical order.

        read        keyin1                Reads data inputted by keyboard and stores in the store location  keyin1

        read        keyin2                Reads data inputted by keyboard and stores in the store location  keyin2

        load        keyin1                Loads data from the store location keyin1 in to the accumulator

        sub                keyin2                Subtracts the store location keyin2  from the accumulator

        jifz                lower                Transfers control to the instruction lower if the zero flag is set

        print        keyin1                Displays contents of the store location keyin1 on the screen

Join now!

        print        keyin2                Displays contents of the store location keyin2 on the screen

        stop                                Stops program execution

lower        print        keyin2                Displays contents of the store location keyin2 on the screen

        print        keyin1                 Displays contents of the store location keyin1 on the screen

        stop                                Stops program execution

keyin1        data        0                Initialises a store location keyin1 with the value 0 in it

keyin2        data        0                Initialises a store location keyin2 with the value 0 in it

4.        Write a TOM program that reads a number N from the keyboard and displays the sum of all integers from 1 to N i.e.1+2+3+…+N.

        read        keyin                Reads data inputted by keyboard and stores in the store location keyin

loop        load        sofar                Loads data from the store location sofar in to ...

This is a preview of the whole essay