Page 218 - DCAP104_EXPOSURE_TO_COMPUTER_DISCPLINES
P. 218

Unit 11: Programming Process



                             (a) Our computer has 4 registers and 32 memory locations.            Notes
                             (b) Each instruction is 16 bits.
                             (c) Here is a machine language program for our simulated computer:
                                         1000000100100101
                                         1000000101000101
                                         1010000100000110
                                         1000001000000110
                                         1111111111111111

                                      Instruction ID     Register #         Memory
                                                                            Location



              LOAD contents of memory             100000010 RR MMMMM
              location into register              example:
                                                  R0 = Mem[3]
                                                  100000010 00 00011
              LOAD contents of memory location into   100000010 RR MMMMM
              register                            ex: R0 =  Mem [3]
                                                  100000010 00 00011
              Store contents of register into memory   100000010 RR MMMMM
              location                            ex: Mem[4] = R0
                                                  100000100 00 00100
              MOVE contents of one register into   100100010000 RR RR
              another register                    ex: R0 = R1
                                                  100100010000 00 01
              ADD contents of 2 registers,        1010000100 RR RR RR
              store result in third.              ex: R0 = R1 + R2
                                                  1010000100 00 01 10
              SUBTRACT contents of 2              1010001000 RR RR RR
              registers, store result into third   ex: R0 = R1 — R2
                                                  1010001000 00 01 10
              Halt the program                    1111111111111111


            11.2.2 Reading Machine Language
             (a) In our case, first nine bits specifies the operation, last 6 (or 7) bits specifies the arguments:
                 100000010  01  00101                Load Memory 5 — > R1
                 100000010  10  00101                Load Memory 5 — > R2
                 1010000100  00  01 10               R1  + R2 — > R0
                 1111111111111111                    Store R0 — > Memory 6
             (b) It is very tedious to program in machine language.






                                             LOVELY PROFESSIONAL UNIVERSITY                                   211
   213   214   215   216   217   218   219   220   221   222   223