コード例 #1
0
ファイル: step2.py プロジェクト: juanirow/esic
 def operation_type_3_4(self,cp,operator,arg,format_type,num_line,dir_type,type_c,is_index,valid_label):
     c = Convert()
     operator = self.get_binary_code(operator)
     flags = self.get_flags(dir_type)
     num_max = 3
     res = arg
     entra = True
     if format_type == 4:
         flags['e']=1
         num_max=5
         if not type_c and valid_label == "relativo":
             self.m_register.append(num_line)
         res = self.current_register.adjust_bytes(arg,num_max,True)
     else:
         if type_c:
             if not self.is_type_c(arg):
                 entra = True
             else:
                 entra = False
                 if not c.is_hexadecimal(arg):
                     arg = c.decimal_to_hexadecimal(arg)
                 res = self.current_register.adjust_bytes(arg,3,True)
         if entra:
             res = self.is_relative_cp(cp,arg)
             if not res:
                 res = self.relative_base(arg)
                 if res:
                     flags['b'] = 1
                 else:
                     res = arg
                     valid_label = False
             else:
                 flags['p'] = 1
             res = self.current_register.adjust_bytes(res,num_max,True)
     if is_index:
         flags['x'] = 1
     if not valid_label:
         flags['b'] = 1
         flags['p'] = 1
     if valid_label == "_":
         flags['b'] = 0
         flags['p'] = 0
     flags = self.flags_string(flags)
     val = operator + flags
     val = str(int(val,2))
     val = c.decimal_to_hexadecimal(val)
     if len(val)==3:
         val = "0"+val
     val = self.current_register.adjust_bytes(val,3,True)
     val += str(res)
     del c
     return val
コード例 #2
0
ファイル: step2.py プロジェクト: juanirow/esic
 def operations_type2_n(self,operator,n1):
     operation_code = self.operations[operator]
     c = Convert()
     n1 = c.decimal_to_hexadecimal(n1)
     n1 = n1[:-1]
     del c
     return operation_code + str(n1) + "0"
コード例 #3
0
ファイル: step2.py プロジェクト: juanirow/esic
 def operations_type_2_rn(self,operator,r,n):
     operation_code = self.operations[operator]
     r = self.registers.get(r,"")
     c = Convert()
     n = c.decimal_to_hexadecimal(n)
     n = n[:-1]
     del c
     obj_code = operation_code + r + str(n)
     return obj_code
コード例 #4
0
ファイル: step2.py プロジェクト: juanirow/esic
 def directive_word(self,value):
     c = Convert()
     if not c.is_hexadecimal(value):
         value = int(float(value))
         value = c.decimal_to_hexadecimal(value)
     r = Register("T")
     value = r.adjust_bytes(value,6,True)
     value = r.filter_number(value)
     del r
     return value
コード例 #5
0
ファイル: bloque.py プロジェクト: Juanirow/esic
 def get_len_program(self):
     c = Convert()
     x = self.bloques[-1]
     ini = self.bloques[0]
     val = c.to_decimal(x.get_load_dir())
     val_len = c.to_decimal(x.length)
     val_ini = c.to_decimal(ini.get_load_dir())
     val = val + val_len - val_ini
     val = c.decimal_to_hexadecimal(val)
     return val
コード例 #6
0
 def make_T(self):
     c = Convert()
     dir = self.filter_number(self.init_dir)
     dir = self.adjust_bytes(dir,6,False)
     len_register = len(self.register)/2
     len_hex = c.decimal_to_hexadecimal(len_register)
     hex = self.filter_number(len_hex)
     hex = self.adjust_bytes(hex,2,False)
     register = "T" + dir +hex+self.register
     return register
コード例 #7
0
ファイル: hexadecimal.py プロジェクト: juanirow/esic
 def div(self,num1,num2):
     convert = Convert()
     num1 = self.change_hexadecimal(num1)
     num2 = self.change_hexadecimal(num2)
     num1 = convert.to_decimal(num1)
     num2 = convert.to_decimal(num2)
     res = int(num1)/int(num2)
     res = convert.decimal_to_hexadecimal(res)
     del convert
     return res
コード例 #8
0
ファイル: bloque.py プロジェクト: juanirow/esic
 def get_len_program(self):
     c = Convert()
     x = self.bloques[-1]
     ini = self.bloques[0]
     val = c.to_decimal(x.get_load_dir())
     val_len = c.to_decimal(x.length)
     val_ini = c.to_decimal(ini.get_load_dir())
     val = val + val_len - val_ini
     val = c.decimal_to_hexadecimal(val)
     return val
コード例 #9
0
ファイル: step2.py プロジェクト: juanirow/esic
 def get_value_cad_BYTE(self,data):
     string_out =""
     c = Convert()
     r = Register("T")        
     for caracter in data:
         car = str(ord(caracter))
         car = c.decimal_to_hexadecimal(car)
         car = r.filter_number(car)
         string_out+=car
     del c
     return string_out
コード例 #10
0
 def make_M_modificado(self,obj_code,cp_num):
     c = Convert()
     cp_num = c.to_decimal(cp_num)
     cp_num = c.decimal_to_hexadecimal(cp_num)        
     dir= self.filter_number(cp_num)
     dir = self.adjust_bytes(dir,6,False)
     edit_bytes = obj_code
     len_bytes = len(edit_bytes)
     len_bytes = self.adjust_bytes(str(len_bytes),2,False)
     register = "M" + str(dir) + str(len_bytes)+"+"+self.name
     return register
コード例 #11
0
ファイル: hexadecimal.py プロジェクト: juanirow/esic
 def plus(self,num1,num2):
     convert = Convert()
     num1 = self.change_hexadecimal(num1)
     num2 = self.change_hexadecimal(num2)
     num1 = convert.to_decimal(num1)
     num2 = convert.to_decimal(num2)
     if not num1 == -1 and not num2 ==-1:            
         res = num1+num2
         res = convert.decimal_to_hexadecimal(res)
         return res
     else:
         return "error"
コード例 #12
0
ファイル: hexadecimal.py プロジェクト: juanirow/esic
 def subs(self,num1,num2):
     convert = Convert()
     num1 = self.change_hexadecimal(num1)
     num2 = self.change_hexadecimal(num2)
     num1 = convert.to_decimal(num1)
     num2 = convert.to_decimal(num2)          
     res = num1-num2
     if res < 0:
         res = int(res * -1)
         res = res ^ 4095
         res += 1
     if res == 0:
         res = "0H"
     else:
         res = convert.decimal_to_hexadecimal(res)
     return res
コード例 #13
0
ファイル: hexadecimal.py プロジェクト: juanirow/esic
    def mul(self,num1,num2):
        convert = Convert()
        num1 = self.change_hexadecimal(num1)
        num2 = self.change_hexadecimal(num2)
        num1 = convert.to_decimal(num1)
        num2 = convert.to_decimal(num2)
        res = int(num1)*int(num2)
        res = convert.decimal_to_hexadecimal(res)
        del convert
        return res

    
    
            
#hex = Hexadecimal()
#print hex.plus("0H","23H")
コード例 #14
0
ファイル: hexadecimal.py プロジェクト: juanirow/esic
 def suma(self,num1,num2):
     convert = Convert()
     print "antes",num1,num2       
     num1 = self.get_int_operator(num1)
     num2 = self.get_int_operator(num2)  
     res = num1+num2     
     print "despues",num1,num2,res
     if res < 0:
         res = int(res * -1)
         res = res ^ 4095
         res += 1
     if res == 0:
         res = "0H"
     else:
         res = convert.decimal_to_hexadecimal(res)
     print "resultado",res
     return res
コード例 #15
0
ファイル: step2.py プロジェクト: juanirow/esic
 def operations_code(self,operator,m,is_index):
     r = Register("T")
     c = Convert()        
     op = self.operations[operator]
     op = op+"H"
     op = c.to_decimal(op)
     op = int(op)
     binary = c.decimal_to_binary(op,24)
     binary = c.shift_binary_left(binary,16)
     if is_index:
         binary = c.mask_or(binary,"000000001000000000000000")
     m = c.to_decimal(m)
     m = int(m)
     m = c.decimal_to_binary(m,24)
     binary = c.mask_or(binary,m)
     val = int(binary,2)
     val = c.decimal_to_hexadecimal(val)
     val = r.filter_number(val)  
     val = r.adjust_bytes(val,6,False)
     del r
     del c
     return val
コード例 #16
0
ファイル: Cargadorx.py プロジェクト: Juanirow/esic
class Cargadorx():
    def __init__(self,window):
        self.window = window
        self.tabse = Tabse()
        self.lonsc = "0H"
        self.dirsc = "0H"
        self.dirprog = "0H"
        self.direj = "0H"
        self.hexa = Hexadecimal()
        self.convert = Convert()
        self.register = Register("A")
        self.error_indefinido = False
        self.error_duplicado = False

    def show_error(self,msg):
        ##QtGui.QMessageBox.about(self.window,"Error",msg)
        self.window.textEdit_Actions.setText(msg)

    def load_file_name(self,list_obj,dirprog):
        val_int = self.convert.to_decimal(dirprog)
        self.dirprog = self.convert.decimal_to_hexadecimal(val_int)
        self.dirprog = self.register.adjust_bytes(self.dirprog,6,False)+"H"
        self.dirsc = self.dirprog
        self.step_1(list_obj)
        if not self.error_duplicado:
            self.create_memory()
            self.dirsc = self.dirprog
            self.direj = self.dirprog
            self.step_2(list_obj)
            self.init_empty_rows()
            self.tabse.print_tabse()
            if self.error_indefinido:
                self.show_error("Error en simbolo indefinido")
        else:
            self.show_error("Error simbolo duplicado")



    def step_1(self,list_obj):
        for list_n in list_obj:
            for n in list_n:
                if len(n) > 0:
                    if n[0] == "H":
                        self.step_h(n,1)
                    elif n[0] == "D":
                        self.step_1_d(n)
            self.dirsc = self.hexa.plus(self.dirsc,self.lonsc)

    def step_h(self,n,step):
        name = n[1:7]
        name = name.strip()
        self.lonsc = n[13:]+"H"
        if step == 1:
            if not self.tabse.exist_node(name):
                self.tabse.insert_section(name,self.dirsc,self.lonsc)
            else:
                ##print name
                self.error_duplicado = True

    def step_1_d(self,n):
        num = (len(n)-1)/12
        it = 0
        # print "num",num,len(n)
        while it < num:
            index1 = (it * 12)+1
            index2 = index1 + 6
            index3 = index2 + 6
            name = n[index1:index2].strip()
            #print "name",name 
            if index3 >= len(n):
                len_r = n[index2:]+"H"
            else:
                len_r = n[index2:index3]+"H"
            if not self.tabse.exist_node(name):
                val = self.hexa.plus(len_r,self.dirsc)
                self.tabse.insert_variable(name,val)
            else:
                print "error",name
                self.error_duplicado = True
            it += 1

    def step_2(self,list_obj):
        for list_n in list_obj:
            for n in list_n:
                if len(n) > 0:
                    if n[0] == "H":
                        self.step_h(n,2)
                    elif n[0] == "T":
                        self.charge_obj_code(n)
                    elif n[0] == "M":
                        self.change_m_register(n)
                    elif n[0] == "E":
                        self.reg_e(n)
            self.dirsc = self.hexa.plus(self.dirsc,self.lonsc) 

    def reg_e(self,r):
        if len(r) > 1:
            val = r[1:] + "H"
            self.direj = self.hexa.plus(self.dirsc,val)

    def charge_obj_code(self,r):
        string = r[9:]
        index = 0
        init = r[1:7]
        init = self.hexa.plus(init+"H",self.dirsc)[:-1]
        col_start = init[-1]+"H"
        col = int(self.convert.to_decimal(col_start)  + 1)
        dat1 = self.get_part_dat(init)
        res = self.hexa.subs(dat1,self.dirprog[:-2])
        dec_res = int(self.convert.to_decimal(res))
        while index < len(string):
            byte = string[index:index+2]
            item = QtGui.QTableWidgetItem(byte)
            self.window.tableWidget.setItem(dec_res,col,item)
            index+=2
            col = (col + 1) % 17
            if col == 0:
                col = 1
                dec_res += 1

    def get_part_dat(self,dat):
        if len(dat) == 1:
            return "0"
        else:
            return dat[:-1]

    def change_m_register(self,r):
        val = r[1:7]
        med_byte = r[7:9]
        sign = r[9]
        name = r[10:].strip()
        # print val,med_byte,sign,name
        n = self.tabse.get_register(name)
        if n:
            # print "existe"
            val = self.hexa.plus(val,self.dirsc)[:-1]
            content = self.get_content_at(val,3)
            # print val,content
            ant_content = ""
            if med_byte == "5":
                ant_content = content[0]
                content = content[1:]
            dir_es = n.get_dir()
            new_dir = self.make_operation(sign,content,dir_es)
            # print "perico",new_dir,content,sign,dir_es
            new_dir = self.register.adjust_bytes(new_dir,6,True)
            if med_byte == "5":
                new_dir = ant_content + new_dir[1:]
            new_dir = ant_content + new_dir
            # print new_dir
            col_num = val[-1] + "H"
            col = int(self.convert.to_decimal(col_num) + 1)
            val = self.get_part_dat(val)
            ren = self.hexa.subs(val,self.dirprog[:-2])
            ren = int(self.convert.to_decimal(ren))
            index = 0
            while index < len(new_dir):
                byte = new_dir[index:index+2]
                item = QtGui.QTableWidgetItem(byte)
                self.window.tableWidget.setItem(ren,col,item)
                index+=2
                col = (col + 1) % 17
                if col == 0:
                    col = 1
                    ren += 1
        else:
            self.error_indefinido = True

    def make_operation(self,sign,dat1,dat2):
        val1 = self.get_int_operator(dat1)
        val2 = self.get_int_operator(dat2)
        if sign == "-":
            ret = val1-val2
        else:
            ret = val1+val2
        ret = self.exp_to_hexadecimal(ret)
        return ret

    def get_int_operator(self,dat):
        if dat[-1] == "H":
            dat = dat[:-1]
        if dat[0] == "F":
            string = ""
            it = 0
            while it < len(dat):
                if not dat[it] == "F":
                    string += dat[it]
                it += 1
            if len(string) == 0:
                return -1
            else:
                val = "1"+("0"*len(string))+"H"
                val = self.convert.to_decimal(val)
                val2 = self.convert.to_decimal(string+"H")
                return val2-val
        else:
            return self.convert.to_decimal(dat+"H")


    def get_content_at(self,dirr,num):
        dir_n = dirr[-1]+"H"
        col = int(self.convert.to_decimal(dir_n) + 1)
        dire = self.get_part_dat(dirr)
        ren = self.hexa.subs(dire,self.dirprog[:-2])
        ren = int(self.convert.to_decimal(ren))
        it = 0
        text = ""
        while it < num:
            item = self.window.tableWidget.item(ren,col)
            text += str(item.text())
            it += 1
            col = (col + 1) % 17
            if col == 0:
                col = 1
                ren += 1 
        return text

    def exp_to_hexadecimal(self,val):
        if val < 0:
            val = int(val * -1)
            val = val ^ 65535
            val += 1
        if val == 0:
            val = "0H"
        else:
            val = self.convert.decimal_to_hexadecimal(val)
            if val[0] == "F" and len(val) > 6:
                val = "0"+val
        return val



    def create_memory(self):
        init = self.dirprog[:-1]
        length = self.hexa.subs(self.dirsc,self.dirprog)[:-1]
        star_rows= length[:-1]
        index = init[:-1]
        num_rows=star_rows+"H"
        num_rows=int(self.convert.to_decimal(num_rows))
        self.window.tableWidget.setRowCount(num_rows+1)
        it = 0
        while it <= num_rows:
            dir = index+"0H"
            dir = self.register.adjust_bytes(dir,6,False)
            item = QtGui.QTableWidgetItem(dir)
            self.window.tableWidget.setItem(it,0,item)
            it += 1
            index = self.hexa.plus(index,"1H")[:-1]

    def init_empty_rows(self):
        rows_count = self.window.tableWidget.rowCount()
        colum_count = self.window.tableWidget.columnCount()
        for i in range(rows_count):
            for j in range(colum_count):
                item = self.window.tableWidget.item(i,j)                
                if item == None:
                    item_text = QtGui.QTableWidgetItem("FF")
                    self.window.tableWidget.setItem(i,j,item_text)
コード例 #17
0
class Segment:
    def __init__(self):
        self.index = 0
        self.list_n = []
        self.conv = Convert()
        self.reg = Register("X")
        self.hexa = Hexadecimal()
        self.last_code = 0

    ## regresa el segmento actual
    def get_segment(self):
        return self.list_n[self.index]
    
    ##crea un segmento con el nombre especificado
    # @param name nombre del segmento que se creara 
    def new_segment(self,name):
        self.index = len(self.list_n)
        self.list_n.append(NodoS(name,self.index))


    ##inserta una etiqueta a la tabla de simbolos y si esta ya se encuentra marca un error
    #@param name simbolo que se intentara insertar a la tabla
    #@param dir_val direccion o valor del simbolo
    #@param sym_type tipo del simbolo el cual puede ser relativo o absoluto
    #@param lineno numero de linea donde se encontro la etiqueta
    def insert_symbol(self,name,dir_val,sym_type,lineno,bloque_index,externo = False):
        if self.exist_symbol(name):
            self.insert_error(str(lineno),"etiqueta previamente definida")
        else:
            sym = Symbol(name,dir_val,sym_type,bloque_index,externo)
            self.get_segment().symbols.append(sym)
            
    def exist_symbol(self ,name):
        for it in self.get_segment().symbols:
            if it.get_name() == name:
                return it
        return None
        
    ##checa si en el diccionario de errores ya se inserto un error en esa linea de codigo
    #y si no es asi la inserta 
    #@param line linea de codigo donde se encontro un error
    #@param text cadena que se genera en el error
    def insert_error(self,line,text):
        l = int(line) - self.last_code -1
        if not str(l) in self.get_segment().errors and l >= 0:
            self.get_segment().errors[str(l)]= text
    
    ##checa si en el diccionario de advertencias ya se inserto un error en esa linea de codigo
    #y si no es asi la inserta 
    #@param line linea de codigo donde se encontro un warnind
    #@param text cadena que se genera en el warning
    def insert_warning(self,line,text):
        l = int(line) - self.last_code
        if not str(l) in self.get_segment().warnings:
            self.get_segment().warnings[str(line)] = text
            
    ##aumenta el contador de programa 
    #@param increment cantidad en hexadecimal que se le agregara al CP
    def increment_PC(self,increment):
        num1 = self.get_segment().pc[-1]
        if not self.conv.is_hexadecimal(str(increment)):
            increment = self.conv.decimal_to_hexadecimal(increment)
        val = self.hexa.plus(num1,increment)
        if val == "H":
            val = "0H"
        val = self.reg.adjust_bytes(val,6,False)+"H"
        self.get_segment().bloques.set_last_cp(val)
        self.get_segment().pc.append(val)
        self.get_segment().num_bloque.append(self.get_segment().bloques.get_index())
        
    ## calcula el tamaño del programa 
    #@return regresa en hexadecimal el tamaño del programa
    def get_len_program(self):
        return  self.get_segment().bloques.get_len_program()

    ## genera y completa la tabla de bloques de todos los segmentos 
    def genera_tabla_bloques(self):
        for it in self.list_n:
            it.bloques.gen_table()
    ## regresa un segmento en un index especificado   
    # @param index posicion del segmento que se quiere
    def get_segment_at(self,index):
        return self.list_n[index] 
    
    ## imprime los resultados de un segmento 
    # @param extension es la extencion que tendran los archivos de salida de los segmentos       
    def print_results(self,extension):
        for it in self.list_n:
            # print it.errors,it.errors_s
            it.archivo_intermedio(extension)
            if len(it.errors) == 0 and len(it.errors_s) == 0:
                it.archivo_objeto(extension)
            print "Errors", len(it.errors)+len(it.errors_s)

    def get_num_errors_all(self):
        cant = 0
        for it in self.list_n:
            cant += len(it.errors_s)
            cant += len(it.errors)
        return cant 
コード例 #18
0
ファイル: Cargador.py プロジェクト: Juanirow/esic
 def increment_cp(self, num):
     c = Convert()
     num = c.decimal_to_hexadecimal(num)
     cp = self.get_CP_value()
     cp = self.hex.plus(cp, num)
     self.set_cp_value(cp)
コード例 #19
0
class Cargadorx():
    def __init__(self, window):
        self.window = window
        self.tabse = Tabse()
        self.lonsc = "0H"
        self.dirsc = "0H"
        self.dirprog = "0H"
        self.direj = "0H"
        self.hexa = Hexadecimal()
        self.convert = Convert()
        self.register = Register("A")
        self.error_indefinido = False
        self.error_duplicado = False

    def show_error(self, msg):
        ##QtGui.QMessageBox.about(self.window,"Error",msg)
        self.window.textEdit_Actions.setText(msg)

    def load_file_name(self, list_obj, dirprog):
        val_int = self.convert.to_decimal(dirprog)
        self.dirprog = self.convert.decimal_to_hexadecimal(val_int)
        self.dirprog = self.register.adjust_bytes(self.dirprog, 6, False) + "H"
        self.dirsc = self.dirprog
        self.step_1(list_obj)
        if not self.error_duplicado:
            self.create_memory()
            self.dirsc = self.dirprog
            self.direj = self.dirprog
            self.step_2(list_obj)
            self.init_empty_rows()
            self.tabse.print_tabse()
            if self.error_indefinido:
                self.show_error("Error en simbolo indefinido")
        else:
            self.show_error("Error simbolo duplicado")

    def step_1(self, list_obj):
        for list_n in list_obj:
            for n in list_n:
                if len(n) > 0:
                    if n[0] == "H":
                        self.step_h(n, 1)
                    elif n[0] == "D":
                        self.step_1_d(n)
            self.dirsc = self.hexa.plus(self.dirsc, self.lonsc)

    def step_h(self, n, step):
        name = n[1:7]
        name = name.strip()
        self.lonsc = n[13:] + "H"
        if step == 1:
            if not self.tabse.exist_node(name):
                self.tabse.insert_section(name, self.dirsc, self.lonsc)
            else:
                ##print name
                self.error_duplicado = True

    def step_1_d(self, n):
        num = (len(n) - 1) / 12
        it = 0
        # print "num",num,len(n)
        while it < num:
            index1 = (it * 12) + 1
            index2 = index1 + 6
            index3 = index2 + 6
            name = n[index1:index2].strip()
            #print "name",name
            if index3 >= len(n):
                len_r = n[index2:] + "H"
            else:
                len_r = n[index2:index3] + "H"
            if not self.tabse.exist_node(name):
                val = self.hexa.plus(len_r, self.dirsc)
                self.tabse.insert_variable(name, val)
            else:
                print "error", name
                self.error_duplicado = True
            it += 1

    def step_2(self, list_obj):
        for list_n in list_obj:
            for n in list_n:
                if len(n) > 0:
                    if n[0] == "H":
                        self.step_h(n, 2)
                    elif n[0] == "T":
                        self.charge_obj_code(n)
                    elif n[0] == "M":
                        self.change_m_register(n)
                    elif n[0] == "E":
                        self.reg_e(n)
            self.dirsc = self.hexa.plus(self.dirsc, self.lonsc)

    def reg_e(self, r):
        if len(r) > 1:
            val = r[1:] + "H"
            self.direj = self.hexa.plus(self.dirsc, val)

    def charge_obj_code(self, r):
        string = r[9:]
        index = 0
        init = r[1:7]
        init = self.hexa.plus(init + "H", self.dirsc)[:-1]
        col_start = init[-1] + "H"
        col = int(self.convert.to_decimal(col_start) + 1)
        dat1 = self.get_part_dat(init)
        res = self.hexa.subs(dat1, self.dirprog[:-2])
        dec_res = int(self.convert.to_decimal(res))
        while index < len(string):
            byte = string[index:index + 2]
            item = QtGui.QTableWidgetItem(byte)
            self.window.tableWidget.setItem(dec_res, col, item)
            index += 2
            col = (col + 1) % 17
            if col == 0:
                col = 1
                dec_res += 1

    def get_part_dat(self, dat):
        if len(dat) == 1:
            return "0"
        else:
            return dat[:-1]

    def change_m_register(self, r):
        val = r[1:7]
        med_byte = r[7:9]
        sign = r[9]
        name = r[10:].strip()
        # print val,med_byte,sign,name
        n = self.tabse.get_register(name)
        if n:
            # print "existe"
            val = self.hexa.plus(val, self.dirsc)[:-1]
            content = self.get_content_at(val, 3)
            # print val,content
            ant_content = ""
            if med_byte == "5":
                ant_content = content[0]
                content = content[1:]
            dir_es = n.get_dir()
            new_dir = self.make_operation(sign, content, dir_es)
            # print "perico",new_dir,content,sign,dir_es
            new_dir = self.register.adjust_bytes(new_dir, 6, True)
            if med_byte == "5":
                new_dir = ant_content + new_dir[1:]
            new_dir = ant_content + new_dir
            # print new_dir
            col_num = val[-1] + "H"
            col = int(self.convert.to_decimal(col_num) + 1)
            val = self.get_part_dat(val)
            ren = self.hexa.subs(val, self.dirprog[:-2])
            ren = int(self.convert.to_decimal(ren))
            index = 0
            while index < len(new_dir):
                byte = new_dir[index:index + 2]
                item = QtGui.QTableWidgetItem(byte)
                self.window.tableWidget.setItem(ren, col, item)
                index += 2
                col = (col + 1) % 17
                if col == 0:
                    col = 1
                    ren += 1
        else:
            self.error_indefinido = True

    def make_operation(self, sign, dat1, dat2):
        val1 = self.get_int_operator(dat1)
        val2 = self.get_int_operator(dat2)
        if sign == "-":
            ret = val1 - val2
        else:
            ret = val1 + val2
        ret = self.exp_to_hexadecimal(ret)
        return ret

    def get_int_operator(self, dat):
        if dat[-1] == "H":
            dat = dat[:-1]
        if dat[0] == "F":
            string = ""
            it = 0
            while it < len(dat):
                if not dat[it] == "F":
                    string += dat[it]
                it += 1
            if len(string) == 0:
                return -1
            else:
                val = "1" + ("0" * len(string)) + "H"
                val = self.convert.to_decimal(val)
                val2 = self.convert.to_decimal(string + "H")
                return val2 - val
        else:
            return self.convert.to_decimal(dat + "H")

    def get_content_at(self, dirr, num):
        dir_n = dirr[-1] + "H"
        col = int(self.convert.to_decimal(dir_n) + 1)
        dire = self.get_part_dat(dirr)
        ren = self.hexa.subs(dire, self.dirprog[:-2])
        ren = int(self.convert.to_decimal(ren))
        it = 0
        text = ""
        while it < num:
            item = self.window.tableWidget.item(ren, col)
            text += str(item.text())
            it += 1
            col = (col + 1) % 17
            if col == 0:
                col = 1
                ren += 1
        return text

    def exp_to_hexadecimal(self, val):
        if val < 0:
            val = int(val * -1)
            val = val ^ 65535
            val += 1
        if val == 0:
            val = "0H"
        else:
            val = self.convert.decimal_to_hexadecimal(val)
            if val[0] == "F" and len(val) > 6:
                val = "0" + val
        return val

    def create_memory(self):
        init = self.dirprog[:-1]
        length = self.hexa.subs(self.dirsc, self.dirprog)[:-1]
        star_rows = length[:-1]
        index = init[:-1]
        num_rows = star_rows + "H"
        num_rows = int(self.convert.to_decimal(num_rows))
        self.window.tableWidget.setRowCount(num_rows + 1)
        it = 0
        while it <= num_rows:
            dir = index + "0H"
            dir = self.register.adjust_bytes(dir, 6, False)
            item = QtGui.QTableWidgetItem(dir)
            self.window.tableWidget.setItem(it, 0, item)
            it += 1
            index = self.hexa.plus(index, "1H")[:-1]

    def init_empty_rows(self):
        rows_count = self.window.tableWidget.rowCount()
        colum_count = self.window.tableWidget.columnCount()
        for i in range(rows_count):
            for j in range(colum_count):
                item = self.window.tableWidget.item(i, j)
                if item == None:
                    item_text = QtGui.QTableWidgetItem("FF")
                    self.window.tableWidget.setItem(i, j, item_text)
コード例 #20
0
class Simuladorx(QtGui.QDockWidget):
    REG_CP = 0
    REG_A = 1
    REG_X = 2
    REG_L = 3
    REG_SW = 4
    REG_B = 5
    REG_S = 6
    REG_T = 7
    REG_F = 8

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        self.window = Ui_DockWidget()
        self.window.setupUi(self)
        self.add_registers()
        self.cargador = None
        self.hexa = Hexadecimal()
        self.convert = Convert()
        self.register = Register("A")
        self.init_registers()
        self.end_program = "0H"
        self.cc_val = "="
        self.window.btnSimular.clicked.connect(self.simular)
        self.operations_3 = {
            "18": "ADD",
            "00": "LDA",
            "40": "AND",
            "28": "COMP",
            "24": "DIV",
            "3C": "J",
            "30": "JEQ",
            "34": "JGT",
            "38": "JLT",
            "48": "JSUB",
            "50": "LDCH",
            "08": "LDL",
            "04": "LDX",
            "20": "MUL",
            "4C": "RSUB",
            "0C": "STA",
            "54": "STCH",
            "14": "STL",
            "E8": "STSW",
            "10": "STX",
            "1C": "SUB",
            "2C": "TIX",
            "58": "ADDF",
            "88": "COMPF",
            "64": "DIVF",
            "68": "LDB",
            "70": "LDF",
            "6C": "LDS",
            "74": "LDT",
            "D0": "LPS",
            "60": "MULF",
            "EC": "SSK",
            "78": "STB",
            "80": "STF",
            "D4": "STI",
            "7C": "STS",
            "E8": "STSW",
            "84": "STT",
            "5C": "SUBF",
            "E0": "TD",
            "DC": "WD",
            "44": "OR"
        }
        self.operations_1 = {
            "C4": "FIX",
            "C0": "FLOAT",
            "F4": "HIO",
            "C8": "NORM",
            "F0": "SIO",
            "F8": "TIO"
        }
        self.operations_2 = {
            "90": "ADDR",
            "B4": "CLEAR",
            "A0": "COMPR",
            "9C": "DIVR",
            "98": "MULR",
            "AC": "RMO",
            "A4": "SHIFTL",
            "A8": "SHIFTR",
            "94": "SUBR",
            "B0": "SVC",
            "B8": "TIXR"
        }
        self.operations = {
            "18": self.add,
            "00": self.lda,
            "40": self.and_op,
            "28": self.comp,
            "24": self.div,
            "3C": self.j_op,
            "30": self.jeq,
            "34": self.jgt,
            "38": self.jlt,
            "48": self.jsub,
            "50": self.ldch,
            "08": self.ldl,
            "04": self.ldx,
            "20": self.mul,
            "4C": self.rsub,
            "0C": self.sta,
            "54": self.stch,
            "14": self.stl,
            "E8": self.stsw,
            "10": self.stx,
            "1C": self.sub,
            "2C": self.tix,
            "58": self.float_operations,
            "88": self.float_operations,
            "64": self.float_operations,
            "68": self.ldb,
            "70": self.float_operations,
            "6C": self.lds,
            "74": self.ldt,
            "D0": self.system_operations,
            "60": self.float_operations,
            "EC": self.system_operations,
            "78": self.stb,
            "80": self.float_operations,
            "D4": self.system_operations,
            "7C": self.sts,
            "E8": self.system_operations,
            "84": self.stt,
            "5C": self.float_operations,
            "E0": self.system_operations,
            "DC": self.system_operations,
            "C4": self.float_operations,
            "C0": self.float_operations,
            "F4": self.system_operations,
            "C8": self.float_operations,
            "F0": self.system_operations,
            "44": self.or_op,
            "F8": self.system_operations,
            "90": self.addr,
            "B4": self.clear,
            "A0": self.compr,
            "9C": self.divr,
            "98": self.mulr,
            "AC": self.rmo,
            "A4": "SHIFTL",
            "A8": "SHIFTR",
            "94": self.subr,
            "B0": "SVC",
            "B8": self.tixr
        }
        self.registers = {
            "0": [self.REG_A, "A"],
            "1": [self.REG_X, "X"],
            "2": [self.REG_L, "L"],
            "8": [self.REG_CP, "CP"],
            "9": [self.REG_SW, "SW"],
            "3": [self.REG_B, "B"],
            "4": [self.REG_S, "S"],
            "5": [self.REG_T, "T"],
            "6": [self.REG_F, "F"]
        }
        self.operations_m = [
            "J", "JLT", "JEQ", "JGT", "JSUB", "STA", "STB", "STCH", "STL",
            "STS", "STSW", "STT", "STX", "LDCH"
        ]

    def simular(self):
        num_actions = self.get_count_next_actions()
        print "num actions", num_actions
        if num_actions == -1:
            self.window.textEdit_Actions.setText(
                "Numero de simulaciones no Validas")
        else:
            self.make_n_simulations(num_actions)

    def make_n_simulations(self, number):
        it = 0
        while it < number:
            cp = self.get_register(self.REG_CP)
            if self.hexa.minus_than(cp, self.end_program):
                op = self.get_operation()
                type_op = op[2]
                inst = op[1]
                m = self.get_m(type_op, cp, inst)
                if m == "Error":
                    self.window.textEdit_Actions.setText(
                        "El programa se termino debido a un error de operacion"
                    )
                else:
                    fun = self.operations[op[0]]
                    fun(m)
                    self.show_next_instr()
            else:
                self.window.textEdit_Actions.setText("El programa se termino")
            it += 1

    def get_m(self, type_op, cp, inst):
        if type_op == "Error":
            return type_op
        if type_op == "1":
            self.increment_cp(1)
            return "0"
        if type_op == "2":
            cp_n = self.hexa.plus(cp, "1H")
            self.increment_cp(2)
            return self.get_data_form_mem(cp_n, 1)
        if inst in self.operations_m:
            print "\n\n" + inst + "\n\n"
            return self.get_m_type3_m()
        return self.get_m_type3()

    def get_count_next_actions(self):
        count_actions = str(self.window.textEdit_Num.toPlainText())
        if count_actions == "":
            count_actions = 1
        elif not count_actions.isdigit():
            return -1
        return int(count_actions)

    def system_operations(self, val):
        self.window.textEdit_Actions.setText(
            "No tiene los permisos \n para ejecutar esta instruccion")

    def float_operations(self, val):
        self.window.textEdit_Actions.setText(
            "Las instrucciones flotantes \n no se pueden ejecutar")

    def add_registers(self):
        self.window.tableWidget_2.setRowCount(9)
        item = QtGui.QTableWidgetItem()
        item.setText("B")
        self.window.tableWidget_2.setVerticalHeaderItem(5, item)
        item = QtGui.QTableWidgetItem()
        item.setText("S")
        self.window.tableWidget_2.setVerticalHeaderItem(6, item)
        item = QtGui.QTableWidgetItem()
        item.setText("T")
        self.window.tableWidget_2.setVerticalHeaderItem(7, item)
        item = QtGui.QTableWidgetItem()
        item.setText("F")
        self.window.tableWidget_2.setVerticalHeaderItem(8, item)

    def init_registers(self):
        it = 0
        while it < 9:
            item_text = QtGui.QTableWidgetItem("FFFFFFFH")
            self.window.tableWidget_2.setItem(it, 0, item_text)
            it += 1

    def set_register(self, reg_num, val):
        val_hex = self.register.adjust_bytes(val, 6, False)
        val_hex = self.hexa.change_hexadecimal(val_hex)
        item_text = QtGui.QTableWidgetItem(val_hex)
        self.window.tableWidget_2.setItem(reg_num, 0, item_text)

    def get_register(self, reg_num):
        item = self.window.tableWidget_2.item(reg_num, 0)
        return str(item.text())

    def carga(self, list_obj, dirprog):
        self.cargador = Cargadorx(self.window)
        self.cargador.load_file_name(list_obj, dirprog)
        cp = self.cargador.direj
        self.set_register(self.REG_CP, cp)
        self.show_next_instr()
        self.end_program = self.cargador.dirsc
        if self.cargador.error_duplicado:
            QtGui.QMessageBox.about(self, "Error", "Error simbolo duplicado")
        elif self.cargador.error_indefinido:
            QtGui.QMessageBox.about(self, "Error", "Error simbolo indefinido")

    def increment_cp(self, num):
        num_hexa = self.convert.decimal_to_hexadecimal(num)
        cp = self.get_register(self.REG_CP)
        res = self.hexa.plus(num_hexa, cp)
        self.set_register(self.REG_CP, res)

    def show_next_instr(self):
        op = self.get_operation()
        self.window.label_sig.setText(op[1])

    def get_operation(self):
        cp = self.get_register(self.REG_CP)
        value = self.get_data_form_mem(cp, 1)
        val = value[0]
        val2 = value[1]
        val_d = int(self.convert.to_decimal(val2 + "H"))
        val_d = val_d & 12
        value = val + self.convert.decimal_to_hexadecimal(str(val_d))[:-1]
        tip = "Error"
        op = self.operations_1.get(value, "Error")
        if not op == "Error":
            tip = "1"
        else:
            op = self.operations_2.get(value, "Error")
            if not op == "Error":
                tip = "2"
            else:
                op = self.operations_3.get(value, "Error")
                if not op == "Error":
                    tip = "3"
        return [value, op, tip]

    ##regresa los datos de una localidad y las licalidades
    #siguientes
    # @param localidad  donde se obtendra el dato
    # @param num_loc cuantas localidades siguientes accedera
    def get_data_form_mem(self, location, num_loc):
        loc = self.register.filter_number(location)
        row = self.get_row_index(loc)
        col = self.get_column_index(loc)
        data = ""
        it = col
        count = 0
        while count < num_loc:
            item = self.window.tableWidget.item(row, it)
            data += str(item.text())
            it = (it + 1) % 17
            if it == 0:
                it = 1
                row += 1
            count += 1
        return data

    def get_row_index(self, value):
        index = str(value[0:-1]) + "0"
        it = 0
        index = self.register.adjust_bytes(index, 6, False)
        num_rows = self.window.tableWidget.rowCount()
        while it < num_rows:
            val = self.window.tableWidget.item(it, 0)
            if str(val.text()) == index:
                return it
            it += 1
        return 0

    def get_column_index(self, value):
        index = str(value[-1]) + "H"
        index = self.convert.to_decimal(index)
        return index + 1

    def get_m_type3(self):
        cp = self.get_register(self.REG_CP)
        data1 = self.get_data_form_mem(cp, 1)
        type_d = self.get_operation_type(data1)
        next_loc = self.hexa.plus(cp, "1H")
        data = self.get_data_form_mem(next_loc, 1)
        print data1, type_d, next_loc, data
        msb = data[0]
        msb_d = int(self.convert.to_decimal(msb + "H"))
        tam = 3
        if (msb_d & 1) == 1:
            tam = 4
        next_loc = self.hexa.plus(next_loc, "1H")
        m = data[1] + self.get_data_form_mem(next_loc, tam - 2)
        print m, tam, next_loc
        cp = self.get_register(self.REG_CP)
        cp = self.hexa.plus(cp, str(tam))
        self.set_register(self.REG_CP, cp)
        if type_d == "simple_s":
            m = str(msb_d & 7) + m
            type_d = "simple"
        elif (msb_d & 6) == 0:
            m = m
        else:
            if (msb_d & 4) == 4:
                b = self.get_register(self.REG_B)
                m = self.hexa.change_hexadecimal(m)
                print "rel base", b, m
                m = self.hexa.suma(m, b)
            if (msb_d & 2) == 2:
                cp = self.get_register(self.REG_CP)
                m = self.hexa.change_hexadecimal(m)
                print "rel cp", cp, m
                m = self.hexa.suma(m, cp)
        if (msb_d & 8) == 8:
            x = self.get_register(self.REG_X)
            m = self.hexa.change_hexadecimal(m)
            print ", X", x, m
            m = self.hexa.suma(m, x)
        print "mem", m
        if not type_d == "inmediato":
            m = self.register.adjust_bytes(m, 6, False)
            m = self.get_data_form_mem(m, 3)
            if not type_d == "simple":
                m = self.register.adjust_bytes(m, 6, False)
                m = self.get_data_form_mem(m, 3)
        print "return", m
        return m

    def get_m_type3_m(self):
        cp = self.get_register(self.REG_CP)
        data1 = self.get_data_form_mem(cp, 1)
        type_d = self.get_operation_type(data1)
        next_loc = self.hexa.plus(cp, "1H")
        data = self.get_data_form_mem(next_loc, 1)
        print data1, type_d, next_loc, data
        msb = data[0]
        msb_d = int(self.convert.to_decimal(msb + "H"))
        tam = 3
        if (msb_d & 1) == 1:
            tam = 4
        next_loc = self.hexa.plus(next_loc, "1H")
        m = data[1] + self.get_data_form_mem(next_loc, tam - 2)
        print m, tam, next_loc
        cp = self.get_register(self.REG_CP)
        cp = self.hexa.plus(cp, str(tam))
        self.set_register(self.REG_CP, cp)
        if type_d == "simple_s":
            m = str(msb_d & 7) + m
            type_d = "simple"
        elif (msb_d & 6) == 0:
            m = m
        else:
            if (msb_d & 4) == 4:
                b = self.get_register(self.REG_B)
                m = self.hexa.change_hexadecimal(m)
                print "rel base", b, m
                m = self.hexa.suma(m, b)
            if (msb_d & 2) == 2:
                cp = self.get_register(self.REG_CP)
                m = self.hexa.change_hexadecimal(m)
                print "rel cp", cp, m
                m = self.hexa.suma(m, cp)
        if (msb_d & 8) == 8:
            x = self.get_register(self.REG_X)
            m = self.hexa.change_hexadecimal(m)
            print ", X", x, m
            m = self.hexa.suma(m, x)
        print "mem", m
        # if not type_d == "inmediato":
        # 	m = self.register.adjust_bytes(m,6,False)
        # 	m = self.get_data_form_mem(m,3)
        # 	if not type_d == "simple":
        # 		m = self.register.adjust_bytes(m,6,False)
        # 		m = self.get_data_form_mem(m,3)
        # print "return",m
        return m

    def get_operation_type(self, data):
        d = data[1]
        d_d = int(self.convert.to_decimal(d + "H"))
        val = d_d & 3
        if val == 3:
            return "simple"
        elif val == 2:
            return "indirecto"
        elif val == 1:
            return "inmediato"
        return "simple_s"

    def add(self, m):
        string = "ADD\nA <- (A) + (m..m+2)"
        a = self.get_register(self.REG_A)
        res = self.hexa.plus(a, m)
        string += "\n(A) = " + a + "\n(m..m+2) = " + m + "\n(A) = " + res
        self.set_register(self.REG_A, res)
        self.window.textEdit_Actions.setText(string)

    def addr(self, m):
        string = "ADDR\nr2 <- (r1) + (r2)" + "\n"
        r1 = self.registers[m[0]]
        r2 = self.registers[m[1]]
        string += "(r1) = " + r1[1] + "\n (r2) = " + r2[1] + "\n"
        dat1 = self.get_register(r1[0])
        dat2 = self.get_register(r2[0])
        res = self.hexa.plus(dat1, dat2)
        string += "(" + r2[1] + ")<-" + res
        self.set_register(r2[0], res)
        self.window.textEdit_Actions.setText(string)

    def and_op(self, m):
        string = "AND\nA <- (A) & (m..m+2)\n"
        a = self.get_register(self.REG_A)
        string += "(A) : " + a + "\n" + "(m..m+2) : " + m
        res = self.hexa.and_op(a, m)
        self.set_register(self.REG_A, res)
        self.window.textEdit_Actions.setText(string)

    def clear(self, m):
        r = self.registers[m[0]]
        string = "CLEAR\nr1 <- 0\nr1:" + r[1]
        self.set_register(r[0], "0H")
        self.window.textEdit_Actions.setText(string)

    def comp(self, m):
        string = "COMP\nCC = (A) : (m..m+2)"
        a = self.get_register(self.REG_A)
        string += "\n (A) = " + a + "\n (m..m+2) = " + m
        self.cc_val = self.hexa.cmp_op(a, m)
        string += "\nCC =" + self.cc_val
        self.window.textEdit_Actions.setText(string)

    def compr(self, m):
        r1 = self.registers[m[0]]
        r2 = self.registers[m[1]]
        dat1 = self.get_register(r1[0])
        dat2 = self.get_register(r2[0])
        string = "COMPR\nCC = r1 : r2\n" + "r1 = " + r1[1] + "\nr2 = " + r2[1]
        self.cc_val = self.hexa.cmp_op(dat1, dat2)
        string += "\n CC = " + self.cc_val
        self.window.textEdit_Actions.setText(string)

    def div(self, m):
        string = "DIV\nA <- (A) / (m..m+2)"
        a = self.get_register(self.REG_A)
        res = self.hexa.div(a, m)
        string += "\n(A) = " + a + "\n(m..m+2) = " + m + "\n(A) = " + res
        self.set_register(self.REG_A, res)
        self.window.textEdit_Actions.setText(string)

    def divr(self, m):
        r1 = self.registers[m[0]]
        r2 = self.registers[m[1]]
        dat1 = self.get_register(r1[0])
        dat2 = self.get_register(r2[0])
        string = "DIVR\nr2 <- (r2) / (r1)\nr1 = " + r1[1] + "\nr2 = " + r2[1]
        res = self.hexa.div(dat2, dat1)
        string += "r2 = " + res
        self.set_register(r2[0], res)
        self.window.textEdit_Actions.setText(string)

    def j_op(self, m):
        string = "J: \n CP <- m\nm = " + m
        self.set_register(self.REG_CP, m)
        self.window.textEdit_Actions.setText(string)

    def jeq(self, m):
        string = "JEQ: \nsi CC == '=':\n\tCP <- m\n"
        string += "CC = '" + self.cc_val + "'"
        if self.cc_val == "=":
            self.set_register(self.REG_CP, m)
            string += "\nCP <- " + m
        self.window.textEdit_Actions.setText(string)

    def jgt(self, m):
        string = "JGT: \nsi CC == '>':\n\tCP <- m\n"
        string += "CC = '" + self.cc_val + "'"
        if self.cc_val == ">":
            self.set_register(self.REG_CP, m)
            string += "\nCP <- " + m
        self.window.textEdit_Actions.setText(string)

    def jlt(self, m):
        string = "JLT: \nsi CC == '<':\n\tCP <- m\n"
        string += "CC = '" + self.cc_val + "'"
        if self.cc_val == "<":
            self.set_register(self.REG_CP, m)
            string += "\nCP <- " + m
        self.window.textEdit_Actions.setText(string)

    def jsub(self, m):
        string = "JSUB:\n L <- (CP)\nCP <- m"
        cp = self.get_register(self.REG_CP)
        string += "\n(CP) = " + cp + "\nm = " + m
        self.set_register(self.REG_L, cp)
        self.set_register(self.REG_CP, m)
        self.window.textEdit_Actions.setText(string)

    def lda(self, m):
        string = "LDA\nA <- (m..m+2)\n(m..m+2) = " + m
        self.set_register(self.REG_A, m)
        self.window.textEdit_Actions.setText(string)

    def ldb(self, m):
        string = "LDB\nB <- (m..m+2)\n(m..m+2) = " + m
        self.set_register(self.REG_B, m)
        self.window.textEdit_Actions.setText(string)

    def ldch(self, m):
        string = "LDCH\nA[+der] <- (m)"
        a = self.get_register(self.REG_A)
        m = self.register.adjust_bytes(m, 6, False)
        m = self.get_data_form_mem(m, 1)
        string += "\n(A) = " + a + "\n(m) = " + m
        a = self.register.filter_number(a)
        a = a[0:-2] + m
        self.set_register(self.REG_A, a)
        self.window.textEdit_Actions.setText(string)

    def ldl(self, m):
        string = "LDL\nL <- (m..m+2)\n(m..m+2) = " + m
        self.set_register(self.REG_L, m)
        self.window.textEdit_Actions.setText(string)

    def lds(self, m):
        string = "LDS\nS <- (m..m+2)\n(m..m+2) = " + m
        self.set_register(self.REG_S, m)
        self.window.textEdit_Actions.setText(string)

    def ldt(self, m):
        string = "LDT\nT <- (m..m+2)\n(m..m+2) = " + m
        self.set_register(self.REG_T, m)
        self.window.textEdit_Actions.setText(string)

    def ldx(self, m):
        string = "LDX\nX <- (m..m+2)\n(m..m+2) = " + m
        self.set_register(self.REG_X, m)
        self.window.textEdit_Actions.setText(string)

    def mul(self, m):
        a = self.get_register(self.REG_A)
        string = "MUL\nA <- (A) * (m..m+2)\n(A) = " + a + "\n(m..m+2)=" + m
        res = self.hexa.mul(a, m)
        string += "\n (A) <- " + res
        self.set_register(self.REG_A, res)
        self.window.textEdit_Actions.setText(string)

    def mulr(self, m):
        r1 = self.registers[m[0]]
        r2 = self.registers[m[1]]
        dat1 = self.get_register(r1[0])
        dat2 = self.get_register(r2[0])
        string = "MULR\nr2 <- (r2) * (r1)\nr1 = " + r1[1] + "\nr2 = " + r2[1]
        res = self.hexa.mul(dat2, dat1)
        string += "r2 = " + res
        self.set_register(r2[0], res)
        self.window.textEdit_Actions.setText(string)

    def or_op(self, m):
        string = "OR\nA <- (A) | (m..m+2)\n"
        a = self.get_register(self.REG_A)
        string += "(A) : " + a + "\n" + "(m..m+2) : " + m
        res = self.hexa.or_op(a, m)
        self.set_register(self.REG_A, res)
        self.window.textEdit_Actions.setText(string)

    def rmo(self, m):
        r1 = self.registers[m[0]]
        r2 = self.registers[m[1]]
        dat1 = self.get_register(r1[0])
        string = "RMO\nr2 <- (r1)\n r1 = " + r1[1] + "\nr2 =" + r2[1]
        string += "\nr2 <- " + dat1
        self.set_register(r2[0], dat1)
        self.window.textEdit_Actions.setText(string)

    def rsub(self, m):
        l = self.get_register(self.REG_L)
        string = "RSUB\nCP <- (L)\n(L) = " + l
        string += "CP <-" + l
        self.set_register(self.REG_CP, l)
        self.window.textEdit_Actions.setText(string)

    def sta(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_A)
        string = "STA\n m..m+2 <- (A)\nm..m+2 = " + m + "\n(A) = " + reg
        reg = self.register.filter_number(reg)
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def sta(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_A)
        string = "STA\n m..m+2 <- (A)\nm..m+2 = " + m + "\n(A) = " + reg
        reg = self.register.filter_number(reg)
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def stb(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_B)
        string = "STB\n m..m+2 <- (B)\nm..m+2 = " + m + "\n(B) = " + reg
        reg = self.register.filter_number(reg)
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def stch(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_A)
        reg = self.register.filter_number(reg)[-2:]
        string = "STCH\n m <- (A)[+der]\nm..m+2 = " + m + "\n(A)[+der] = " + reg
        ##S rm = self.hexa.plus(m,"2H")
        m = self.register.adjust_bytes(m, 6, False)
        print "stsh", reg, m
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def stl(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_L)
        string = "STL\n m..m+2 <- (L)\nm..m+2 = " + m + "\n(L) = " + reg
        reg = self.register.filter_number(reg)
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def sts(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_S)
        string = "STS\n m..m+2 <- (S)\nm..m+2 = " + m + "\n(S) = " + reg
        reg = self.register.filter_number(reg)
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def stsw(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_SW)
        string = "STSW\n m..m+2 <- (SW)\nm..m+2 = " + m + "\n(SW) = " + reg
        reg = self.register.filter_number(reg)
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def stt(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_T)
        string = "STT\n m..m+2 <- (T)\nm..m+2 = " + m + "\n(T) = " + reg
        reg = self.register.filter_number(reg)
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def stx(self, m):
        m = self.register.adjust_bytes(m, 6, False)
        reg = self.get_register(self.REG_X)
        string = "STX\n m..m+2 <- (X)\nm..m+2 = " + m + "\n(X) = " + reg
        reg = self.register.filter_number(reg)
        self.modf_reg(reg, m)
        self.window.textEdit_Actions.setText(string)

    def modf_reg(self, reg, m):
        row = self.get_row_index(m)
        col = self.get_column_index(m)
        it = col
        count = 0
        while count < len(reg):
            item = self.window.tableWidget.item(row, it)
            text = reg[count:count + 2]
            count += 2
            item.setText(text)
            it = (it + 1) % 17
            if it == 0:
                it = 1
                row += 1

    def sub(self, m):
        string = "ADD\nA <- (A) - (m..m+2)"
        a = self.get_register(self.REG_A)
        res = self.hexa.subs(a, m)
        string += "\n(A) = " + a + "\n(m..m+2) = " + m + "\n(A) = " + res
        self.set_register(self.REG_A, res)
        self.window.textEdit_Actions.setText(string)

    def subr(self, m):
        r1 = self.registers[m[0]]
        r2 = self.registers[m[1]]
        dat1 = self.get_register(r1[0])
        dat2 = self.get_register(r2[0])
        string = "SUBR\nr2 <- (r2) - (r1)\nr1 = " + r1[1] + "\nr2 = " + r2[1]
        res = self.hexa.subs(dat2, dat1)
        string += "r2 = " + res
        self.set_register(r2[0], res)
        self.window.textEdit_Actions.setText(string)

    def tix(self, m):
        x = self.get_register(self.REG_X)
        string = "TIX\n(X) <- (X) + 1\n(X) : (m..m+2)\n(X)=" + x
        x = self.hexa.plus(x, "1H")
        self.set_register(self.REG_X, x)
        string += "\n(X)<- (X) + 1\n(X) <- " + x + "\n(m..m+2)=" + m
        self.cc_val = self.hexa.cmp_op(x, m)
        string += "\nCC = " + self.cc_val
        self.window.textEdit_Actions.setText(string)

    def tixr(self, m):
        r1 = self.registers[m[0]]
        dat1 = self.get_register(r1[0])
        string = "TIX\n X <- (X) + 1\n(X) : (r1)\nr1 = " + r1[1]
        x = self.get_register(self.REG_X)
        x = self.hexa.plus(x, "1H")
        self.set_register(self.REG_X, x)
        self.cc_val = self.hexa.cmp_op(x, dat1)
        string += "CC = " + self.cc_val
        self.window.textEdit_Actions.setText(string)
コード例 #21
0
ファイル: simuladorx.py プロジェクト: Juanirow/esic
class Simuladorx(QtGui.QDockWidget):
	REG_CP = 0
	REG_A = 1
	REG_X = 2
	REG_L = 3
	REG_SW = 4
	REG_B = 5
	REG_S = 6
	REG_T = 7
	REG_F = 8

	def __init__(self,parent=None):
		QtGui.QWidget.__init__(self)
		self.window = Ui_DockWidget()
		self.window.setupUi(self)
		self.add_registers()
		self.cargador = None
		self.hexa = Hexadecimal()
		self.convert = Convert()
		self.register = Register("A")
		self.init_registers()
		self.end_program = "0H"
		self.cc_val = "="
		self.window.btnSimular.clicked.connect(self.simular)
		self.operations_3 = {"18":"ADD","00":"LDA","40":"AND","28":"COMP","24":"DIV","3C":"J","30":"JEQ","34":"JGT","38":"JLT",
                           "48":"JSUB","50":"LDCH","08":"LDL","04":"LDX","20":"MUL","4C":"RSUB","0C":"STA","54":"STCH","14":"STL",
                           "E8":"STSW","10":"STX","1C":"SUB","2C":"TIX","58":"ADDF","88":"COMPF","64":"DIVF","68":"LDB","70":"LDF",
                           "6C":"LDS","74":"LDT","D0":"LPS","60":"MULF","EC":"SSK","78":"STB","80":"STF","D4":"STI","7C":"STS","E8":"STSW",
                           "84":"STT","5C":"SUBF","E0":"TD","DC":"WD","44":"OR"}
		self.operations_1 = {"C4":"FIX","C0":"FLOAT","F4":"HIO","C8":"NORM","F0":"SIO","F8":"TIO"}
		self.operations_2 = {"90":"ADDR","B4":"CLEAR","A0":"COMPR","9C":"DIVR","98":"MULR","AC":"RMO","A4":"SHIFTL","A8":"SHIFTR",
							"94":"SUBR","B0":"SVC","B8":"TIXR"}
		self.operations = {"18":self.add,"00":self.lda,"40":self.and_op,"28":self.comp,"24":self.div,"3C":self.j_op,
							"30":self.jeq,"34":self.jgt,"38":self.jlt,"48":self.jsub,"50":self.ldch,
							"08":self.ldl,"04":self.ldx,"20":self.mul,"4C":self.rsub,"0C":self.sta,"54":self.stch,"14":self.stl,
                           "E8":self.stsw,"10":self.stx,"1C":self.sub,"2C":self.tix,"58":self.float_operations,
                           "88":self.float_operations,
                           "64":self.float_operations,"68":self.ldb,"70":self.float_operations,"6C":self.lds,"74":self.ldt,
                           "D0":self.system_operations,"60":self.float_operations,"EC":self.system_operations,"78":self.stb,
                           "80":self.float_operations,"D4":self.system_operations,"7C":self.sts,"E8":self.system_operations,
                           "84":self.stt,"5C":self.float_operations,"E0":self.system_operations,"DC":self.system_operations,
                           "C4":self.float_operations,
                           "C0":self.float_operations,"F4":self.system_operations,"C8":self.float_operations,
                           "F0":self.system_operations,"44":self.or_op,
                           "F8":self.system_operations,"90":self.addr,"B4":self.clear,"A0":self.compr,
                           "9C":self.divr,"98":self.mulr,"AC":self.rmo,"A4":"SHIFTL",
                           "A8":"SHIFTR","94":self.subr,"B0":"SVC","B8":self.tixr}
		self.registers = {"0":[self.REG_A,"A"],"1":[self.REG_X,"X"],"2":[self.REG_L,"L"],"8":[self.REG_CP,"CP"],"9":[self.REG_SW,"SW"],"3":[self.REG_B,"B"],
       				"4":[self.REG_S,"S"],"5":[self.REG_T,"T"],"6":[self.REG_F,"F"]}
		self.operations_m = ["J","JLT","JEQ","JGT","JSUB","STA","STB","STCH","STL","STS","STSW","STT","STX","LDCH"]

	def simular(self):
		num_actions = self.get_count_next_actions()
		print "num actions",num_actions
		if num_actions == -1:
			self.window.textEdit_Actions.setText("Numero de simulaciones no Validas")
		else:
			self.make_n_simulations(num_actions)

	def make_n_simulations(self,number):
		it = 0
		while it < number:
			cp = self.get_register(self.REG_CP)
			if self.hexa.minus_than(cp,self.end_program):
				op = self.get_operation()
				type_op = op[2]
				inst = op[1]
				m = self.get_m(type_op,cp,inst)
				if m == "Error":
					self.window.textEdit_Actions.setText("El programa se termino debido a un error de operacion")
				else:
					fun = self.operations[op[0]]
					fun(m)
					self.show_next_instr()
			else:
				self.window.textEdit_Actions.setText("El programa se termino")
			it += 1

	def get_m(self,type_op,cp,inst):
		if type_op == "Error":
			return type_op
		if type_op == "1":
			self.increment_cp(1)
			return "0"
		if type_op == "2":
			cp_n = self.hexa.plus(cp,"1H")
			self.increment_cp(2)
			return self.get_data_form_mem(cp_n,1)
		if inst in self.operations_m:
			print "\n\n"+inst+"\n\n"
			return self.get_m_type3_m()
		return self.get_m_type3()

	def get_count_next_actions(self):
		count_actions = str(self.window.textEdit_Num.toPlainText())
		if count_actions == "":
			count_actions = 1
		elif not count_actions.isdigit():
			return -1
		return int(count_actions)

 	def system_operations(self,val):
 		self.window.textEdit_Actions.setText("No tiene los permisos \n para ejecutar esta instruccion")

	def float_operations(self,val):
 		self.window.textEdit_Actions.setText("Las instrucciones flotantes \n no se pueden ejecutar")

	def add_registers(self):
		self.window.tableWidget_2.setRowCount(9)
		item = QtGui.QTableWidgetItem()
		item.setText("B")
		self.window.tableWidget_2.setVerticalHeaderItem(5, item)
		item = QtGui.QTableWidgetItem()
		item.setText("S")
		self.window.tableWidget_2.setVerticalHeaderItem(6, item)
		item = QtGui.QTableWidgetItem()
		item.setText("T")
		self.window.tableWidget_2.setVerticalHeaderItem(7, item)
		item = QtGui.QTableWidgetItem()
		item.setText("F")
		self.window.tableWidget_2.setVerticalHeaderItem(8, item)

	def init_registers(self):
		it = 0
		while it < 9:
			item_text = QtGui.QTableWidgetItem("FFFFFFFH")
			self.window.tableWidget_2.setItem(it,0,item_text)
			it += 1

	def set_register(self,reg_num,val):
		val_hex = self.register.adjust_bytes(val,6,False)
		val_hex = self.hexa.change_hexadecimal(val_hex)
		item_text = QtGui.QTableWidgetItem(val_hex)
		self.window.tableWidget_2.setItem(reg_num,0,item_text)

	def get_register(self,reg_num):
		item = self.window.tableWidget_2.item(reg_num,0)
		return str(item.text())

	def carga(self,list_obj,dirprog):
		self.cargador = Cargadorx(self.window)
		self.cargador.load_file_name(list_obj,dirprog)
		cp = self.cargador.direj
		self.set_register(self.REG_CP,cp)
		self.show_next_instr()
		self.end_program = self.cargador.dirsc
		if self.cargador.error_duplicado:
			QtGui.QMessageBox.about(self,"Error","Error simbolo duplicado")
		elif self.cargador.error_indefinido:
			QtGui.QMessageBox.about(self,"Error","Error simbolo indefinido")


	def increment_cp(self,num):
		num_hexa = self.convert.decimal_to_hexadecimal(num)
		cp = self.get_register(self.REG_CP)
		res = self.hexa.plus(num_hexa,cp)
		self.set_register(self.REG_CP,res)

	def show_next_instr(self):
		op = self.get_operation()
		self.window.label_sig.setText(op[1])
	
	def get_operation(self):
		cp = self.get_register(self.REG_CP)
		value = self.get_data_form_mem(cp,1)
		val = value[0]
		val2 = value[1]
		val_d = int(self.convert.to_decimal(val2+"H"))
		val_d = val_d & 12
		value = val + self.convert.decimal_to_hexadecimal(str(val_d))[:-1]
		tip = "Error"
		op = self.operations_1.get(value,"Error")
		if not op == "Error":
			tip = "1"
		else:
			op = self.operations_2.get(value,"Error")
			if not op == "Error":
				tip = "2"
			else:
				op = self.operations_3.get(value,"Error")
				if not op == "Error":
					tip = "3"
		return [value,op,tip]
		
	##regresa los datos de una localidad y las licalidades 
	#siguientes 
	# @param localidad  donde se obtendra el dato
	# @param num_loc cuantas localidades siguientes accedera 
	def get_data_form_mem(self,location,num_loc):
		loc = self.register.filter_number(location)
		row = self.get_row_index(loc)
		col = self.get_column_index(loc)
		data = ""
		it = col
		count = 0
		while count < num_loc:
			item = self.window.tableWidget.item(row,it)
			data += str(item.text())
			it = (it+1)%17
			if it == 0:
				it = 1
				row+=1
			count += 1
		return data

	def get_row_index(self,value):
		index = str(value[0:-1])+"0"
		it = 0
		index = self.register.adjust_bytes(index,6,False)
		num_rows = self.window.tableWidget.rowCount()
		while it < num_rows:
			val = self.window.tableWidget.item(it,0)
			if str(val.text()) == index:
				return it
			it += 1
		return 0
        
	def get_column_index(self,value):
		index = str(value[-1])+"H"
		index = self.convert.to_decimal(index)
		return index+1

	def get_m_type3(self):
		cp = self.get_register(self.REG_CP)
		data1 = self.get_data_form_mem(cp,1)
		type_d = self.get_operation_type(data1)
		next_loc = self.hexa.plus(cp,"1H")
		data = self.get_data_form_mem(next_loc,1)
		print data1,type_d,next_loc,data
		msb = data[0]
		msb_d = int(self.convert.to_decimal(msb+"H"))
		tam = 3
		if (msb_d & 1) == 1:
			tam = 4
		next_loc = self.hexa.plus(next_loc,"1H")
		m = data[1] + self.get_data_form_mem(next_loc,tam-2)
		print m,tam,next_loc
		cp = self.get_register(self.REG_CP)
		cp = self.hexa.plus(cp,str(tam))
		self.set_register(self.REG_CP,cp)
		if type_d == "simple_s":
			m = str(msb_d & 7) + m
			type_d = "simple"
		elif (msb_d & 6) == 0:
			m = m
		else:
			if (msb_d & 4) == 4:
				b = self.get_register(self.REG_B)
				m = self.hexa.change_hexadecimal(m)
				print "rel base",b,m
				m = self.hexa.suma(m,b)
			if (msb_d & 2) == 2:
				cp = self.get_register(self.REG_CP)
				m = self.hexa.change_hexadecimal(m)
				print "rel cp",cp,m
				m = self.hexa.suma(m,cp)
		if (msb_d & 8) == 8:
			x = self.get_register(self.REG_X)
			m = self.hexa.change_hexadecimal(m)
			print ", X",x,m
			m = self.hexa.suma(m,x)
		print "mem",m
		if not type_d == "inmediato":
			m = self.register.adjust_bytes(m,6,False)
			m = self.get_data_form_mem(m,3)
			if not type_d == "simple":
				m = self.register.adjust_bytes(m,6,False)
				m = self.get_data_form_mem(m,3)
		print "return",m
		return m

	def get_m_type3_m(self):
		cp = self.get_register(self.REG_CP)
		data1 = self.get_data_form_mem(cp,1)
		type_d = self.get_operation_type(data1)
		next_loc = self.hexa.plus(cp,"1H")
		data = self.get_data_form_mem(next_loc,1)
		print data1,type_d,next_loc,data
		msb = data[0]
		msb_d = int(self.convert.to_decimal(msb+"H"))
		tam = 3
		if (msb_d & 1) == 1:
			tam = 4
		next_loc = self.hexa.plus(next_loc,"1H")
		m = data[1] + self.get_data_form_mem(next_loc,tam-2)
		print m,tam,next_loc
		cp = self.get_register(self.REG_CP)
		cp = self.hexa.plus(cp,str(tam))
		self.set_register(self.REG_CP,cp)
		if type_d == "simple_s":
			m = str(msb_d & 7) + m
			type_d = "simple"
		elif (msb_d & 6) == 0:
			m = m
		else:
			if (msb_d & 4) == 4:
				b = self.get_register(self.REG_B)
				m = self.hexa.change_hexadecimal(m)
				print "rel base",b,m
				m = self.hexa.suma(m,b)
			if (msb_d & 2) == 2:
				cp = self.get_register(self.REG_CP)
				m = self.hexa.change_hexadecimal(m)
				print "rel cp",cp,m
				m = self.hexa.suma(m,cp)
		if (msb_d & 8) == 8:
			x = self.get_register(self.REG_X)
			m = self.hexa.change_hexadecimal(m)
			print ", X",x,m
			m = self.hexa.suma(m,x)
		print "mem",m
		# if not type_d == "inmediato":
		# 	m = self.register.adjust_bytes(m,6,False)
		# 	m = self.get_data_form_mem(m,3)
		# 	if not type_d == "simple":
		# 		m = self.register.adjust_bytes(m,6,False)
		# 		m = self.get_data_form_mem(m,3)
		# print "return",m
		return m
		
	def get_operation_type(self,data):
		d = data[1]
		d_d = int(self.convert.to_decimal(d+"H"))
		val = d_d & 3
		if val == 3:
			return "simple"
		elif val == 2:
			return "indirecto"
		elif val == 1:
			return "inmediato"
		return "simple_s"

	def add(self,m):
		string = "ADD\nA <- (A) + (m..m+2)"
		a = self.get_register(self.REG_A)
		res = self.hexa.plus(a,m)
		string += "\n(A) = "+a+"\n(m..m+2) = "+m+"\n(A) = "+res
		self.set_register(self.REG_A,res)
		self.window.textEdit_Actions.setText(string)

	def addr(self,m):
		string ="ADDR\nr2 <- (r1) + (r2)"+"\n"
		r1 = self.registers[m[0]]
		r2 = self.registers[m[1]]
		string += "(r1) = "+r1[1]+"\n (r2) = "+r2[1]+"\n"
		dat1 = self.get_register(r1[0])
		dat2 = self.get_register(r2[0])
		res = self.hexa.plus(dat1,dat2)
		string += "("+r2[1]+")<-"+res
		self.set_register(r2[0],res)
		self.window.textEdit_Actions.setText(string)

	def and_op(self,m):
		string = "AND\nA <- (A) & (m..m+2)\n"
		a = self.get_register(self.REG_A)
		string += "(A) : " + a +"\n" +"(m..m+2) : "+m
		res = self.hexa.and_op(a,m)
		self.set_register(self.REG_A,res)
		self.window.textEdit_Actions.setText(string)

	def clear(self,m):
		r = self.registers[m[0]]
		string = "CLEAR\nr1 <- 0\nr1:"+r[1]
		self.set_register(r[0],"0H") 
		self.window.textEdit_Actions.setText(string)

	def comp(self,m):
		string = "COMP\nCC = (A) : (m..m+2)"
		a = self.get_register(self.REG_A)
		string += "\n (A) = "+a+"\n (m..m+2) = "+m
		self.cc_val = self.hexa.cmp_op(a,m)
		string += "\nCC ="+self.cc_val
		self.window.textEdit_Actions.setText(string)

	def compr(self,m):
		r1 = self.registers[m[0]]
		r2 = self.registers[m[1]]
		dat1 = self.get_register(r1[0])
		dat2 = self.get_register(r2[0])
		string = "COMPR\nCC = r1 : r2\n"+"r1 = "+r1[1]+"\nr2 = "+r2[1]
		self.cc_val = self.hexa.cmp_op(dat1,dat2)
		string += "\n CC = "+self.cc_val
		self.window.textEdit_Actions.setText(string)

	def div(self,m):
		string = "DIV\nA <- (A) / (m..m+2)"
		a = self.get_register(self.REG_A)
		res = self.hexa.div(a,m)
		string += "\n(A) = "+a+"\n(m..m+2) = "+m+"\n(A) = "+res
		self.set_register(self.REG_A,res)
		self.window.textEdit_Actions.setText(string)

	def divr(self,m):
		r1 = self.registers[m[0]]
		r2 = self.registers[m[1]]
		dat1 = self.get_register(r1[0])
		dat2 = self.get_register(r2[0])
		string = "DIVR\nr2 <- (r2) / (r1)\nr1 = "+r1[1] +"\nr2 = "+r2[1]
		res = self.hexa.div(dat2,dat1)
		string += "r2 = "+res
		self.set_register(r2[0],res)
		self.window.textEdit_Actions.setText(string)

	def j_op(self,m):
		string = "J: \n CP <- m\nm = "+m
		self.set_register(self.REG_CP,m)
		self.window.textEdit_Actions.setText(string)

	def jeq(self,m):
		string = "JEQ: \nsi CC == '=':\n\tCP <- m\n"
		string += "CC = '"+self.cc_val+"'"
		if self.cc_val == "=":
			self.set_register(self.REG_CP,m)
			string += "\nCP <- "+m
		self.window.textEdit_Actions.setText(string)

	def jgt(self,m):
		string = "JGT: \nsi CC == '>':\n\tCP <- m\n"
		string += "CC = '"+self.cc_val+"'"
		if self.cc_val == ">":
			self.set_register(self.REG_CP,m)
			string += "\nCP <- "+m
		self.window.textEdit_Actions.setText(string)

	def jlt(self,m):
		string = "JLT: \nsi CC == '<':\n\tCP <- m\n"
		string += "CC = '"+self.cc_val+"'"
		if self.cc_val == "<":
			self.set_register(self.REG_CP,m)
			string += "\nCP <- "+m
		self.window.textEdit_Actions.setText(string)

	def jsub(self,m):
		string = "JSUB:\n L <- (CP)\nCP <- m"
		cp = self.get_register(self.REG_CP)
		string += "\n(CP) = "+cp+"\nm = "+m
		self.set_register(self.REG_L,cp)
		self.set_register(self.REG_CP,m)
		self.window.textEdit_Actions.setText(string)

	def lda(self,m):
		string = "LDA\nA <- (m..m+2)\n(m..m+2) = "+m
		self.set_register(self.REG_A,m)
		self.window.textEdit_Actions.setText(string)

	def ldb(self,m):
		string = "LDB\nB <- (m..m+2)\n(m..m+2) = "+m
		self.set_register(self.REG_B,m)
		self.window.textEdit_Actions.setText(string)

	def ldch(self,m):
		string = "LDCH\nA[+der] <- (m)"
		a = self.get_register(self.REG_A)
		m = self.register.adjust_bytes(m,6,False)
		m = self.get_data_form_mem(m,1)
		string += "\n(A) = "+a+"\n(m) = "+m
		a = self.register.filter_number(a)
		a = a[0:-2] + m
		self.set_register(self.REG_A,a)
		self.window.textEdit_Actions.setText(string)

	def ldl(self,m):
		string = "LDL\nL <- (m..m+2)\n(m..m+2) = "+m
		self.set_register(self.REG_L,m)
		self.window.textEdit_Actions.setText(string)

	def lds(self,m):
		string = "LDS\nS <- (m..m+2)\n(m..m+2) = "+m
		self.set_register(self.REG_S,m)
		self.window.textEdit_Actions.setText(string)

	def ldt(self,m):
		string = "LDT\nT <- (m..m+2)\n(m..m+2) = "+m
		self.set_register(self.REG_T,m)
		self.window.textEdit_Actions.setText(string)

	def ldx(self,m):
		string = "LDX\nX <- (m..m+2)\n(m..m+2) = "+m
		self.set_register(self.REG_X,m)
		self.window.textEdit_Actions.setText(string)

	def mul(self,m):
		a = self.get_register(self.REG_A)
		string = "MUL\nA <- (A) * (m..m+2)\n(A) = "+a+"\n(m..m+2)="+m
		res = self.hexa.mul(a,m)
		string += "\n (A) <- "+res
		self.set_register(self.REG_A,res)
		self.window.textEdit_Actions.setText(string)

	def mulr(self,m):
		r1 = self.registers[m[0]]
		r2 = self.registers[m[1]]
		dat1 = self.get_register(r1[0])
		dat2 = self.get_register(r2[0])
		string = "MULR\nr2 <- (r2) * (r1)\nr1 = "+r1[1] +"\nr2 = "+r2[1]
		res = self.hexa.mul(dat2,dat1)
		string += "r2 = "+res
		self.set_register(r2[0],res)
		self.window.textEdit_Actions.setText(string)

	def or_op(self,m):
		string = "OR\nA <- (A) | (m..m+2)\n"
		a = self.get_register(self.REG_A)
		string += "(A) : " + a +"\n" +"(m..m+2) : "+m
		res = self.hexa.or_op(a,m)
		self.set_register(self.REG_A,res)
		self.window.textEdit_Actions.setText(string)

	def rmo(self,m):
		r1 = self.registers[m[0]]
		r2 = self.registers[m[1]]
		dat1 = self.get_register(r1[0])
		string = "RMO\nr2 <- (r1)\n r1 = "+r1[1]+"\nr2 ="+r2[1]
		string += "\nr2 <- " + dat1
		self.set_register(r2[0],dat1)
		self.window.textEdit_Actions.setText(string)

	def rsub(self,m):
		l = self.get_register(self.REG_L)		
		string = "RSUB\nCP <- (L)\n(L) = "+l
		string += "CP <-"+l
		self.set_register(self.REG_CP,l)
		self.window.textEdit_Actions.setText(string)

	def sta(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_A)
		string = "STA\n m..m+2 <- (A)\nm..m+2 = "+m+"\n(A) = "+reg
		reg = self.register.filter_number(reg)
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def sta(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_A)
		string = "STA\n m..m+2 <- (A)\nm..m+2 = "+m+"\n(A) = "+reg
		reg = self.register.filter_number(reg)
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def stb(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_B)
		string = "STB\n m..m+2 <- (B)\nm..m+2 = "+m+"\n(B) = "+reg
		reg = self.register.filter_number(reg)
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def stch(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_A)
		reg = self.register.filter_number(reg)[-2:]
		string = "STCH\n m <- (A)[+der]\nm..m+2 = "+m+"\n(A)[+der] = "+reg
		##S rm = self.hexa.plus(m,"2H")
		m = self.register.adjust_bytes(m,6,False)
		print "stsh",reg,m
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def stl(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_L)
		string = "STL\n m..m+2 <- (L)\nm..m+2 = "+m+"\n(L) = "+reg
		reg = self.register.filter_number(reg)
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def sts(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_S)
		string = "STS\n m..m+2 <- (S)\nm..m+2 = "+m+"\n(S) = "+reg
		reg = self.register.filter_number(reg)
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def stsw(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_SW)
		string = "STSW\n m..m+2 <- (SW)\nm..m+2 = "+m+"\n(SW) = "+reg
		reg = self.register.filter_number(reg)
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def stt(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_T)
		string = "STT\n m..m+2 <- (T)\nm..m+2 = "+m+"\n(T) = "+reg
		reg = self.register.filter_number(reg)
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def stx(self,m):
		m = self.register.adjust_bytes(m,6,False)
		reg = self.get_register(self.REG_X)
		string = "STX\n m..m+2 <- (X)\nm..m+2 = "+m+"\n(X) = "+reg
		reg = self.register.filter_number(reg)
		self.modf_reg(reg,m)
		self.window.textEdit_Actions.setText(string)

	def modf_reg(self,reg,m):
		row = self.get_row_index(m)
		col = self.get_column_index(m)
		it = col
		count = 0
		while count < len(reg):
			item = self.window.tableWidget.item(row,it)
			text = reg[count:count+2]
			count += 2
			item.setText(text)
			it = (it+1)%17
			if it == 0:
				it = 1
				row+=1

	def sub(self,m):
		string = "ADD\nA <- (A) - (m..m+2)"
		a = self.get_register(self.REG_A)
		res = self.hexa.subs(a,m)
		string += "\n(A) = "+a+"\n(m..m+2) = "+m+"\n(A) = "+res
		self.set_register(self.REG_A,res)
		self.window.textEdit_Actions.setText(string)

	def subr(self,m):
		r1 = self.registers[m[0]]
		r2 = self.registers[m[1]]
		dat1 = self.get_register(r1[0])
		dat2 = self.get_register(r2[0])
		string = "SUBR\nr2 <- (r2) - (r1)\nr1 = "+r1[1] +"\nr2 = "+r2[1]
		res = self.hexa.subs(dat2,dat1)
		string += "r2 = "+res
		self.set_register(r2[0],res)
		self.window.textEdit_Actions.setText(string)

	def tix(self,m):
		x = self.get_register(self.REG_X)
		string ="TIX\n(X) <- (X) + 1\n(X) : (m..m+2)\n(X)="+x
		x = self.hexa.plus(x,"1H")
		self.set_register(self.REG_X,x)
		string +="\n(X)<- (X) + 1\n(X) <- "+x+"\n(m..m+2)="+m
		self.cc_val = self.hexa.cmp_op(x,m)
		string += "\nCC = "+self.cc_val
		self.window.textEdit_Actions.setText(string)

	def tixr(self,m):
		r1 = self.registers[m[0]]
		dat1 = self.get_register(r1[0])
		string = "TIX\n X <- (X) + 1\n(X) : (r1)\nr1 = "+r1[1]
		x = self.get_register(self.REG_X)
		x = self.hexa.plus(x,"1H")
		self.set_register(self.REG_X,x)
		self.cc_val = self.hexa.cmp_op(x,dat1)
		string += "CC = "+self.cc_val
		self.window.textEdit_Actions.setText(string)
コード例 #22
0
ファイル: Cargador.py プロジェクト: juanirow/esic
 def increment_cp(self, num):
     c = Convert()
     num = c.decimal_to_hexadecimal(num)
     cp = self.get_CP_value()
     cp = self.hex.plus(cp, num)
     self.set_cp_value(cp)