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

View File

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