Starting from:

$20

Assignment 2 Assembly language programming Solution

Complete the associated exercises before attempting the assignment

Aim

This assignment provides some limited experience with assembly language programming.

Objectives
On completion of this assignment and its associated exercise, you will be able to:
• Explain how assembly language programs are prepared using a two pass assembler, are loaded and executed
• Explain the operation of a simple assembler and the use of conventional assembly language directives for setting origins, defining variables, strings, and blocks of initialized data
• Explain how input and output can be realised using wait loops and interrupt mechanisms
• Explain “op-codes” and “addressing modes”
• Use assembly language to implement simple programming constructs such as indexed array accessing, use of pointers, simple subroutine calls, and use of a primitive “operating system” implemented with trap (svc) system call instructions.
Task
You are to implement a simple data processing application in PDP11 assembly language, making use of the supplied primitive “operating system” to handle I/O.
A simple program for summary statistics
The program is to produce some summary statistics for an array of data. The outline of a C version (which you should implement in full first) is as follows:
The program determines the mean, mode of the data in an array, and also identifies the largest and smallest value.
You should be able to work out the code for the functions mean() and maxandmin(). Code for the mode() function could be as follows:
The data for the array are to be created using a supplied “datagen” program.
Example data – your values will differ:
An executable version of the datagen program for the Ubuntu computers in the lab can be downloaded from http://www.uow.edu.au/~nabg/131/Resources/datagen (after download,
change the permission to make the file executable). This program will generate a
personalized set of data values; it will generate the same set of values each time you run the program, and can output the data in a form for pasting into C code or into your assembly language program.
Output for C:
Output for assembly language (same values, just reformatted and printed in octal):
Assembly language implementation
As in the exercise, start your assembly language version by taking the code of the example os2btrap.txt and cutting out the example application code to leave just the “operating system and
library” components.
The “operating system” offers five system functions that are invoked via traps (supervisor calls):
Remove the application code; leave the “operating system and library”
code
Supervisor calls:
• Exit:
Terminate execution of application program, return to OS (which then halts).
• Readline:
This trap takes one argument in the following memory location; this is the address
of a buffer (character array) where input characters will be stored. The implementation of the supervisor call reads characters from the keyboard (under
interrupt control) until a newline character has been read. All characters read are
store in the input buffer.
• Writeline:
This trap takes one argument in the following memory location; this is the address
of a buffer (character array) with a generated message. The implementation of the supervisor call writes the content of the array to the tty.
• Atoi:
(Not used in this application). This trap takes one argument; this is the address of a buffer that is supposed to contain the ASCII representation of an integer. The
integer value will be returned.
• Itoa:
This trap takes two arguments; the first is the address of a variable containing an
integer value, the second is the address of a buffer where an ASCII string should be generated to represent that value (in decimal).
Start by implementing an application that invokes stub functions that output fixed values rather than actual data:
These stub functions simply print messages and output a fixed value. A stub implementation of mean() is shown below; the mode() and maxandmin() stub functions are similar:
You will need message strings and some variables:
This stubbed out version of the application should run:
You can then add the actual data to your code:
Your real task is implementing the functions mean(), mode(), and maxandmin(), using simple assembly language constructs for array access and counting loops.
Your completed assembly language program should produce the same output as your C version:
Assignment report
You do not submit your code files!
You are marked on a report that you write. This report presents details of your assembly
language program. You must include the assembly language code for the three functions
(screen shots can be used). For each function, explain how you have encoded the loop
constructs in assembly language and how you are accessing the array elements.
Submission
Prepare your report and convert to PDF format as the file A2.pdf.
Submission is done electronically via a program called turnin that runs on “banshee” – the
main CS undergraduate machine. You must first transfer your A2.pdf file to your home
directory on banshee (this is different from the home directory that you access on the Linux
machines). You can transfer the file using a SSH file-transfer program. The Ubuntu OS
allows you to open a file-browser connected to your banshee home directory – and you can
simply drag your A2.pdf file across using the visual file browser.
For CSCI131, assignments are submitted electronically via the turnin system. For this
assignment you submit your assignment via the command:
turnin -c csci131 -a 2 A2.pdf
Late submissions would be submitted as:
turnin -c csci131 -a 2late A2.pdf
The program turnin only works when you are logged in to the main banshee undergraduate
server machine. From an Ubuntu workstation in the lab, you must open a terminal session on
the local machine, and then login to banshee via ssh and run the turnin program.
Marking
The assignment is worth 8 marks total.
• Appearance and structure of report: 1 mark
• Evidence for correct operation (screenshots from both C and assembly language versions)
: 1 mark
• Code and explanations of each of the three functions: 6 marks total

More products