sections in this module City College of San Francisco - CS270
Computer Architecture

Module: Simple Machine
module list

Issues and Problems

Problem One:

The following RTL is for what SM instruction?

MAR(15:10) <- 0
MAR(9:0) <- IR(9:0)
get()
ACCUM <- MBR

Problem Two:

Convert this code snippet to GOTOs and branches

int firstnums[N], secondnums[N];
int differindex=0;
for (i=0; i< N; i++ )
if (firstnums[i] != secondnums[i]) {
differindex=i;
break;
}

This code snippet cannot be easily rewritten to take advantage of the DEC instruction. Give two reasons why that is true.

Problem Three:

Convert this loop using GOTOs and branches. Then write the Simple Machine program

int N, constant;
int arr[N];

for (i=0; i<N; i++)
arr[i] += constant;

Start by rewriting the code so that you can make use of the DECR instruction for the loop. Then convert it using GOTOs and branches. Then write the Simple Machine program. Make sure the array is at the end of the data portion (so it could change size) and you have inserted ample pad words between the instructions and data.

Problem Four:

One significant issue with the SM is its single general-use register. Suppose it had a second accumulator, accum2.
  1. explain why this would ease the programming problems
  2. how could you incorporate the second register into the instruction set while maintaining compatibility of existing code? discuss the issues with your solution.
  3. what new instruction(s), if any, would you need?

Answers:

Problem One

The instruction whose RTL this is does the following:

"take the ADDR part of the instruction and retrieve the value at that address, placing the value back in the accumulator". This is the LOAD instruction.

Problem Two:

differindex=0;
i=0;
loop:
if ( i == N)
goto loopdone;
if (firstnums[i] == secondnums[i])
goto loopagain;
differindex=i;
goto loopdone;
loopagain:
i=i+1;
goto loop;
loopdone:

It is pointless to rewrite this code to use the DEC instruction for two reasons:

Problem Three:

First, rewrite the code simply (and I have removed the += operator for clarity)


int N, constant;
int arr[N];

for (i=(N-1); i>=0; i--)
arr[i] = arr[i] + constant;

Now, rewrite this using GOTOs and branches. (The code part only)

i=(N-1);
loop: if (i<0) goto loopdone;
arr[i] = arr[i] + constant;
i--;
goto loop;
loopdone:

Translate it to SM mneumonics, line by line. We will leave I in the CTR register since that is the only thing that needs a comparison! (As a matter of fact, the registers work out very well in this SM program...)

# i=(N-1);
LA   1
SUB  N
MVAC
#loop: if (i<0) goto loopdone;
loop: JLT  loopdone
#arr[i] = arr[i] + constant;
LA   ARR
ADDC
MVAA
LIA
ADD  CONSTANT
SIA
#i--;
DECR
#goto loop;
JMP  loop
#loopdone:
loopdone: HALT
# insert 5 pad words here
# address 0x12:
0x5  # N [0x12]
0x2  # CONSTANT [0x13]
0x0  # I (unused) [0x14]
0x1  # ARR [0x15]
0x2
0x3
0x4
0x5

The entire program is translated to Simple Machine in the file online/simple/prob3

Problem Four

  1. Having two accumulators would avoid having to save and restore values so often. You could leave one value in the first accumulator while you use the second.
  2. You could incorporate this change by using one of the two unused bits in the instruction word. If the bit is off, the instruction uses the original (first) accumulator. Thus existing code would not be affected. If the bit is on, the instruction uses the second accumulator. Thus, if we used bit 10 as the "second accumulator bit", the instruction 0x2010 would store the value in the first accumulator at 0x10, while 0x2410 would store the value in the second accumulator at 0x10
  3. Although helpful, the benefits of a second accumulator would be limited unless there were some instructions to use both accumulators in one instruction, such as to add them together or compare them. This, however, would be a significant change in design of the SM.
Prev This page was made entirely with free software on linux:  
Kompozer, the Mozilla Project
and Openoffice.org    
Next

Copyright 2014 Greg Boyd - All Rights Reserved.