示例#1
0
    def fhook(self, ops, vm):
        check_num_args(self.get_nm(), ops, 2, type_ins=1)
        if isinstance(ops[0], Register):
            checkEven(ops[0])
            if isinstance(ops[1], RegAddress):
                reg_number = int(ops[0].get_nm()[1:])
                curr_reg = "F" + str(reg_number + 0)
                next_reg = "F" + str(reg_number + 1)
                first_half = vm.registers[curr_reg]
                second_half = vm.registers[next_reg]
                full_b = first_half + second_half
                v = b_to_f64(full_b)
                ops[1].set_val(v)

                # deprecated code below
                # print(ops[0])
                # first_half = ops[0].get_val()
                # reg_name = "F" + str(int(ops[0].get_nm()[1:]))
                # second_half = vm.registers[reg_name]
                # full_b = first_half + second_half
                # print("full_b", full_b)
                # v = b_to_f64(full_b)
                # ops[1].set_val(v)
            else:
                InvalidArgument(ops[1].get_nm())
        else:
            raise InvalidArgument(ops[0].get_nm())
示例#2
0
def check_immediate_three(instr, ops):
    if not isinstance(ops[0], Register):
        raise InvalidArgument(ops[i].get_nm())
    else:
        if isinstance(ops[1], Register):
            if not isinstance(ops[2], IntegerTok):
                raise InvalidArgument(ops[2].get_nm())
        else:
            raise InvalidArgument(ops[1].get_nm())
示例#3
0
 def fhook(self, ops, vm):
     check_num_args(self.get_nm(), ops, 2)
     if isinstance(ops[0], Register):
         if isinstance(ops[1], RegAddress):
             ops[1].set_val(ops[0].get_val())
         else:
             InvalidArgument(ops[1].get_nm())
     else:
         raise InvalidArgument(ops[0].get_nm())
示例#4
0
 def fhook(self, ops, vm):
     check_num_args(self.get_nm(), ops, 1)
     if isinstance(ops[0], NewSymbol):
         if ops[0].get_nm() in vm.locals:
             stack_loc = hex(vm.get_sp()).split('x')[-1].upper()
             vm.stack[stack_loc] = vm.locals[ops[0].get_nm()]
             vm.inc_sp()
         else:
             raise InvalidArgument(ops[0].get_nm())
     else:
         raise InvalidArgument(ops[0].get_nm())
示例#5
0
 def fhook(self, ops, vm):
     check_num_args(self.get_nm(), ops, 1)
     if isinstance(ops[0], IntegerTok):
         try:
             stack_loc = hex(vm.get_sp()).split('x')[-1].upper()
             vm.stack[stack_loc] = ops[0].get_val()
             vm.inc_sp()
         except Exception:
             raise InvalidArgument(ops[0].get_nm())
     else:
         raise InvalidArgument(ops[0].get_nm())
示例#6
0
 def fhook(self, ops, vm):
     check_num_args(self.get_nm(), ops, 2)
     if isinstance(ops[0], Register):
         checkEven(ops[0])
         if isinstance(ops[1], RegAddress):
             # if (float(ops[0].get_val()) > float(2 ** 22)):
             #     raise TooBigForSingle(str(float(ops[0].get_val())))
             ops[1].set_val(float(ops[0].get_val()))
         else:
             InvalidArgument(ops[1].get_nm())
     else:
         raise InvalidArgument(ops[0].get_nm())
示例#7
0
 def fhook(self, ops, vm):
     check_num_args(self.get_nm(), ops, 1)
     if isinstance(ops[0], NewSymbol):
         if ops[0].get_nm() in vm.globals:
             vm.dec_sp()
             stack_loc = hex(vm.get_sp()).split('x')[-1].upper()
             vm.globals[ops[0].get_nm()] = vm.stack[stack_loc]
             vm.inc_sp()
             vm.changes.add(f'GLOBALVAR{ops[0].get_nm()}')
         else:
             raise InvalidArgument(ops[0].get_nm())
     else:
         raise InvalidArgument(ops[0].get_nm())
示例#8
0
 def fhook(self, ops, vm):
     check_num_args(self.name, ops, 1)
     if not isinstance(ops[0], Register):
         raise InvalidArgument(ops[0].get_nm())
     ops[0].set_val(vm.registers['LO'])
     vm.changes.add(ops[0].get_nm())
     return ''
示例#9
0
 def fhook(self, ops, vm):
     check_num_args(self.get_nm(), ops, 1)
     if isinstance(ops[0], NewSymbol):
         vm.locals[ops[0].get_nm()] = ops[0].get_val()
         vm.changes.add(f'LOCALVAR{ops[0].get_nm()}')
     else:
         raise InvalidArgument(ops[0].get_nm())
示例#10
0
 def fhook(self, ops, vm):
     check_num_args("BNE", ops, 3)
     disp = 0
     if isinstance(ops[2], IntegerTok):
         disp = ops[2].get_val()
     else:
         raise InvalidArgument(ops[0].get_nm())
     val_one, val_two = (0, 0)
     if isinstance(ops[0], Register):
         val_one = ops[0].get_val()
         if isinstance(ops[1], Register):
             val_two = ops[1].get_val()
         else:
             InvalidArgument(ops[1].get_nm())
     else:
         InvalidArgument(ops[0].get_nm())
     if val_one != val_two:
         current_ip = vm.get_ip()
         if current_ip + disp * 4 >= 0:
             vm.set_ip(current_ip + disp * 4)
         else:
             raise OutofBounds()
示例#11
0
    def fhook(self, ops, vm):
        check_num_args(self.get_nm(), ops, 2, type_ins=1)
        if isinstance(ops[0], Register):
            checkEven(ops[0])
            if isinstance(ops[1], RegAddress):
                bin_string = f_to_b64(ops[1].get_val())
                # split the string into two
                first_half = bin_string[:32]
                second_half = bin_string[32:]
                # since we're storing in 2 registers
                # we need to know which register comes next...
                reg_number = int(ops[0].get_nm()[1:])
                next_reg = "F" + str(reg_number + 1)

                ops[0].set_val(first_half)
                vm.registers[next_reg] = second_half
                vm.changes.add(ops[0].get_nm())
                vm.changes.add(next_reg)
            else:
                raise InvalidArgument(ops[1].get_nm())
        else:
            raise InvalidArgument(ops[0].get_nm())
示例#12
0
def check_reg_only(instr, ops):
    for i in range(0, len(ops) - 1):
        if not isinstance(ops[i], Register):
            raise InvalidArgument(ops[i].get_nm())