[Solved] Comp2300 Lab 1

$25

File Name: Comp2300_Lab_1.zip
File Size: 131.88 KB

SKU: [Solved] Comp2300 Lab 1 Category: Tag:
5/5 - (1 vote)

In this weeks lab you will:

  1. get your discoboard and connect it to the computer
  2. create your first program using the VSCode IDE
  3. compile, run and debug your first program
  4. pledge to be a person of integrity in this course

Introduction

Welcome to the COMP2300 labs! These labs are the heart of the course, and theyre your opportunity to practice the core concepts youll need for the assessments. They are also your chance to explore and ask questions. If you dont understand all of whats going on in this lab, thats okfor two reasons:

  1. this is just the first lab (and its in week 1, not week 2 which is the case for some other courses), so well cover all this stuff in detail in both lectures and future labs
  2. there are no dumb questions in this course, so the lab sessions are the time to speak up

The labs for this course have a few different recurring parts, and they will be presented using different coloured boxes:

General notes & information will be highlighted in a blue box.

Sometimes you need to think about stuff before you go ahead. If you see something in a pink box (because your brain is pinksortof), thats your clue to pause and thinkhow do you expect the next part will work? Take a moment to think before you blaze away and start coding, because then you can check whether you really understand whats going on or whether youre just copy-pasting stuff without really understanding it. If you dont understand it perfectly, thats okask your lab neighbour, or your labs Teams chat (or your tutor directly) to help you understand.

All assignment & lab submissions in this course happen through GitLab. None of your lab work contributes to your final grade, however you are expected to push your lab work up to the server at various stages during your lab so that the tutors can see your progress and give you feedback. When its time to push something, itll be clearly marked in an orange-coloured box. Dont just read past this box to the next section, where the answer might be discussedmake sure you attempt to complete the exercise yourself.

Computer organisation and program execution (hey, thats the name of this course!) are huge topics, and mastering them takes a lifetime. So the material in these lab sessions will only cover the fundamentals. However, sometimes there are interesting extension exercises you might try if you want to go deeper, and these will be in a purple box. If you dont know how to approach the problems in the purple boxes, thats ok tooyoull do just fine in the course if you can do all the rest of the stuff in the labs. Still, its a chance to ask your lab mates and tutors and stretch yourself if you have time.

These coloured boxes will be used consistently through the lab material, so take a moment to familiarise yourself with what the different colours mean, or at least remember that you can come back here and check at any time.

Exercise 0: setting up the COMP2300 software environment

Setting things up deserves its own page. Go have a look, see you back here when youre done 🙂

Exercise 1: getting your discoboard

If youre online, well let you know how you can get your own discoboard in the week 1 lectures. For now youll be using the discoboard emulator, which is a piece of software that works in the exact same (well, sort of) way as a physical boardhow to use it is explained a bit later in the lab. If this is you, skip to exercise 3.

If youre in-person, during this lab the tutors will come around and give you a discoboard and USB cable of your very ownthis is yours to keep forever. How exciting! The only caveat is that if you unenroll from the course before the census date (March 31) you have to give it back.

When you get your board, the tutor will also take note of the serial number (down the bottom on the back side of the board).

Discoboard upside-down

Discoboard upside-down

Handing all the boards out might take a bit of time, though, so thanks for your patience. While youre waiting, push your chair away from the desk, turn, and say hello to the person next to you. Introduce yourself. Find out what degree theyre taking, and why theyre taking this courseis it a prerequisite or an elective? If youre feeling extra-personable, ask what they like to do in their spare time. (If theyre already your friend, find someone else who you dont know and talk to them instead.)

Exercise 2: connecting the board to the computer

Boxed discoboard

Boxed discoboard

The discoboard connects to the lab computer (or your personal laptop) via a mini-USB cable.

As far as electronics go, this board isnt super fragile, but youll still need to be careful with it when youre handling it and carting it around. Thats why you got it in a plastic containerkeep it and your cable together in there. If youre not used to handling electronics, here are a few tips:

Holding your discoboard

Holding your discoboard

  • handle it by the edges (as in the photo)
  • dont touch any of the pins or little microchips on the board
  • keep the plastic case to carry the board around
  • be careful of static electricityif youre the sort of person who regularly shocks themselves, then you need to ground yourself before touching the board
  • the USB cable you received will only fit in one end of the board (even though theres a different USB connector on the other end) so if its not going in, try the other enddont try to force it!

Once youve received your new discoboard, plug it in to the lab computerthe full-size USB end goes into the lab computer, and the mini end of the USB cable goes into the connector on the discoboard (up the top end, closer to the LCD screen).

Exercise 3: your first discoboard program

With your lab neighbour, open up the main VSCode documentation website. Discuss with them: what makes a good documentation website?

Now that youve connected your board to the computer its time to turn everything on and see if it works. This exercise is a bit longer, so its broken down into stages: clone, edit, build & run.

Fork & clone

In this course, youll be using git a lot, and youll have a lot of git repositories (repos for short). Dont fear: youve done this before (in COMP1100, one of the pre-requisites for this course) and its the same process here. Since were at the start of the course, heres a tip: its probably a good idea to make a comp2300 (or comp6300) directory somewhere on your computer where you can keep all of your stuff for this course.

Ok, now here goes:

  1. fork the lab 1 template to your user account (i.e. uXXXXXXX)
  2. clone it to your local machine

You can do the git clone step in the terminal, or your favourite git client, it doesnt matter. If you like, you can use VSCodes built-in git support: heres a link to the general docs on this view, and heres the specific instructions on how to clone a repo.

Remember, this is all stuff you learned in COMP1100. Well make sure we help you out if youre a bit rusty, but make sure you can fork, clone and (at the end) push to GitLabyou wont be able to submit the assessment items any other way.

After youve cloned, open the top-level folder in VSCode. If you used the integrated VSCode git clone command, this will happen automatically. If you cloned the repo some other way, youll need to open the folder yourself with File: Open... in the command palette. Once youve done that you should see something like this:

VSCode after opening the cloned repo

VSCode after opening the cloned repo

Again, the VSCode docs have a good explanation of the user interface.

Now, in the Explorer view, open the src/main.S file, you should see something like this:

The main.s file in VSCodium

The main.s file in VSCodium

Even if youve never seen any assembly language before, what do you think this program does?

Edit

Add some code so that main.S looks like this:

.syntax unified.global main.type main, %functionmain:  mov r1, 0loop:  add r1, 1  b loop

Save the file when youre done. Dont worry if you dont understand all the details at this stagethe goal for this weeks lab is just to plug things in, turn them on, and make sure that everythings working. If you have any problems, let your tutor know now.

Build

You can build (or compilethey mean the same thing in this context) your program using the Build command (COMP2300: Build in the command palette). Youll see some stuff printed to the terminal (near the bottom of your VSCodium window), and when its done it should look something like this:

View after the build command

View after the build command

The compilation process takes all the code (text files), translates them into binary instructions for the target Instruction Set Architecture (ISA) ARMv7 in this caseand links them together into a binary file (image). You can learn more about it here if you want to read ahead, but youll also get familiar with it throughout this course.

Upload

If youre a remote student without a discoboard, skip to the next step 🙂 Youll learn how to get programs onto the emulator there.

Youve built the program on your laptop/desktop. To run it on your discoboard you need to upload it with the Upload (COMP2300: Upload) command. Again, afterward it should look something like this:

The first time you flash a Discoboard you might see a Error: init mode failed (unable to connect to target), this is solved by following the instructions in the COMP2300: first time flash command (link to troubleshooting here).

View after the upload command

View after the upload command

If you get errors at this point, then theyll be printed (probably in red) in the terminal. Try and figure out whats going wrong yourself, also checkout the troubleshoot section in software setup

Run & Debug

When you upload your program to the discoboard, it starts running it automatically.

To debug the program (stepping it through, inspecting the CPU & memory states), well use VSCodiums built-in debuggeran invaluable tool for making things work right when were writing programs for the discoboard. You may have used a debugger like this before, or you may not havethats ok! Well lead you through the basics in the labs over the next couple of weeks.

Open up the Debug view and make sure build & debug is selected (if you are a remote student wanting to use the emulator, select build & debug (emulator)).

Debug config selection box

Debug config selection box

Click the green play button to run your program, pausing (breaking) on entry.

Debugging in progress

Debugging in progress

The highlighted yellow line of assembly code (shown in the above screenshot) represents where the program is up to (next instruction to execute). When you first start it running, the IDE creates a breakpoint at the main: label in your program, so when your program reaches that line of code it stops and waits for further instructions (from you!).

At this point, you can step through the code one instruction at a time using the debug controls:

Debugger controls

Debugger controls

Discuss with your lab neighbourwhat do all these debug control buttons do? Play around with them togethercan you see what effect theyre having on the program executing on your discoboard? Are you pumped?

If you want your program to keep running (i.e. to unpause the program) just hit the green play button (although its called continue rather than play when youre debugging, because it continues after you last paused the execution). Once its running, you can pause it again by hitting the pause button, and even stop it with the red stop button.

Once its stopped, you can restart the whole process again in a new debugging session by going back to the start of these instructions.

Sometimes the debuggers are a bit flaky, and get into some problems. Youll get the hang of recognising when things have gone wrong & how to fix them. Remember that its ok to use the stop or restart buttons to try and get things back on track, or (worst-comes-to-worst) unplug and re-plug your discoboard.

You can also examine the values of your registers in the REGISTERS viewlet under the Debug View (see the bottom left corner in the below screenshot):

VSCodium debug view, showing registers (bottom left)

VSCodium debug view, showing registers (bottom left)

If you want to control exactly where the system pauses for debugging, you can set a new breakpoint by clicking in the left-hand gutter (or margin) of the code view in the IDE. You should see a little red dot appear:

A breakpoint (indicated by the red dot)

A breakpoint (indicated by the red dot)

The program isnt running on the lab computer on the desktop (well, unless youre using the emulator if you are then ✨imagine✨!)its running on your discoboard. What does that mean? What are the implications for the way you run & debug your program?

Make sure you understand whats going on! Of course this is the goal of this course, and you will get to learn more as you go. But just a warning before you embark on this journey: make sure you dont get tripped up at the final over some of these fundamental concepts, like many journey men before you did. Remember that your tutor is there for you to grill them with questions. 😉

Rate this product

One of the great things about uni is that you dont learn in isolation (no matter if youre online, or on-campus were putting in the effort to make sure this is true!). These lab sessions, no matter how you take them, will give you plenty of chances to discuss things with other people in your lab group. If you see a green box, read it and talk about the prompt with someone in your groupif youre in person youll need to remember to do this social distantly, and if youre online your tutors will explain how to start a discussion in Teams.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Comp2300 Lab 1
$25