public static AsmProgram loadProgram(String fileName)
	throws AssemblerException {

		File file = new File(fileName);
		AsmProgram prog = new AsmProgram(Definitions.getInstance().getAddressesTable());
		if (!file.exists())
			throw new AssemblerException(fileName + " doesn't exist");

		if (fileName.endsWith(".hack")) {
			try {
				BufferedReader reader = new BufferedReader(new FileReader(fileName));
				String line;
				int pc = 0;

				while ((line = reader.readLine()) != null) {

					short value = 0;

					if (pc >= AsmProgram.MAXIMUM_PROGRAM_SIZE)
						throw new AssemblerException("Program too large");

					try {
						value = (short)Conversions.binaryToInt(line);
					} catch (NumberFormatException nfe) {
						throw new AssemblerException("Illegal character");
					}
					prog.addLine(value, null);
					pc++;
				}

				reader.close();
			} catch (IOException ioe) {
				throw new AssemblerException("IO error while reading " + fileName);
			}
		}
		else if (fileName.endsWith(".asm")) {
			try {
				AssemblyParser assembler = new AssemblyParser(fileName, false);
				prog = assembler.getProgram();
			} catch (HackTranslatorException ae) {
				throw new AssemblerException(ae.getMessage());
			}
		}
		else
			throw new AssemblerException(fileName + " is not a .hack or .asm file");

		return prog;
	}