<< 2012-3 >>
Department of
Computer Science
 

Introduction

This document gives a guide to using the assembler system to assembler programs written in the PREASM assembly language.

Installing The Assembler

The assembler system is written in Java and so to use it you must have a recent version of the Java runtime system installed. Once this is achieved, you should be able to sucessfully issue the following command : machine% java -version java version "1.1.3" Having installed a Java runtime system, you should set up your CLASSPATH environment variable to point at the installation JAR file containing the assembler system : machine% CLASSPATH=$CLASSPATH:assembler.jar From now on you should be able to compile programs written in the PRE language by issuing commands as discussed below : machine% java assembler.Assembler -source in.preasm -target out.preobj

Customizing The Assembler Behaviour

The behaviour of the assembler is changed by the use of the command line options shown below :

Switch Default Value Resulting Behaviour
-source <file> stdin The -source option directs the assembler to read the source code for the PREASM program from the specified file instead of from stdin.
-target <file> stdout The -target option directs the assembler to write the assembled object file to the specified file instead of to stdout.
-O0 No optimisations are attempted.
-O1 Only optimisations that are considered safe and stable are attempted.
-O2 All availible optimisations are attempted which may result in some problems in the resulting code.
-help Prints a help screen with a brief rundown of availible options.

Assembler Optimisations

Currently, the PREASM assembler attempts a number of conventional optimisations by employing a peephole optimisation strategy. The extent to which this effects the source program can be controlled using command line options. By default no optimisations are attempted.

The user should envoke the assembly optimisation process with care due to the aggressive nature of the system. When attempting to optimise hand written code it is important that the user understands the optimisations carried out and that the target code is verified as correct before execution starts.

An example pitfall that could cause had written assembly code to be incorrectly assembled is one type of MOV folding. If the peephole optimiser comes accross some code which read :

MOV 2, 1 MOV 3, 2 it will fold the two moves into one : MOV 3, 1 For assembly code generated by the compiler, this is a effective way of reducing the number of instructions in the resulting program. However, in hand written code it could cause incorrect behaviour if the programmer relies on the fact that the value being moved from register 1 to register 3 is also in register 2.
© 1995-2013 University of Bristol  |  Terms and Conditions  |  Use of Cookies
About this Page