Skip to main content

Using the Assembler

In order to test your project, you need to assemble programs to be loaded into memory. To do this, there is a simple assembler provided. It will take source code that looks like the text in figure below and produces two files: An object file and a listing for your reference.

An example assembly program

          slbi    r1, 0
          slbi    r1, 0x55
          slli    r2, r1, 8
          bnez    r2, .LAB3
          subi    r2, r2, 1
          .LAB3:
          halt
        

// An example object file

          @0
          9100
          9155
          a948
          6a01
          4a41
          0000
        

// An example binary listing (.lst file)

          0000 9100 slbi    r1, 0
          0001 9155 slbi    r1, 0x55
          0002 a948 slli    r2, r1, 8
          0003 6a01 bnez    r2, .LAB3
          0004 4a41 subi    r2, r2, 1
          0005      .LAB3:
          0005 0000 halt
        

The assembler is located here: /u/s/i/sinclair/courses/cs552/spring2022/handouts/bins/assemble.sh

As mentioned elsewhere, you should add this directory to your PATH variable.

Say you have a source file names "myfile.asm"; to assemble it, type: assemble.sh myfile.asm

This produces many files, two of the files are: The listing file is called loadfile.lst and the object file is the second name specified (loadfile_all.img).

The assembler always produces a warning that if there are any errors, the output is not valid. This is just a reminder -- this message itself is not an error.

See running the programs in the WISC-SP22 simulator-debugger.

The assembler will also produce 4 files of the form loadfile_0,1,2,3.img. These are binary images you can load into the four-banked memory when you get to it. You load one of these files into each bank.

Assembler Syntax

Assembly programs are written using the semantics outlined in the WISC-SP22 ISA document. C style comments can be used (//). Static data and labels can be used as follows:

Labels:

          beqz r0, .label1

          .label1:
          <-- code here -->
        

Static data:

          lbi r0, L.DataArea //load the lower half of datum
          slbi r0, U.DataArea //load the upper half of datum

          .DataArea
          data 0x1234
          data 0x5678