Amongst the Prac2 example files there are a number of assembly files, some of which we have not built into executables for you. These include:
|
File |
Purpose |
|---|---|
|
count.s |
The assembly code for the counting example. |
|
ians.s |
A simple example provided by Ian. |
|
char_io.s |
Reads twenty characters from the "Console Input" and writes them to the "Console Output". |
|
simple.s |
Just adds %r2 to %r3 and puts the result in %r4. |
|
rnd_test.s and random.s |
A pair of files which implement a simple program to generate a sequence of "pseudo-random" numbers. Type in the number of random trials you want to make and an arbitrary "seed" value (both in hex) and watch it go. |
Each of these is a text file, which you can view
and modify using your favourite text editor.
To produce the corresponding executables we need to perform two steps:
Assemble each assembly language file (with a ".s" extension) to produce a corresponding object file (with a ".o" extension). Given an assembly file called "file.s" we can produce its object file by executing the following command at a titanic (Unix) command prompt
as-isem -o file.o file.s
If you want to actually see information about the output the assembler produces, especially if you're trying to work out why something hasn't assembled properly, then use the "-a" option. It useful to redirect the output produced by the "-a" flag to another file, called "file.log" for instance, which you can load into your editor and inspect at your leisure. You can do this using the command:
as-isem -a -o file.o file.s > file.log
Link the object file(s) for a particular program together to produce the eventual executable file. This is really only a relevant operation if you've split your program across more than one assembler file, however it always needs to be done even if you only have one assembly file. Suppose that we had assembled the files "file1.s", "file2.s" and "file3.s" to object files "file1.o", "file2.o" and "file3.o" then we could link these all together into a single program executable "file" by issuing the command:
ld-isem -o file file1.o file2.o file3.o
For instance, the "count" executable was produced by issuing the commands:
as-isem -o count.o
count.s
ld-isem -o count count.o
Try assembling and linking the other examples - then running them in Isem to see how they work.
Of course, for bigger projects we'd use the "make" utility to do all of this automatically - we'll show you how to do this in a later practical.