HYMN Assembler Tutorial

PGSS Computer Science Core Course

NOTE: This page is outdated, being replaced by a new, much-enhanced assembler. See its page for details.


For more experience with the assembly language we've discussed, we have a HYMN Assembler. This assembler runs through the Web, simulating the machine using a program written by the instructor.

How does a program in HYMN Assembly appear?

HYMN's assembly language is described in the table on page 17 of the course notes, with an example program on page 18. This program, which tests the primality of its input, is the default text when you enter the assembler.

The program is slightly modified to fit this assembler. Things are substantially simpler with the capacity to name lines. This way, when we branch, we can branch to a meaningful place; the address 00011110, one of the lines on page 18, just isn't as descriptive as NOTPRIME. Even more important, with line labels we don't have to rewrite every branch instruction in the program just to insert a new line.

To label a line, begin it with the label in parentheses (``(NOTPRIME) LR R0, 0''). Then we can branch to that line with the instruction ``BLESS R3, (NOTPRIME)''. This is demonstrated by the example primality program below.

The assembler automatically numbers the line with memory addresses strarting at 0 and incrementing by 2 (since HYMN has two-byte words) each line. This numbering is invisible to you. (It means, however, that programs are limited to 64 lines, since n must be at memory location 128.)

Here's the text of the program again. A line-by-line description is on page 18 of the notes.

            LR      R0, 2
            LR      R1, 1
            LRA     R2, 10000000
            SUB     R3, R2, R0
            BLESS   R3, (NOTPRIME)
            BEQUAL  R3, (ISPRIME)
(NEXTITER)  DIV     R3, R4, R2, R0
            BEQUAL  R4, (NOTPRIME)
            ADD     R0, R0, R1
            MULT    R3, R0, R0
            SUB     R3, R3, R2
            BLESS   R3, (NEXTITER)
            BEQUAL  R3, (NOTPRIME)
(ISPRIME)   LR      R0, 1
            B       (ENDPROG)
(NOTPRIME)  LR      R0, 0
(ENDPROG)   STORE   10000010, R0
(There are a couple of errors in the text fixed here. The text has BZERO in line 00001010, which should be a BEQUAL. And the second and third arguments of the first SUB instruction (line 00000110) are swapped.)

How do I use the assembler?

To run a program, go to the HYMN Assembler. Modify the program appearing under ``Program''. The program's input is a single integer, which you can set through the field named ``Value to test (n)''. This will set memory location 128 to be that value when the program is begun.

Only one other memory location is available for writing. This is memory location 130, called dest. The intention is that the program will put a 1 in dest if n is prime and a 0 otherwise.

To debug the program, select the box labeled ``Print debugging output''. This will print the state of HYMN before executing each instruction. A line of the debugging output contains 10 columns. The first tells how many clock cycles have elapsed since the beginning. The second is the line number (numbering from 1 and stepping by 1) that is about to be executed. The next eight fields give the contents of the eight registers.

If the program has a problem, the assembler will give the line number where the problem is (numbering from 1 and stepping by 1) and a short description of the problem. If you find an error message unclear, ask a friend or TA for an interpretation or e-mail the instructor.

Enjoy your assembly programming experience!