Skip to content

Commit

Permalink
Added directory for resource images
Browse files Browse the repository at this point in the history
  • Loading branch information
jurem committed Oct 12, 2014
0 parents commit e789d13
Show file tree
Hide file tree
Showing 140 changed files with 9,309 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
SicChain.iml
out
51 changes: 51 additions & 0 deletions doc/addressing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
In the following:
* five is absolute symbol (e.g., five EQU 5)
* label is relative symbol (e.g., label FIX)

Immediate addressing
* precedence order: signed absolute, pc, base
* absolute (direct): signed 12-bit operand
* LDA #5
* LDA #-42
* LDA #five
* pc-relative: signed 12-bit displacement
* LDA #label
* base-relative: unsigned 12-bit displacement
* LDA #label
* absolute extended: unsigned 20-bit operand
* +LDA #5
* +LDA #five
* +LDA #label

Indirect addressing
* precedence order: pc, base, absolute
* absolute (direct): unsigned 12-bit address
* LDA @5
* LDA @five
* pc-relative: signed 12-bit displacement
* LDA #label
* base-relative: unsigned 12-bit displacement
* LDA #label
* absolute extended: unsigned 20-bit address
* +LDA @5
* +LDA @five
* +LDA @label

Simple addressing
* precedence order: pc, base, absolute, sic absolute
* absolute (direct): unsigned 12-bit address
* LDA 5
* LDA five
* pc-relative: signed 12-bit displacement
* LDA #label
* base-relative: unsigned 12-bit displacement
* LDA #label
* sic absolute: unsigned 15 bit address
* LDA 5
* LDA five
* LDA label
* program becomes unrelocatable
* absolute extended: unsigned 20-bit address
* +LDA 5
* +LDA label
* all modes can be combined with indexed addressing
18 changes: 18 additions & 0 deletions doc/directives.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Supported directives

name START abs_expr
END expr

name CSECT
USE name

ORG abs_expr
LTORG


BASE expr
NOBASE

name EQU expr

RESx abs_expr
51 changes: 51 additions & 0 deletions doc/questions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
MSB vs. LSB
* p.5: ... words are addressed by the location of their lowest numbered byte
* p.47: prog 2.2: "LDA three" and storage directive "three WORD 3" ... seems as MSB
* What is lowest numbered byte? Is this LSB?
* Decision: We use MSB!

Register numbers
* p.5: PC=8, SW=9 due to compatibility with XE
* Why is number 7 unused?
* Number 9=10001b does not fit into 4 bits, e.g., in instructions ADDR, ...
* Better would be PC=7, SW=8

Multiple sections with the same name
* Is this allowed?
* No. Since, the CSECT format is: <section_name> CSECT and labels are unique.
* However, the assembler could easily be extended to support section reentry.
* Decision: by the book, no section reentry.

Addressing resolution
* p.59
* first try PC-relative, then base-relative
* if neither is applicable programmer must use format 4 (extended)
* So when direct/absolute addressing can be used? Only for absolute symbols?
* Can we after PC-rel and base-rel have failed use direct? See also next point.

Direct/absolute addressing in format 3 and SIC format
* Renders the code unrelocatable.
* In particular, it is unrelocatable only in the range of 12 bit displacement.
* Should we use this mode?

Immediate with negative operands
* e.g., LDA #-1
* use of direct/absolute addressing
* however in simple and indirect operand gives the absolute address, thus it is unsigned
* can in the case of immediate addressing the operand be signed.
* Decision: the assembler treats immediate as signed, all other as unsigned

Directive ORG value
* p.73: "value is a constant or an expression involving constants and previously defined symbols"
* Can we use forward reference? At least to absolute symbols. Yes?
* Thus, expressions consists of constants and symbols (absolute or (relative) previously defined)

Directive ORG and length of code?
* How does one calculate code length if it contains ORG:
* so there is a large non-assembled gap, or
* there ORG address is before start address (we have negative code length)
* See also p. 74 for a discussion on ORG (without parameter) used for resetting to the previous value.
* Decision:
* At the end of every section we implicitly issue ORG (reset the locctr).
* Then we calculate the length.
* Consequently, we ignore all the "ORG address" parts.
Binary file added img/rbp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 138 additions & 0 deletions src/sic/Asm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package sic;

import sic.asm.Assembler;
import sic.asm.ErrorCatcher;
import sic.asm.Options;
import sic.ast.Program;
import sic.common.Mnemonics;
import sic.asm.visitors.*;
import sic.common.Utils;

import java.io.*;

/**
* Sic/XE assembler.
*
* @author jure
*/
public class Asm {

public static final int Version_Major = 1;
public static final int Version_Minor = 0;

//
private boolean stdin;
private String input;
private Writer lstwriter;
private Writer logwriter;
private Writer objwriter;

public static void printHelp() {
System.out.print(
"Sic/XE Assembler " + Version_Major + "." + Version_Minor + "\n" +
"Usage: java sic.Asm options parameters\n" +
"Options:\n" +
" -help|-h Print help.\n" +
" -refshort Print short assembly reference.\n" +
" -reflong|-ref Print long assembly reference.\n" +
"\n" +
" -obj-dense Dense object files (without space).\n" +
" -obj-slack Slack object files (with space).\n" +
" -space-require Require whitespace after labels and mnemonics.\n" +
" -space-forgo\n" +
" -comment-dot-require Require dots in comments.\n" +
" -comment-dot-forgo.\n"
);
}

public void processArgs(String[] args) {
if (args.length > 0) {
if ("-help".equals(args[0]) || "-h".equals(args[0])) {
printHelp();
System.exit(0);
}
if ("-refshort".equals(args[0])) {
new Mnemonics().printReferenceShort();
System.exit(0);
}
if ("-reflong".equals(args[0]) || "-ref".equals(args[0])) {
new Mnemonics().printReferenceLong();
System.exit(0);
}
}
// assembler flags
int last = 0;
while (last < args.length) {
String arg = args[last];
if ("-obj-dense".equals(arg)) Options.addSpaceInObj = false;
if ("-obj-slack".equals(arg)) Options.addSpaceInObj = true;
if ("-space-require".equals(arg)) Options.requireWhitespace = true;
if ("-space-forgo".equals(arg)) Options.requireWhitespace = false;
if ("-comment-dot-require".equals(arg)) Options.requireCommentDot = true;
if ("-comment-dot-forgo".equals(arg)) Options.requireCommentDot = false;
if (!arg.startsWith("-")) break;
last++;
}
// use standard input?
if (last >= args.length) {
stdin = true;
input = Utils.readStdin();
lstwriter = new BufferedWriter(new OutputStreamWriter(System.out));
logwriter = lstwriter;
objwriter = lstwriter;
return;
}
// prepare files
String filename = args[last];
input = Utils.readFile(filename);
String basename = Utils.getFileBasename(filename);
lstwriter = Utils.createFileWriter(basename + ".lst");
logwriter = Utils.createFileWriter(basename + ".log");
objwriter = Utils.createFileWriter(basename + ".obj");
}

public void processSource() {
Assembler assembler = new Assembler();
ErrorCatcher errorCatcher = assembler.errorCatcher;
Program program = assembler.assemble(input);
if (errorCatcher.count() > 0) {
new WriteErrors(program, errorCatcher).visitCommands();
errorCatcher.print();
return;
}
//
try {
if (stdin) lstwriter.write("******************** Program *******************\n");
assembler.generateListing(program, lstwriter);
lstwriter.flush();
if (stdin) logwriter.write("******************** Structure *****************\n");
assembler.generateLog(program, logwriter);
logwriter.flush();
if (stdin) objwriter.write("********************** Text ********************\n");
assembler.generateObj(program, objwriter, Options.addSpaceInObj);
objwriter.flush();
if (!stdin) {
lstwriter.close();
logwriter.close();
objwriter.close();
}
} catch (IOException e) {
System.err.println("Error while generating files.");
}
errorCatcher.print();
}

public static void main(String[] args) {
Asm asm = new Asm();
asm.processArgs(args);
asm.processSource();
}

}

/* TODO: assembler todo list
assembler arguments
-sic ... use SIC
-sicxe ... use SIC/XE
-nosic ... do not use old SIC format
*/
48 changes: 48 additions & 0 deletions src/sic/Sim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package sic;

import sic.common.Mnemonics;
import sic.disasm.Disassembler;
import sic.sim.Executor;
import sic.sim.MainView;
import sic.sim.vm.Machine;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/**
* Simulator of the SIC/XE computer.
*
* @author jure
*/
public class Sim {

// TODO: -freq 10
// -registers
// -memory start len
// -debug level


public static void main(String[] args) throws Exception {
// ToolTipManager.sharedInstance().setDismissDelay(15000);
// UIManager.put("ToolTip.font", new FontUIResource("Courier New", Font.PLAIN, 14));
//
Machine machine = new Machine();
Executor executor = new Executor(machine);
Disassembler disassembler = new Disassembler(new Mnemonics(), machine);

final MainView mainView = new MainView(executor, disassembler);

if (args.length > 0) mainView.load(new File(args[0]));

// executor.start();
mainView.updateView();

executor.onBreakpoint = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
mainView.updateView();
}
};
}
}
39 changes: 39 additions & 0 deletions src/sic/asm/AsmError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package sic.asm;

import com.sun.istack.internal.NotNull;

/**
* Syntax errors.
*
* @author jure
*/
public class AsmError extends Exception implements Comparable<AsmError> {

public final Location loc;

public AsmError(Location loc, String msg) {
super(msg);
this.loc = loc;
}

public AsmError(Location loc, String format, Object... objs) {
this(loc, String.format(format, objs));
}

public AsmError(String format, Object... objs) {
this(null, format, objs);
}

@Override
public String toString() {
String head = "Error" + (loc != null ? " at " + loc + " (" + loc.pos + ")" : "");
String message = this.getLocalizedMessage();
return ((message != null) ? (head + ": " + message) : head) + ".";
}

@Override
public int compareTo(AsmError that) {
return this.loc.pos - that.loc.pos;
}

}
Loading

0 comments on commit e789d13

Please sign in to comment.