0% found this document useful (0 votes)
654 views

FIT1047 Assignment - 1-4

This document provides guidelines for Assignment 1 of the unit FIT1047 S1 2018. It states that the assignment is individual work and is due on April 20, 2018 by 11:55pm. Submissions must be in PDF and code file formats and uploaded to Moodle. Late submissions within 5 days will lose 5% of the mark per day. The assignment is out of 70 marks and counts for 22.5% of the total unit marks. Plagiarism will result in zero marks. The assignment contains two tasks - the first involves Boolean algebra and circuit design in Logisim, the second involves developing a database application in MARIE assembly language.

Uploaded by

Shaun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
654 views

FIT1047 Assignment - 1-4

This document provides guidelines for Assignment 1 of the unit FIT1047 S1 2018. It states that the assignment is individual work and is due on April 20, 2018 by 11:55pm. Submissions must be in PDF and code file formats and uploaded to Moodle. Late submissions within 5 days will lose 5% of the mark per day. The assignment is out of 70 marks and counts for 22.5% of the total unit marks. Plagiarism will result in zero marks. The assignment contains two tasks - the first involves Boolean algebra and circuit design in Logisim, the second involves developing a database application in MARIE assembly language.

Uploaded by

Shaun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

FIT1047 S1 2018

Assignment 1
Submission guidelines
This is an individual assignment, group work is not permitted.
Deadline: April 20, 2018, 11:55pm
Submission format: PDF for the written tasks, LogiSim circuit files for task 1, MARIE
assembly files for task 2. All files must be uploaded electronically via Moodle.
Individualised exercises: Some exercises require you to pick one of several options
based on your student ID.
Late submission:
• By submitting a special consideration form, available from http://www.monash.
edu.au/exams/special-consideration.html
• Without special consideration, you lose 5% of your mark per day that you submit
late (including weekends). Submissions will not be accepted more than 5 days late.
This means that if you got x marks, only 0.95n × x will be counted where n is the
number of days you submit late.
In-class interviews: See instructions for Task 2 for details.
Marks: This assignment will be marked out of 70 points, and count for 22.5% of your
total unit marks.
Plagiarism: It is an academic requirement that the work you submit be original. Zero
marks will be awarded for the whole assignment if there is any evidence of copying
(including from online sources without proper attribution), collaboration, pasting from
websites or textbooks. This includes both the student who copies, and the student who
lets them copy!
The faculty’s Plagiarism Policy applies to all assessment:
http://intranet.monash.edu.au/infotech/resources/students/assignments/policies.
html
Further Note: When you are asked to use internet resources to answer a question, this
does not mean copy-pasting text from websites. Write answers in your own words
such that your understanding of the answer is evident. Acknowledge any sources by
citing them.

1
1 Boolean Algebra and Logisim Task

The following truth table describes a Boolean function with four input values X1, X2, X3, X4
and two output values Z1, Z2.

X1 X2 X3 X4 Z1 Z2
0 0 0 0 1 1
0 0 0 1 0 1
0 0 1 0 1 0
0 0 1 1 1 1
0 1 0 0 0 1
0 1 0 1 1 0
0 1 1 0 1 0
0 1 1 1 1 1
1 0 0 0 0 0
1 0 0 1 1 0
1 0 1 0 1 0
1 0 1 1 1 0
1 1 0 0 0 1
1 1 0 1 0 1
1 1 1 0 1 0
1 1 1 1 0 1

The main result of this task will be a logical circuit correctly implementing this Boolean
function in the logisim simulator. Each step as defined in the following sub-tasks needs
to be documented and explained.

1.1 Step 1: Boolean Algebra Expressions (8 points)

Write the Boolean function as Boolean algebra terms. First, think about how to deal
with the two outputs. Then, describe each single row in terms of Boolean algebra.
Finally, combine the terms for single rows into larger terms. Briefly explain these steps
for your particular truth table.

1.2 Step 2: Logical circuit in Logisim (8 points)

Model the resulting Boolean terms from Step 1 in a single Logisim circuit, using the
basic gates AND, OR, NOT. You can use gates with more than two inputs.
Explain what you did for each step.
Test your circuit using values from the truth table and document the tests.

2
1.3 Step 3: Optimized circuit (9 points)

The goal of this task is to find a minimal circuit using only AND, OR, and NOT gates.
Based on the truth table and Boolean algebra terms from Step 1, optimize the function
using Karnaugh maps.
You will need to create two Karnaugh maps, one for each output. Your documentation
should show the maps as well as the groups found in the maps and how they relate to
terms in the optimized Boolean function.
Then use Logisim to create a minimal circuit. Dont use any other gates than AND, OR,
and NOT. Test your optimized circuit using values from the truth table.

2 Development of a Database for Unit Prerequisites in MARIE

In this task you will develop a MARIE application that implements a database with
information about unit prerequisites. We will break it down into small steps for you.
Most of the tasks require you to write code, test cases and some small analysis. The
code must contain comments, and you submit it as .mas files together with the rest of
your assignment. The test cases should also be working, self-contained MARIE assembly
files. The analysis needs to be submitted as part of the main PDF file you submit for
this assignment.

In-class interviews: You will be required to demonstrate your code to your tutor after
the submission deadline. Failure to demonstrate will lead to zero marks being awarded
for the entire programming part of this assignment.

2.1 Strings

This section doesn’t contain any tasks for you yet, it only introduces the concepts you
need for the rest of the assignment.
A string is a sequence of characters. It’s the basic data structure for storing text in a
computer. There are several different ways of representing a string in memory – e.g.
you need to decide which character set to use (Unicode or ASCII), and how to deal with
strings of arbitrary length.
For this assignment, we will use the following string representation:

• A string is represented in a contiguous block of memory, with each address con-


taining one character.
• The characters are encoded using the ASCII encoding.

3
• The end of the string is marked by the value 0.

As an example, this is how the string FIT1047 would be represented in memory (written
as hexadecimal numbers):
046 049 054 031 030 034 037 000
Note that for a string with n characters, we need n + 1 words of memory in order to
store the additional 0 that marks the end of the string.
In MARIE assembly, we can use the HEX keyword initialise the MARIE memory with a
fixed string:

FIT1047, HEX 046


HEX 049
HEX 054
HEX 031
HEX 030
HEX 034
HEX 037
HEX 000

After assembling this code, you can verify that the string has been loaded into the
MARIE memory.

2.2 Your name as a MARIE string (3 points)

This is the first task you need to submit. Similar to the FIT1047 example above, encode
your name using ASCII characters. You should encode at least 10 characters – if your
name is longer, you can shorten it if you want, if it’s shorter, you need to add some
characters (such as !?! or ..., or invent a middle name).
You need to submit a MARIE file that contains code, using HEX like above, so that after
assembling, the MARIE memory contains the string with your name.

2.3 A subroutine for printing a string (7 points)

For this task, you need to write MARIE code that can print any string (no matter
how long) that is already stored in memory, by using the Output instruction on each
character of the string. Start by using a label PrintString that holds the start address
of the string. The code should then load a character from that address, output it if it is
not 0, then increment the address by one, and keep doing that until the character loaded
from the address is a 0 (which signals the end of the string).

4
To receive full marks, your code needs to be in the form of a subroutine that can be
called using the JnS instruction. You can start from the following template, which will
print FIT1047 once you add the correct printing code.

Load StringAddr / Get start address of string


Store PrintString / Store as argument of subroutine
Jns Print / Execute printing subroutine
Halt

PrintString, HEX 0 / argument: address of string


Print, HEX 0 / subroutine start
/
/
/ your printing code goes here
/
/

StringAddr, JnS FIT1047 / Address of the string


FIT1047, HEX 046 / Start of string data
HEX 049
HEX 054
HEX 031
HEX 030
HEX 034
HEX 037
HEX 000

This code uses an interesting trick: The label FIT1047 represents the address where the
string starts. Unfortunately, there is no MARIE instruction to load the address of a label
into the AC register – but we need to pass the start address to the Print subroutine!
Luckily there is a workaround. The JnS instruction has opcode 0. This means that in
memory, JnS FIT1047 will be represented as 0000XXXXXXXXXXXX, where XXXXXXXXXXXX
is the address of label FIT1047. That is exactly what we wanted!
To help you remember this trick, think of the JnS mnemonic to have two meanings:
Jump and Store (this is the usual meaning), or Just an addresS (if you want to get the
address of a label).
Submit your MARIE code, extending the above template, and where the string has been
replaced by your name from the previous task.

5
2.4 A subroutine for user input of a string (5 points)

In the code above, we have hard-coded the strings into the assembly code, so that they
end up in memory when we assemble the program. In real programming languages,
this would mean that those strings are embedded and fixed in the programs. E.g., if
a program prints an error message, then the string for the message would typically be
hard-coded into the program like this. For the database we are implementing here, we
will assume that the actual data it stores does not change and is therefore hard-coded
into the assembly code.
In many cases, however, we want the user to supply a string when the program is running.
For our database, the search query will be given as user input - this means that you can
run multiple queries without re-assembling the program.
Your task is to write a subroutine that lets users input a string one character at a time,
using the Input instruction. The subroutine should take an address as its argument and
store the string at that address. When the user enters the value 0 (i.e., the integer value
0, not the character 0!), this will signal the end of the string.
Here is a template that you can start from.

Load StringAddr / Get start address where string should be stored


Store InputAddr / Store as argument of subroutine
Jns InputString / Execute input subroutine
Halt

InputAddr, HEX 0 / argument: address where string


/ will be stored
InputString, HEX 0 / subroutine start
/
/
/ your input code goes here
/
/

StringAddr, JnS UserInput / Address of the string


UserInput, HEX 0 / Start of string data

Tip: you can switch the type of input in the MARIE simulator. For the actual string,
use the unicode input method so you can enter real characters. For the final 0, switch to
the decimal input method.

6
2.5 String comparison (10 points)

Now we are going to implement a string comparison subroutine. It takes two (addresses
of) strings as arguments and returns 1 if they are equal (i.e., they have the same length
and contain the same characters in the same order), and 0 otherwise.
The subroutine will communicate the result back to the caller (the code that called textt-
tJnS) in the address with the label CmpEqual, i.e., after returning from the subroutine,
CmpEqual will be equal to 1 if and only if the two strings are equal.
In order to achieve this, your code needs to loop through both strings, one character at
a time:
1. If the current character in the first string is 0 (i.e., the end of the string), check if
the character in the second string is also 0. If it is, set CmpEqual to 1 and return,
otherwise set it to 0 and return.
2. If the current character in the first string is not 0:
a) Check if the current character in the second string is 0. If it is, the strings
are not equal, so set CmpEqual to 0 and return.
b) If the current character in the second string is not 0, you now have to compare
the two characters. If they are not equal, set CmpEqual to 0 and return.
c) If they are equal, move to the next character in both strings and go back
step 1 in order to compare the next characters.
Implement this subroutine using the following skeleton:

Cmp1, HEX 0 / Address of first string to compare


Cmp2, HEX 0 / Address of second string to compare
CmpEqual, DEC 0 / Return value: 1 if strings are equal, 0 otherwise
Cmp, HEX 0 / Entry point of subroutine (will hold return address)
/ Your code goes here
/ ...

You need to submit a MARIE file that includes the subroutine and five test cases:
1. A test case where the two strings are empty
2. A test case where the two strings are equal (and not empty)
3. A test case where the first string is shorter and a prefix of the second string (i.e.,
it’s shorter, but all characters are the same as in the second string; e.g. “abcde”
is a prefix of “abcdefgh”)
4. A test case where the second string is shorter and a prefix of the first string

7
5. A test case where the two strings have the same length, at least the first characters
are the same, but the strings are not equal
The test cases have to be described in the PDF you submit!

2.6 Database lookup

Let’s assume we have the following information about unit prerequisites:


• for FIT2093, the prerequisites are FIT1045 and FIT1047
• for FIT2100, the prerequisite is FIT147
We now have to store this information in our MARIE memory in a way that lets us
query it. For this task, we will use the following encoding into MARIE.

2.6.1 Representing the data in MARIE

For each unit, we store a string that lists the prerequisites. In this case, since our
database has two entries (for FIT2093 and FIT2100), we store two strings:

FIT2093, DEC 70 / F
DEC 73 / I
DEC 84 / T
DEC 49 / 1
DEC 48 / 0
DEC 52 / 4
DEC 55 / 7
DEC 44 / ,
DEC 32 /
DEC 70 / F
DEC 73 / I
DEC 84 / T
DEC 49 / 1
DEC 48 / 0
DEC 52 / 4
DEC 53 / 5
DEC 0

FIT2100, DEC 70 / F
DEC 73 / I
DEC 84 / T
DEC 49 / 1
DEC 48 / 0

8
DEC 52 / 4
DEC 55 / 7
DEC 0

Now that we have the actual data in memory, what is missing is an index, i.e., a way
of finding the right information when the user queries the database. The index is repre-
sented as a “list” of strings and addresses:

IdxEntryLength, DEC 9 / Length of each index entry


IdxAddr, JnS Idx
Idx, DEC 70 / F
DEC 73 / I
DEC 84 / T
DEC 50 / 2
DEC 48 / 0
DEC 57 / 9
DEC 51 / 3
DEC 0
JnS FIT2093
DEC 70 / F
DEC 73 / I
DEC 84 / T
DEC 50 / 2
DEC 49 / 1
DEC 48 / 0
DEC 48 / 0
DEC 0
JnS FIT2100
DEC 0 / End of the index

The index starts at address Idx, with the string FIT2093 (including final 0), followed by
the address where the prerequisites for FIT2093 are stored (JnS FIT2093, remember the
JnS Just an addresS trick from the printing subroutine!). Then we have the next index
entry, which is the string FIT2100 followed by the address where the data for FIT2100
is stored. Finally, the end of the index is marked by a 0. We also assume here that each
entry in the index has the same length, which is stored at IdxEntryLength (the length
here is 9 words, one word for each character of the string FITXXXX, plus the trailing 0,
plus one word for the address of the data).

2.6.2 Finding an entry (10 points)

You will now write a subroutine that finds an entry in the index and outputs the corre-
sponding data. The algorithm should work as follows:

9
1. Introduce a label CurrentEntry, and load the address of the first index entry into
CurrentEntry.
2. If the current entry contains an empty string (i.e., there is a 0 stored at that entry,
as for the End of index marker above), return from the subroutine.
3. Otherwise, compare the string in the current entry to the query string.
a) If they are equal, load the address of the data (which is the address of the
current index string plus IdxEntryLength minus 1), output the data and
return.
b) If they are not equal, skip to the next index entry by adding IdxEntryLength
to the address of the current one, and continue with step 2.

Here is the template for the search subroutine:

SearchStrAddr, HEX 0 / Address of string to find


SearchStr, HEX 0 / Entry point of subroutine (will hold return address)
/
/ your search code goes here
/

You need to submit a MARIE file with a subroutine for the database lookup, using your
comparison subroutine from 2.5 and three test cases:
1. A test case that finds the first entry in the database
2. A test case that finds the last entry in the database
3. A test case that looks up an entry that is not in the database
For the test cases, just hard-code the search string into your code and call textttJnS of
your subroutine. You need to explain your test cases in the PDF document you submit.

2.6.3 Upper case (5 points)

The code above now works if the user enters the unit code in upper case characters. We
want to make the system more flexible by automatically converting the user’s input into
upper case. E.g., if the user enters “Fit2100” they should still get the correct answer.
Write a subroutine that takes a string as input and modifies it so that all characters
are upper case (and other characters such as numbers are unchanged). Invoke this
subroutine after requesting the user input. You also need to submit a test case that
shows that the modified code works (e.g. by modifying the string in the code to contain
non-lower-case characters).

10
ToUpperStrAddr, HEX 0 / Address of string to convert to upper case
ToUpper, HEX 0 / Entry point of subroutine
/
/ your code for converting to upper case goes here
/

Hint: to convert an ASCII character from lower case to upper case, you just have to
subtract a fixed number from the integer that encodes the ASCII character. For example,
“A” has ASCII code 65, and “a” has code 97, so subtracting 32 from a lower case
character converts it into upper case.

2.6.4 Putting everything together

We now have all the parts for a simple database lookup program. Your code should
work with the following template, where you add your own subroutines.

Forever, Load StringAddr / Get start address where string should be stored
Store InputAddr / Store as argument of subroutine
Jns InputString / Execute input subroutine
Load StringAddr
Store ToUpperStrAddr
JnS ToUpper / Convert user input to upper case
Load StringAddr
Store SearchStrAddr
Jns SearchStr / Find prerequisites
Jump Forever

/ Add all your subroutines and the database data and index here

/ We put the user input string behind all the other data so that we don’t
/ accidentally overwrite it
StringAddr, JnS String
String, HEX 0

You can also download a file from Moodle that contains all of the templates and the
data.

11

You might also like