From 6a538624c54f949b11bce22d8b9f9b6e3a1d5b19 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 24 Mar 2018 17:54:15 +0200 Subject: [PATCH] remove NotSame from risc instead use a - b and then isZero --- lib/mom/instruction/not_same_check.rb | 9 ++++++--- lib/risc/instructions/branch.rb | 10 +--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/mom/instruction/not_same_check.rb b/lib/mom/instruction/not_same_check.rb index 4c758f93..3f1e22e1 100644 --- a/lib/mom/instruction/not_same_check.rb +++ b/lib/mom/instruction/not_same_check.rb @@ -6,6 +6,8 @@ module Mom # The values that are compared are defined as SlotDefinitions, ie can be anything # available to the machine through frame message or self # + # Acording to Mom::Check logic, we jump to the given label is the values are the same + # class NotSameCheck < Check attr_reader :left , :right @@ -14,12 +16,13 @@ module Mom @left , @right = left , right end - # basically move both left and right values into register and issue a - # risc comparison + # basically move both left and right values into register + # subtract them and see if IsZero comparison def to_risc(compiler) l_val = left.to_register(compiler, self) r_val = right.to_register(compiler, self) - check = Risc::NotSame.new(self, l_val.register, r_val.register, false_jump.to_risc(compiler)) + check = Risc.op( self , :- , l_val.register , r_val.register) + check << Risc::IsZero.new( self, false_jump.to_risc(compiler)) l_val << r_val << check end end diff --git a/lib/risc/instructions/branch.rb b/lib/risc/instructions/branch.rb index cb133a68..6f51b333 100644 --- a/lib/risc/instructions/branch.rb +++ b/lib/risc/instructions/branch.rb @@ -75,14 +75,6 @@ module Risc end end - # branch if two registers contain different values - class NotSame < Branch - attr_reader :left , :right - def initialize(source , left , right , label) - super(source , label) - end - end - class Unconditional < Branch end @@ -90,7 +82,7 @@ module Risc class IsZero < Branch end - class IsNotzero < Branch + class IsNotZero < Branch end class IsMinus < Branch