Call/WhatsApp/Text: +44 20 3289 5183

Question: Developing an Assembly Language Calculator for the WASP Processor: A Step-by-Step Implementation and Enhancement Guide

16 Jan 2025,8:22 AM

 

Task 1 – Assembly programming

Your task is to write a program in assembly for the WASP processor. The program will work as a calculator. The user can input sums and the program will display the answer in decimals (base-10). I suggest you develop the program incrementally. Get a basic version working and then make it more complicated in stages. You will get marks for an incomplete program. If you want to attempt an easier version of the program, that’s okay.

I suggest five stages of development. For each of these, I will give you an indication of the mark you are likely to get, if this is as far as you have got. The exact mark will depend on other factors, such as whether it works reliably and how well you have used programming concepts in your code.

Very basic implementation – The user can enter three characters. The first will be a digit from 0 to 5. The second will be the “+” character. The third will be a digit from 0 to 4. Your program will add the two digits together and display the result.

For example, if the user enters:


 

CopyEdit

3+4

The program will display:


 

CopyEdit

7

A very basic implementation will get a mark of about 10 out of 50, depending on correctness and code quality.

Basic implementation – The user can enter three characters. The first will be a digit from 0 to 9. The second will be the “+” character or the “-“ character. The third will be a digit from 0 to 9. If the middle character is “+” the program will add the two numbers and display the result. If the middle character is “-“ the program will subtract the second number from the first and display the result. (It doesn’t have to work correctly for negative answers.)

For example, if the user enters:


 

CopyEdit

3+4

The program will display:


 

CopyEdit

7 or 07

If the user enters:


 

CopyEdit

7-2

The program will display:


 

CopyEdit

5 or 05

If the user enters:

https://youtu.be/PKVEIBirv-c
 

CopyEdit

9+7

The program will display:


 

CopyEdit

16

A basic implementation will get a mark of about 20 out of 50, depending on correctness and code quality.

Good implementation – The user can enter five characters. The first two will be a number from 00 to 99. The third will be the “+” character or the “-“ character. The last two characters will be a number from 00 to 99. If the middle character is “+” the program will add the two numbers and display the result. If the middle character is “-“ the program will subtract the second number from the first and display the result. (It doesn’t have to work correctly for negative answers or for answers greater than 99.)

For example, if the user enters:


 

CopyEdit

30+41

The program will display:


 

CopyEdit

71

If the user enters:


 

CopyEdit

77-22

The program will display:


 

CopyEdit

55

A good implementation will get a mark of about 30 out of 50, depending on correctness and code quality.

Full implementation – The user can enter five characters. The first two will be a number from 00 to 99. The third will be the “+” character or the “-“ character. The last two characters will be a number from 00 to 99. If the middle character is “+” the program will add the two numbers and display the result. If the middle character is “-“ the program will subtract the second number from the first and display the result. (It does not have to work correctly for negative answers.) The program will repeat in a loop, so the user can keep entering new sums without having to re-start the program. If the user makes an incorrect input, the program will display an error message.

For example, if the user enters:


 

CopyEdit

80+41

The program will display:


 

CopyEdit

121

If the user enters:


 

CopyEdit

x5+12

The program will display:


Developing an Assembly Language Calculator for the WASP Processor
 

go

CopyEdit

error

A full implementation should make use of functions and variables. The program should be clearly organised.

A full implementation will get a mark of about 40 out of 50, depending on correctness and code quality.

Advanced implementation

For marks above 40 out of 50, you should impress us. There are many ways to impress, and you don’t need to do all of them:

  • Get the program to display negative answers correctly.
    • For example: 22-77 = -55
  • Get the program to handle numbers of any length from 0 to 65525.
    • For example: 22+1132 = 1154
  • Get the program to handle negative input values.
    • For example: -2+7 = 5
  • Add prompts to tell the user what to type.
  • Make the program end if the user types xx as input.
  • Support other mathematical operations, such as * and /.

You may think of your own ways to make the program more complex or useful. That’s great. Show us at the demo, and if we are impressed, we can give you marks.

 

 

Demonstration

In the week 20th January to 24th January 2025, you will be asked to demonstrate your WASP program to the tutors. This will take place in a computing lab at the university. We will give you more information (including dates and times) before December 2024.

You do not need to prepare a presentation for this. We just want to see your program working. You will be sitting in front of a computer to demonstrate your code to a tutor, not presenting to the class. It should only take a few minutes. We will also ask you a few questions about your code, to make sure that you understand it and have written it yourself.

If you have a Student Accessibility Plan, and would like to demonstrate at an individual, private session, contact Chris Rook before 20th December 2024.

 

 

Paradigms of computation

You have a choice of three tasks: 2A, 2B, and 2C. You only need to complete one of these tasks.

Task 2A – Set theory

Use your understanding of set theory to explore the scenario below.

On a school sports day, there are several events at different times.

Event Time
100 metre sprint 10am
1 kilometre run 11am
Javelin 2pm
Long jump 2pm
Cross country run 3pm

The children are arranged into three teams:

Team Children
Thames Ann, Dave, Gita, Jack
Avon Ben, Ellen, Harry, Karen
Mersey Claire, Fred, Ivy, Li, Mahmud

Children take part in different events:

Event Children
100 metre sprint Ann, Ben, Harry, Ivy, Li
1 kilometre run Claire, Dave, Karen, Li, Gita
Javelin Ann, Ellen, Ivy, Jack, Mahmud
Long jump Ben, Harry, Karen, Jack, Li
Cross country run Claire, Dave, Ellen, Mahmud, Gita

Write no more than 1000 words to answer the following questions:

  • Show how the data in the table above can be represented as sets and relations.
  • Explain which of your relations are functions.
  • Use set theory notation to demonstrate how composition can be used to find out what times Ann will be competing.
  • Use set theory notation to demonstrate how composition can be used to determine how many members of team “Mersey” will be competing at 2pm.
  • Show another example of how set theory can be used to find other useful information from this data.
  • Explain why sets and relations are useful for organising information in a computer system.

Your word count does not include: anything written in set notation (including the contents of sets), reference lists, titles, diagrams, tables, program code or pseudocode.

 

Task 2B – Logic circuits

We want you to make a logic circuit similar to the ones we have done in class. To make sure you all have a different problem, we will use your student code to generate the problem. Your student code has eight digits. For example:


 

CopyEdit

20016432

Each digit is a number from 0 to 9.

  • Some digits are in your student code, and some are not. For example, in the code above, the digit "6" is in the student code, but the digit "8" is not.
  • Some digits are included more than once. For example, in the code above, the digit "2" is used more than once. The same applies to the digit "0".
  • One of the digits will be the largest digit in the code. In the example above, "6" is the largest digit.

You are going to create a logic circuit using Digital Works that provides four switches so the user can enter a number from 0 to 15 in binary. This number will be used to represent a possible value of a decimal digit from 0 to 9. (A four-digit binary number goes up to 15, of course. The numbers 10 to 15—or 1010 to 1111 in binary—are special cases, see below.)

For example, the switches below represent the binary value 0101, or the digit "5".

The circuit will light up one or more LEDs, depending on the decimal equivalent of the binary value entered.

There are four LEDs, labelled as shown below:

  • If the digit is not part of your student code, it will light up the "Not included" LED.
  • If the digit is part of your student code, it will light up the "Included" LED.
  • If the digit is used more than once in your student code, it will light up the "More than once" LED.
  • If the digit is the highest-value digit in your student code, it will light up the "Highest" LED.

Some digits will cause more than one LED to light up. For example, using the student code 20016432:

  • Binary value 1000 represents the digit "8". This is not part of the student code, so this will light up the "Not included" LED.
  • Binary value 0010 represents the digit "2". This is used twice in the student code, so will light up both the "Included" and "More than once" LEDs.
  • Binary value 0110 represents the digit "6". This is used in the student code and is the largest digit, so will light up both the "Included" and "Highest" LEDs.

Other digits 0, 1, 3, 4, 5, 7, 9 will also light up one or more LEDs.

Binary values 1010 to 1111 represent numbers that cannot be a single decimal digit (larger than 9!) so these will always cause the "Not included" LED to light up.

Note that for this question, you should use your own student code, not the code 20016432 used in the examples above. This is to ensure that every student has a slightly different problem.

First, create a truth table showing all possible values of the four inputs and the four outputs for each binary value. You should label each column in the truth table.

Then use the Digital Works template provided to create a single circuit that has this behaviour. The template looks like this:

[Template image is likely referenced here in the original document]

Your circuit goes in the big space in the middle and connects the four vertical lines on the left (the input binary digit) to the four LEDs on the right. If you need more space, you can move the LEDs further right and/or down.

Q: Why are we using a template?

  • The first reason is that it helps get you started and can help you develop your circuit.
  • The second reason is that this will speed up marking considerably. This is a large module, and anything we can do to speed up marking, even by a few seconds per submission, has a large impact on our work.

Q: What are all the things in the template?

  • This annotation is a helpful reminder of your student ID. You probably know yours off by heart, but it helps us when checking that the circuit behaves correctly. Please alter this to your ID. If we see another student’s ID, we will be suspicious.

[Further template details and explanation likely follow in the document]

 

Q: What are all the things in the template? (continued)

  • This line of four interactive inputs is where you can enter any 4-bit binary number. This is the "input" of the circuit. For convenience, we have attached a display so you can see what the decimal equivalent is of the binary number.

  • These four wires hold the binary input number. You will notice that they are not directly attached to the interactive inputs—that there is a macro box in between. That will be explained next. You should use these wires as the starting point for your circuit, connecting from them to your circuit to the right of them. The LEDs at the bottom show what values are held on the wires. There is another decimal output display showing the value of the current binary number on these wires. If you wish, you may add more vertical wires, for example, connected to NOT gates from each input wire. This seems to be a popular thing to do.

  • The mysterious macro box that separates the input from the signal wires is actually a counter. By default, it passes the input binary number straight through to the output binary number. This is how we expect you will work most of the time. If the interactive input labelled "count" is switched "on", instead of passing the input number through to the output, an internal binary counter counts from 0 to 15 and then starts again, continuously. This is included to allow rapid checking that the outputs are correct for all inputs. It is intended to speed up marking, but of course, you are free to use it for your own checking if you wish. The "reset" input to the left resets the counter to 0. It is only mildly useful.

Finally, write a short essay of up to 600 words, explaining:

  • What steps you have taken to reduce your circuit, making it as simple as possible. You may have used Boolean algebra, Karnaugh maps, inspection, or a combination of these.
  • How the same logical task could be implemented in software. You can use pseudocode or any well-known language. Explain the similarities between the logic gates in your circuit and the AND/OR/NOT expressions in your code.

The word count does not include: code, pseudocode, diagrams, tables, references, titles.

IMPORTANT:

  • You must use Digital Works to create your circuit. If you do not, you will receive no marks for your circuit. You will still be able to get marks for your truth table and your essay.
  • There are marks for using the template. If you submit a Digital Works circuit that doesn’t use the template, you will not get those marks, but we will still mark your circuit. The template is available on BB.

Your submission for this task has three elements: the truth table, the circuit, and the essay. Your submission document should contain the truth table, a screenshot of the circuit, and the essay. You should also hand in the Digital Works circuit file. There are marks for submitting the file, so if you neglect to do so, you will not be awarded those marks.

Hints:

  • You have been asked to create a single circuit. There should be one circuit connected to four inputs and four outputs.
  • You don't need to create a circuit that will analyze your student code and work out the largest digit or count how many times each digit is used. You will do that yourself and create a truth table. You just need to create a circuit that implements that truth table.
  • It is not necessary to give multiple screenshots of your circuit showing different input values.
  • It is possible to gain a passing mark for this task without any circuit reduction.
  • It is possible to do some simple reduction by checking if you are applying a NOT gate to the same input more than once for different parts of the circuit. Instead of using multiple NOT gates, just use one, then feed the output in as many directions as you need. Most circuits will be able to have more complex reduction applied, but it is amazing how often this simple trick is missed.
  • If you are unsure how to start, look at your truth table. It is not just there for the marks; it is the basis of your circuit. It may help you to think about each output one at a time.
  • Remember to ensure that inputs that need to be 0 are actually 0.

 

Task 2C – Turing machines and von Neumann architecture

You have been asked to create a video about Turing Machines for the "True Geek" channel. (Don’t look for it – I made it up.) You should aim the video for an audience of computer enthusiasts, such as knowledgeable students in their first year of a Computer Science degree.

Hi. Thanks for offering to make a video for the channel. A lot of our subscribers have been asking about Turing Machines. I can find information on Wikipedia, but it doesn’t have many good examples to explain what is going on. I would like a video that includes:

  • A description of what a Turing Machine is.
  • A walkthrough of a Turing Machine doing a simple task.
  • Some examples of why Turing Machines are relevant to a modern computer scientist.

The video should be no more than 15 minutes long, or our subscribers will get bored and switch off. You can maybe go over by 10% if you are really interesting. You can use lecture slides if you want but try to make use of lots of visuals – preferably technical details, which our subscribers like. Don’t be afraid to include mathematics, as long as you explain it. If you use images from somewhere else, that’s fine, but make sure you provide references so we can get permission from the copyright owners.

You will use a tool called Panopto to create the video. It is the same tool I use for my lecture videos. I will provide guides showing you how to create and submit the video. There will be information about alternative tools, if you have trouble with Panopto.

What is a "walkthrough"? In this case, it means that you should show the system working step-by-step. Each execution cycle should be shown. If your example is long, it is okay to show the first five or six steps in detail, then the rest much more quickly.

You are not being marked for the quality of your editing or how many special effects you use. The marks are for the information you convey in the presentation.

Expert answer

 

DRAFT / STUDY TIPS:

To approach Task 1 – Assembly programming for the WASP processor, here's how you can systematically go about it:

1. Understand the Requirements

  • The task involves writing an assembly program for the WASP processor that functions as a basic calculator.
  • It should allow users to input simple arithmetic expressions (like 3+4 or 7-2) and output the result.
  • The task is broken into five stages, each increasing in complexity and the potential mark you can achieve.

2. Familiarize Yourself with the WASP Processor

  • Understand the instruction set and architecture of the WASP processor.
  • Know how to handle basic operations like input, output, arithmetic operations, and control flow in assembly language for WASP.

3. Plan Incremental Development

  • Start with a simple version and build upon it.
  • Develop in stages:
    • Stage 1: Implement addition of two single-digit numbers (e.g., 3+4).
    • Stage 2: Extend to support subtraction and handle digits from 0 to 9.
    • Stage 3: Allow two-digit numbers (e.g., 30+41) for both addition and subtraction.
    • Stage 4: Add looping to allow multiple calculations without restarting the program and error handling for incorrect inputs.
    • Stage 5: Implement advanced features like handling negative results, larger numbers, and additional operations.

4. Start Coding

  • Use a simple structure for the initial stage.
  • Use labels for different parts of your code to handle input, processing, and output.
  • Implement conditional jumps to handle different operations (+ and -).

5. Test and Debug

  • After writing each stage, test your program thoroughly.
  • Ensure the program correctly handles valid inputs and gracefully manages errors for invalid inputs.
  • Use debugging techniques to troubleshoot and refine your code.

6. Document Your Code

  • Comment your assembly code to explain each part for clarity.
  • Include explanations for the logic used in different sections.

7. Prepare for Demonstration

  • Be ready to demonstrate your program and explain how it works.
  • Practice answering potential questions about your code to show your understanding

 

 

Here's a sample implementation for Stage 1 of Task 1 – a very basic calculator that adds two single-digit numbers. I'll walk you through the process and the code.

Stage 1: Very Basic Implementation

1. Understand the Requirements

  • The user inputs three characters: a digit from 0 to 5, a + character, and a digit from 0 to 4.
  • The program adds the two digits and outputs the result.

2. WASP Assembly Code Overview

  • Input: Read characters from the user.
  • Processing: Convert character inputs to numeric values, perform addition.
  • Output: Display the result as a decimal.

3. WASP Assembly Code Implementation


 

assembly

START: IN R1 ; Input first character (digit 0-5) IN R2 ; Input second character (must be '+') IN R3 ; Input third character (digit 0-4) SUB R1, R1, #48 ; Convert ASCII character to numeric value (R1 = R1 - '0') SUB R3, R3, #48 ; Convert ASCII character to numeric value (R3 = R3 - '0') ADD R4, R1, R3 ; Add the two numbers (R4 = R1 + R3) ADD R4, R4, #48 ; Convert numeric value to ASCII character (R4 = R4 + '0') OUT R4 ; Output the result character HALT ; Stop the program

4. Explanation of the Code

  • IN R1: Read the first character (e.g., '3') and store it in register R1.
  • IN R2: Read the second character (e.g., '+') and store it in register R2.
  • IN R3: Read the third character (e.g., '4') and store it in register R3.
  • SUB R1, R1, #48: Convert the ASCII value of the first character to its numeric equivalent. ASCII code for '0' is 48.
  • SUB R3, R3, #48: Convert the ASCII value of the third character to its numeric equivalent.
  • ADD R4, R1, R3: Perform the addition of the two numbers.
  • ADD R4, R4, #48: Convert the result back to its ASCII character equivalent for output.
  • OUT R4: Display the result.
  • HALT: Stop the execution of the program.

5. Testing the Program

  • Run the program and input the string 3+4.
  • The output should be 7.

Next Steps

  • For Stage 2, extend this code to handle subtraction and allow digits from 0 to 9.
  • Add logic to check the operator (+ or -) and adjust the arithmetic operation accordingly.

 

Let's move on to Stage 2 of Task 1, where we enhance the calculator to support both addition and subtraction and handle digits from 0 to 9.

Stage 2: Basic Implementation

1. Updated Requirements

  • The user can input three characters: a digit from 0 to 9, an operator (+ or -), and another digit from 0 to 9.
  • The program will perform the specified operation and output the result.

2. Enhancements in the WASP Assembly Code

  • Include a condition to check if the operator is + or -.
  • Perform the corresponding arithmetic operation based on the operator.
  • Handle the conversion of characters to numbers and back to characters.

3. WASP Assembly Code for Stage 2


 

assembly

CopyEdit

START: IN R1 ; Input first character (digit 0-9) IN R2 ; Input second character (operator '+' or '-') IN R3 ; Input third character (digit 0-9) SUB R1, R1, #48 ; Convert ASCII character to numeric value (R1 = R1 - '0') SUB R3, R3, #48 ; Convert ASCII character to numeric value (R3 = R3 - '0') CMP R2, #43 ; Compare operator to ASCII value of '+' BEQ ADDITION ; If equal, branch to ADDITION label CMP R2, #45 ; Compare operator to ASCII value of '-' BEQ SUBTRACTION ; If equal, branch to SUBTRACTION label ERROR: OUT R2 ; Output an error character or message (optional) HALT ; Stop the program ADDITION: ADD R4, R1, R3 ; Perform addition (R4 = R1 + R3) B OUTPUT ; Branch to OUTPUT label SUBTRACTION: SUB R4, R1, R3 ; Perform subtraction (R4 = R1 - R3) B OUTPUT ; Branch to OUTPUT label OUTPUT: ADD R4, R4, #48 ; Convert numeric result back to ASCII character OUT R4 ; Output the result HALT ; Stop the program

4. Explanation of New Code

  • CMP R2, #43: Compare the operator in R2 to the ASCII value of + (which is 43).
  • BEQ ADDITION: If the operator is +, branch to the ADDITION section to perform addition.
  • CMP R2, #45: Compare the operator to the ASCII value of - (which is 45).
  • BEQ SUBTRACTION: If the operator is -, branch to the SUBTRACTION section.
  • ERROR: An optional section to handle invalid inputs, such as operators other than + or -.
  • ADDITION and SUBTRACTION: Sections that perform the corresponding arithmetic operations.
  • OUTPUT: Convert the result to an ASCII character and display it.

5. Testing the Enhanced Program

  • Test cases:
    • Input 3+4 should output 7.
    • Input 7-2 should output 5.
    • Input 9+7 should output 16.

Next Steps

  • For Stage 3, expand the program to handle two-digit numbers (e.g., 30+41).
  • Add logic to parse and handle multi-digit input and ensure proper output formatting.
Stuck Looking For A Model Original Answer To This Or Any Other
Question?


Related Questions

WhatsApp us