CECS Home | ANU Home | Search ANU
The Australian National University
ANU College of Engineering and Computer Science
School of Computer Science
Printer Friendly Version of this Document

UniSAFE

COMP2300 / COMP6300

Tutorial / Laboratory 05 - PeANUt Experiments

Semester 1, 2009         Week 6 (30 March - 03 April)

Note that for this session, there is a submitable laboratory exercise which is due by 09 am Tuesday 07 April (week 7), which will contribute up to 1% of your assessment (in the Tute/Lab mark).

It is expected that you have looked over your lecture notes of the PeANUt module as well as read the relevant parts of the Specification of the PeANUt Computer before doing this session. It is also expected that you have completed the lab exercises of the previous session (at least part 3, Experimenting with the PeANUt, and part 5, Your multiplication program). You should also look at the selected answers now up on the web page.

Preparation Exercises

Complete the following questions on a separate sheet of paper, with your name and student number clearly written. Please ensure your writing is legible. Hand in to your tutor at the beginning of your tutorial / laboratory session.

  1. Briefly describe the term von-Neumann architecture.

  2. Suppose the five 16-bit words starting at byte 1000 of a big-endian machine contain the integers 1, 2, 3, 4, and 5. Further suppose that these five words are transmitted to a little-endian machine as a sequence of bytes in address order and stored at consecutive addresses starting at byte 30000. What are the values of the five 16-bit words now?

  3. Write a sequence of PeANUt MLI instructions that would do the same computation as the C statement x = 3 * y + 1; . Assume x and y are at memory locations a0 and a1 respectively.

Tutorial Exercises

  1. Write a sequence of PeANUt MLI instructions that would do the same computation as the C statement if (x==0) y++;. Assume x and y are at memory locations a0 and a1 respectively.

  2. Write a PeANUt program that would read a character and outputs the same character (but in lower case, if the original character was in upper case). You may (or may not) find useful the following ASCII codes: 'A'=o101, 'Z'=o132, 'a'=o141, 'z'=o172.

    Outline how you might extend this program to one that reverses the case of upper and lower case characters.

  3. Analyse the claim that it is always possible to replace a procedure call with the body of a procedure, and therefore that the procedure is not necessary.

  4. Allocate space in PeANUt assembly language for the following:
      char c; int x; 
    

  5. What is value of AC after executing (if mem[x] = 59, SP = 70, XR = 5):
            load    #15	;  AC = 15
            mul     #4	 ;  AC = AC * 4
            store   !-10	 ;  mem[SP-10] = AC
            dvd     #3       ;  AC = AC / 3
            store   *54	;  mem[XR+54] = AC
            load    x          ;  AC = mem[x]         
            sub     *55	 ;  AC = AC - mem[XR+55]
            add     #40	;  AC = AC + 40
    
    Note: all numbers are in decimal.

  6. Explain why load #530 is illegal, and what problems are encountered in the instruction sequence load #500 followed by mul #500.

Laboratory Exercises

Preliminaries

  1. In your comp2300 folder, create a new directory called lab5.

  2. Copy the files /dept/dcs/comp2300/public/lab5/* into your lab5 folder.

There are a number of questions marked with an asterix '*'. In these questions you will be asked to explain or demonstrate something to your tutor.

Conditionals

Open your copy of lab5a.mli with your favorite text editor. This machine language initialisation file contains a program which is supposed to have the following effect when executed:
  • The numbers stored at a10 and a11 are added.

  • The sum is compared to the number stored at a12.

  • If the sum is less than or equal to the number stored at a12, the character whose ASCII code is equal to the sum is printed to the I/O window.

  1. Start a PeANUt simulator, and initialise it with lab5a.mli (convert the file into an image file using the MLI-IMG button). Execute the instructions. Does the instruction sequence behave as specified?

  2. The machine language initialisation file is partly commented. Analyse each line of the initialisation file and complete the comment, or add useful comments, as necessary. Save your file.

  3. * If you think the initialisation file needs fixing in order to conform to the specifications, make the appropriate correction. Explain your decision to your tutor.

Repetition and Basic Output

The conditional statement you encountered in the previous section is the basis for repetition. Instead of branching to the end, the branch may be back to instructions already executed. In such a case, those instructions would continue to be executed until the condition (expressed in the conditional statement) no longer held.

  1. Close your lab5a.mli file and open lab5b.mli in your favorite text editor. This file should initialise the PeANUt so that when executed, it reads two characters from input, the second of which must be a digit ('0' to '9'). It prints out the first character x times, where x is the number represented by the digits.
      e.g. for the input "X8", the program outputs "XXXXXXXX".
  2. Complete lab5b.mli by writing in appropriate initialisation data (PeANUt instructions and data). You will probably need page 5 of your PeANUt Specification.

  3. * Test your code with a range of inputs.

  4. When you are satisfied that you have lab5b.mli working, test it for correctness with the command:
      previewAutoMark lab5 lab5b.mli
    When satisfied, submit it using the submit command:
        submit comp2300 lab5 lab5b.mli
        submit comp6300 lab5 lab5b.mli

    This is due by 09 am Tuesday April 07 (the deadline is strict) and will contribute up to 1% of your Tute/Lab mark.

Assembly Language via the PeANUt Simulator

Section 4 (pages 14 to 18) of the PeANUt Specification will help you understand the contents of the assembly language file. Note that assembler directives are used to create space for variables, and that these are effectively global variables.

Also, note the different prefixes (#,!,*) used on instruction operands to indicate the mode of the instruction - see page 16 of the PeANUt Specification for an explanation.

To assemble and run the assembly language program lab5d.ass you need to:

  1. Click on the Assemble button and select which file to assemble. If there are no errors, this will produce a corresponding relocatable file (e.g. lab5d.rel).

  2. Click on the Join button and a pop-up window will appear. Select the files to join, adding each to the Files to Join: list by using the >> button. In this case there is only one file needed to build the executable (.img) - this is lab5d.rel. Once it is in the list, click on Join in the pop-up window, if there are no errors the file lab5d.img should be created.

  3. Once an .img file has been created, it can be loaded and executed in the normal manner.
Look at the file lab5d.ass. It is (almost) the assembly language equivalent of lab5a.mli.
  1. Assemble and Link the file in the PeANUt simulator, as explained above.

  2. * Load the image file and compare with lab5a.img. Find the 2 differences.

  3. Step through the execution of the program.

  4. Modify the program so that AC is printed only if the sum of the first two numbers is greater than the third number. Re-assemble and test your program - if it is correct, it should not print anything.

  5. * Modify the numbers so that the sum of the first two numbers is greater. Re-assemble and test your program.

Last modified: 27/03/2009, 12:25

Copyright | Disclaimer | Privacy | Contact ANU