header

Week 8 Homework

Due Mar 4

Microprograms

You can test your microprograms using the simulator by entering your programs in binary in the microprogram editor. Before running your programs, you'll need to edit the memory locations that you access in order to check the results generated by your programs.

Problem 1

Write a microprogram that finds the sum of the word values stored at word addresses 0, 1, 2, and 3 and stores the result in word address 4. Don't forget that the values stored in MAR are word addresses. This program should have a sequential structure. Don't try to implement a loop. Thinking of memory as an array of integers, this problem becomes:

mem[4] = mem[0] + mem[1] + mem[2] + mem[3]

Problem 2

The values stored in memory locations 0, 1, and 2 represent memory addresses. That is, the value stored in mem[0] is the address at which an integer value is stored, the value stored in mem[1] is the address at which an integer value is stored, and the value stored in mem[2] is the address at which an integer value is stored. Write a microprogram that adds the values stored in the first two addresses and stores the sum in the third address. Symbolically,

mem[ mem[2] ] = mem[ mem[0] ] + mem[ mem[1] ]

If we say addr0 = mem[0], addr1 = mem[1], and addr2 = mem[2] then we have:

mem[addr2] = mem[addr0] + mem[addr1]

Problem 3

Memory location mem[0] contains a non-negative integer, n, that corresponds to the size of an array of integers whose first value is at mem[1] and whose last value is at mem[n]. Write a microprogram that finds the sum of the values in the array and stores it in mem[n+1], the first memory location following the array itself. Symbolically,

mem[ mem[0]+1 ] = mem[1] + mem[2] + mem[3] + … + mem[ mem[0] ]

or, given that mem[0] = n

mem[n+1] = mem[1] + mem[2] + mem[3] +  … + mem[n]

Obviously, you will need to use a looping structure since n is not known ahead of time.