QuestionQuestion

Question 1:
List the micro-operations required to execute the following two lines of code:
STR R2,R3,#4
AND R1,R4,R7
At the outset, assume that the PC is already set to the address of the first instruction, but that the instruction has not yet been fetched into the instruction register (you must include the micro-ops to do this). After you have fetched the instruction, you must increment the PC (recall that the PC is pre-incremented in the LC-3) using the appropriate micro-ops before you execute it. Finally, keep in mind that when you finish executing the first instruction, you must also fetch the next one. Group your list of micro-operations into sections according to the high level tasks they perform (eg. “compute address”, “store value in MDR”, etc.), and provide documentation at the top of each section so that it is clear what is happening.

Question 2 [25 marks]
You are part of an elite team of programmers and engineers tasked with designing a rover that will be deployed on the surface of a distant (and foreboding) planet. A satellite orbiting the planet will receive messages sent from Earth and relay them down to the rover on the surface.
The rover computer will receive messages from its antennae one character at a time. Your task is to design a finite state machine (FSM) to process these characters as they come in.
Message Format
Messages begin with an opening angle bracket ‘<’, followed by one or more commands, followed by a closing angle bracket ‘>’. The table below gives a full list of the various commands that the rover could receive.

Command                                             Description
H                                              Halt (stop current action)
A0                                             Move forward
A1                                             Move backward
A2                                             Turn wheels left
A3                                             Turn wheels right
A4                                             Take surface photo
A5                                             Take atmospheric sample
A6                                             Drill for mineral sample
A7                                             Discard mineral sample
A8                                             Wave drill menacingly
A9                                             Flee alien life form

Note that commands come in two forms: the “halt” command consists of a single letter (‘H’), while the other “action” commands consist of two letters (‘A’ followed by a digit). Your FSM must be able to handle both types.
Here are some example messages:
<H>
<A0>
<A0H>
<HA0A3H>
<A6A7A8A9A9A9>
FSM
The FSM will receive messages one character at a time. As soon as it has received a complete command, it should print the command (followed by a space) to the console window.
Note that the action that our FSM takes (printing to the console window) is implemented as a side-effect of following transitions between states (as opposed to a side-effect of being in a state).
When the FSM reaches the end of a message, it should reset and begin listening for the next one.
Here are some sample inputs the FSM could receive, along with its expected output. Note that the input could consist of several messages strung together in a row.

Input                                    Expected Output
<A3>                                           A3
<A0A5HH>                               A0 A5 H H
<A0H><HA0A3H><A4>       A0 H H A0 A3 H A4

Transmission interference
Interference from the planet’s atmosphere can cause characters in a message to be dropped. Interference may also cause characters to “skew” – to turn into other values in the ASCII table that are not part of the message format (eg. ‘x’).
Your FSM should process as much of the message as it can. If it encounters a problem caused by interference, it should reset and begin listening for a new message (starting with a ‘<’). Here are some examples of input that has been altered by interference, along with the expected behaviour of the FSM in each instance.

Input                                       Expected Output
<A0A                                                 A0
c<H>a<A0>                                     H A0
<HA33A4H><A5>                         H A3 A5
<>                                                 (nothing)
<HA0xA3<<A1>                            H A0 A1

a) Draw a diagram of an FSM that fulfills the requirements described above. Include documentation that briefly describes the purpose of each of the states in your diagram. Note: The initial state should be clearly indicated so that someone looking at your machine can tell where it starts.
b) Implement your FSM in LC-3 assembly language by following the steps given below.
i. Begin by defining a label called MSG that contains the input to the machine (use .stringz). In the LC-3, strings are stored just like arrays (one char per 16-bit element). This means that you can iterate through a string just like you would iterate through an array.
The only difference is the stopping condition. Instead of defining the length of the string (using a label called N) and using a counter as we did with arrays, we stop the loop when we encounter a null terminator character (‘\0’, which has the ASCII value 0). Implement such a loop that goes through each character in the MSG string and passes it to your state machine (by calling the appropriate subroutine for the current state – see step (ii) below). Note that this implies that you must keep track of the current state as you iterate.
ii. Create a subroutine for each state of your FSM. Each subroutine should accept a single argument (the current char of the message), and produce a single return value (a number indicating which state the machine should transition to next – these numbers should be defined as labels in the data area of your program, like an Enum in C/Java).
For example (in pseudocode):
process_state_1(c):
;Look at the transitions out of STATE_1 and
;determine where we should go, based on c.
;eg. Suppose that c == ‘A’ causes us to transition to state 2:
if (c == ‘A’)
new_state = STATE_2
else if ... ;conditions for other transitions out of state 1
return new_state
;define labels for each state (like an Enum)
STATE_0 .fill #0
STATE_1 .fill #1
STATE_2 .fill #2
STATE_3 .fill #3
;etc.
iii. When you reach the end of the input string, print a message that says “Done.”

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

.ORIG x3000 ; set origin of program to x3000

; Start of program

LD R6, STACK ; set stack pointer to x5000
LD R4, STATE_0 ; initialize state to 0
LEA R1, MSG ; point to message to be processed
LOOP LDR R0, R1, #0 ; load one character from the string
ADD R0, R0, #0 ; see if the char is zero (end of string)
BRz END ; if end of string, terminate

ADD R2, R4, #0 ; load current state in R2
NOT R2, R2 ; convert to negative by inverting
ADD R2, R2, #1 ; and adding 1 (two's complement)
LD R3, STATE_0 ; load state 0 value
ADD R3, R3, R2 ; compare current state with state 0
BRz CALL0 ; if state 0, jump to process state 0
LD R3, STATE_1 ; load state 1 value
ADD R3, R3, R2 ; compare current state with state 1
BRz CALL1 ; if state 1, jump to process state 1
LD R3, STATE_2 ; load state 2 value
ADD R3, R3, R2 ; compare current state with state 2
BRz CALL2 ; if state 2, jump to process state 2

CALL0 ADD R6,R6,#-2 ; allocate space in stack for argument and return value
STR R0,R6,#0 ; pass character to subroutine
JSR PROCESS0 ; process state 0
LDR R4, R6, #1 ; load returned value from stack as new state
ADD R6,R6,#2 ; restore stack, pop 2 values

BR NEXT ; continue to next char in string
CALL1 ADD R6,R6,#-2 ; allocate space in stack for argument and return value
STR R0,R6,#0 ; pass character to subroutine
JSR PROCESS1 ; process state 1
LDR R4, R6, #1 ; load returned value from stack as new state
ADD R6,R6,#2 ; restore stack, pop 2 values
BR NEXT ; continue to next char in string
CALL2 ADD R6,R6,#-2 ; allocate space in stack for argument and return value
STR R0,R6,#0 ; pass character to subroutine
JSR PROCESS2 ; process state 2
LDR R4, R6, #1 ; load returned value from stack as new state
ADD R6,R6,#2 ; restore stack, pop 2 values

NEXT ADD R1, R1, #1 ; increment position in string
BR LOOP ; repeat to process next character

END LEA R0, ENDMSG ; print end message
       PUTS

HALT

; process_state_0 function, called when the current state is 0
; requires character read from string in stack
; returns next state on stack
PROCESS0 ADD R6,R6,#-2 ; allocate space in stack for saving R0, R1
STR R0, R6, #0 ; save R0 on stack
STR R1, R6, #1 ; save R1 on stack

LDR R0, R6, #2 ; load argument
LD R1, CHRLT_N ; load ascii '<' for comparison
ADD R1, R1, R0 ; compare char with '<'
BRnp S0_RET_0 ; if not equal, state remains in zero

AND R0, R0, #0 ; if '<', return...

By purchasing this solution you'll be able to access the following files:
Solution.docx and Solution.zip.

$109.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Assembly Language Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats