Example #1
0
def OpenFile():
    global addressCounter

    name = askopenfilename(filetypes=(("Assembly File", "*.s"), ("All Files",
                                                                 "*.*")),
                           title="Choose a file.")
    with open(name) as f:
        mem._init_()
        if (mode == "asm"):
            consoleList.insert(END, "Assembling source at: '" + name + "'")
            lc = 1
            for line in f:
                consoleList.insert(END, "->line " + str(lc))
                try:
                    if (line != "\n"):
                        addressCounter = first_pass.par(line, addressCounter)
                        if (line.rstrip() != ""):
                            consoleList.insert(
                                END,
                                str(addressCounter) + ": " + line.rstrip())
                        imc = asm.parse(line)
                        if (imc.rstrip() != ""):
                            consoleList.insert(END,
                                               "Assembly code:" + imc.strip())
                        else:
                            consoleList.insert(END, "Not(yet) an instruction!")
                except Exception as e:
                    consoleList.insert(
                        END, "Syntax Error at line: " + str(lc) + ": " + line +
                        "\n" + str(e))

                    break
                lc += 1
        else:
            consoleList.insert(END, "Processing source at: '" + name + "'")
            lc = 1
            for line in f:
                consoleList.insert(END, "->line " + str(lc))
                try:
                    if (line != "\n"):
                        addressCounter = first_pass.par(line, addressCounter)
                        imc = asm.parse(line)
                        proc.processline(imc)
                        if (imc.rstrip() != ""):
                            consoleList.insert(
                                END, line + " assembled binary: " + imc)
                except Exception as e:
                    consoleList.insert(
                        END, "Syntax Error at line: " + str(lc) + ": " + line +
                        "\n" + str(e))
                    break
                lc += 1
        readmemory()
        readregisters()
Example #2
0
def run(args):
    global addressCounter

    filename = args.input # these match the "dest": dest="input"
    output_filename = args.output # from dest="output"
    r_mode = args.mode

    mem_mod._init_()

    if(r_mode=="asm"):
        if(filename==None):
            run=True
            print("\n-------------------------POWER Sim V0.1 Assembler Console----------------------\n")
            while(run):
                line=input(">>>")
                if(line not in ["quit()","q()","exit","quit"]):
                    try:
                        addressCounter = first_pass.par(line, addressCounter)
                        imc=asm.parse(line)
                        print(imc)
                    except:
                        print("Error thrown")
                else:
                    run=False
        else:
            if(output_filename==None):
                with open(filename, "r") as f:
                    lc=1
                    #line=f.readline()[:-1]
                    #while(line!=""):
                    for line in f:
                        print("\n->line "+str(lc)+"\n")
                        try:
                            if(line!="\n"):
                                addressCounter = first_pass.par(line, addressCounter)
                                imc=asm.parse(line)
                                print(imc)
                        except Exception as e:
                            print("Syntax Error at line: "+str(lc)+": "+line+"\n"+str(e))
                            break
                        #line=f.readline()[:-1]
                        lc+=1
            else:
                with open(filename,"r") as f:
                    lc=1
                    fw=open(output_filename,"w")
                    #line=f.readline()[:-1]
                    #while(line!=""):
                    for line in f:
                        print("\n->line "+str(lc)+"\n")
                        try:
                            addressCounter = first_pass.par(line, addressCounter)
                            imc=asm.parse(line)
                            fw.write(imc)
                        except:
                            print("Syntax Error at line: "+str(lc))
                            break
                        #line=f.readline()[:-1]
                        lc+=1
    elif(r_mode=="proc"):
        if(filename==None):
            run=True
            print("\n-------------------------POWER Sim V0.1 Processor Console----------------------\n")
            while(run):
                line=input(">>>")
                if(line not in ["quit()","q()","exit","quit"]):
                    try:
                        imc=asm.parse(line)
                        prcs.processline(imc)
                    except:
                        print("Error thrown")
                else:
                    run=False