The writeup on data storage directives in the SMAL assembly language forms the framework of the second part of this lecture.
To run the SMAL assembler, log in to any of the machines in the Computer Science Educational Laboratory in Room 105 or Room B12 MacLean Hall. The computers we will be using are made by Hewlett Packard and Silicon Graphics; all run versions of UNIX, either HP-UX or IRIX. These machines can be accessed from the Internet, for example, from machines in the Instructional Technology Centers around campus or from home by dial-up access to the campus modem pool. To do so, you must know that each machine has a name; the current list of machine names is available on the Web.
The door locks on the CSEL rooms have been programmed to accept your university ID card. If they do not work, contact the lab staff in room 303a for help. (If you have ever lost your ID card and gotten it replaced, you will probably need this help!)
Please read at least the first few paragraphs of the writeup in the CSEL web pages on accounts and passwords and the section on changing your password. Do not lose your password! Do not write it down where anyone else could ever read it! Change your password if you even suspect someone else knows it! The lab staff in 303a cannot tell you your password, but in the event of loss, they can set it to a known value at your request, if you show them your university ID to verify who you are.
To run the SMAL assembler, after you've logged into any of the CSEL machines, type:
source /group/22c018/setupThis command enables the special commands for 22C:18. You should only need to enter this command once at the start of a session, after logging in.
Here is an example SMAL program:
TITLE An example SMAL program WORDS: W 0 ;a list of words W 1 W 2 W 3 HALVES: H 4 ;a list of halfwords H 5 H 6 H 7 BYTES: B 8 ;a list of halfwords B 9 B 10 B 11 TEXT: ASCII "STRING!!" W WORDS,HALVES,BYTES,TEXT ENDBy convention, each line of the source file is broken into 4 fields:
WORDS: W 0 ;a list of words
| | | |
| label | op |operand| comment
| | | |
All fields are optional! The label field is only needed if the memory
address used by this line of assembly code is needed elsewhere in the
program. When the assembler encounteres an identifier in the label field,
it remembers that identifier and associates it with the memory location
in which the results of assembling that line are stored. If present, the
label field must end with a colon. The label field usually begins at the
left margin, but may begin anywhere on the line.
The operation field tells the assembler what to do with the remainder of the line. In this example, the W operation tells the assembler to evaluate the expression in the operand field and store its value as one word in memory.
The data stored by consecutive lines of assembly code are stored in consecutive memory locatons. In this example, the assembled result would be stored in memory as:
Memory Hex
Location Value
00 00000000
04 00000001
08 00000002
0C 00000003
10 00050004
14 00070006
18 0B080908
1C 49525453
20 2121474E
24 00000000
28 00000010
2C 00000018
30 0000001C
Note that the memory of a Hawk computer is organized as an array of 32 bit
words, but that the two least significant bits of each memory address may
be used to indicate what byte in a word is being referenced. Thus, in the
above list, consecutive memory addresses differ by 4. Note also that,
in the Hawk architecture, bytes and halfwords are packed right to left.
This order may not be intuitive, but it is the order used by DEC and Intel
computers; IBM mainframes and Motorola computers do it in the opposite
way!
If this program is entered into a file called example.a, it can be assembled with the command:
smal example.aRunning this will produce a listing file called example.l and an object file called example.o. The latter file is not intended to be human readable (although it is text and you can look at it and even decode it, using the section of the SMAL manual on object code formats). The listing file looks like this:
SMAL32, rev 8/96. An example SMAL program 09:44:56 Page 1
Wed Sep 4 1996
1 TITLE An example SMAL program
2
+000000: 00000000 3 WORDS: W 0 ;a list of words
+000004: 00000001 4 W 1
+000008: 00000002 5 W 2
+00000C: 00000003 6 W 3
7
+000010: 0004 8 HALVES: H 4 ;a list of halfwords
+000012: 0005 9 H 5
+000014: 0006 10 H 6
+000016: 0007 11 H 7
12
+000018: 08 13 BYTES: B 8 ;a list of halfwords
+000019: 09 14 B 9
+00001A: 0A 15 B 10
+00001B: 0B 16 B 11
17
+00001C: 53 54 52 49 18 TEXT: ASCII "STRING!!"
4E 47 21 21
19
+000024:+00000000 20 W WORDS,HALVES,BYTES,TEXT
+00000010
+00000018
+0000001C
21 END
no errors
Although the assembler does not require it, every SMAL program should have
a title! The title is repeated at the head of each page of the listing file.
The body of the listing file is organized as follows:
+000000: 00000000 3 WORDS: W 0 ;a list of words | | | | |address| data |line| source text | | | |The leftmost field is the value of the assembly location counter; this gives the memory address in which the data resulting from assembling the code on that source line will be stored. The data itself is listed in the second column. The third column gives the source line number, while the final column lists the assembly code from the source file.
One warning is called for about interpreting SMAL assembly listings! When the assembler listing shows multiple bytes and halfwords resulting from assembling one line, it lists them from left to right with spaces to indicate that they were assembled separately. This makes it easy to read, but it may mislead you! The line
+00001C: 53 54 52 49 18 TEXT: ASCII "STRING!!"shows the value 49525453 being stored as a word in location 1C, for example!