reset flags in interpreter

fix at least part of the problem why comparisons dont work
This commit is contained in:
Torsten 2020-03-17 10:37:35 +02:00
parent 0ed5e74748
commit e4a79aac50
2 changed files with 9 additions and 4 deletions

View File

@ -27,8 +27,7 @@ module Risc
def initialize( linker , stdout = "") def initialize( linker , stdout = "")
@stdout , @clock , @pc , @state = stdout, 0 , 0 , :stopped @stdout , @clock , @pc , @state = stdout, 0 , 0 , :stopped
@registers = {} @registers = {}
@flags = { :zero => false , :plus => false , reset_flags
:minus => false , :overflow => false }
(0...InterpreterPlatform.new.num_registers).each do |reg| (0...InterpreterPlatform.new.num_registers).each do |reg|
#set_register "r#{reg}".to_sym , "r#{reg}:unknown" #set_register "r#{reg}".to_sym , "r#{reg}:unknown"
end end
@ -48,6 +47,12 @@ module Risc
trigger(:state_changed , old , state ) trigger(:state_changed , old , state )
end end
# set all flags to false
def reset_flags
@flags = { :zero => false , :plus => false ,
:minus => false , :overflow => false }
end
def set_pc( pos ) def set_pc( pos )
raise "Not int #{pos}" unless pos.is_a? Numeric raise "Not int #{pos}" unless pos.is_a? Numeric
position = Position.at(pos) position = Position.at(pos)
@ -278,10 +283,10 @@ module Risc
end end
def execute_OperatorInstruction def execute_OperatorInstruction
reset_flags
left = get_register(@instruction.left) || 0 left = get_register(@instruction.left) || 0
rr = @instruction.right rr = @instruction.right
right = get_register(rr) || 0 right = get_register(rr) || 0
@flags[:overflow] = false
result = handle_operator(left,right) result = handle_operator(left,right)
if( result > 2**32 ) if( result > 2**32 )
@flags[:overflow] = true @flags[:overflow] = true

View File

@ -98,7 +98,7 @@ module Risc
# get the return from the message (not exit code) # get the return from the message (not exit code)
# exit code must be int # exit code must be int
def get_message_return def get_message_return
@interpreter.get_register(:r8).return_value @interpreter.get_register(:message).return_value
end end
# wrap the input so it is a main, compile and run it # wrap the input so it is a main, compile and run it