;
;    Mecrisp - A native code Forth implementation for MSP430 microcontrollers
;    Copyright (C) 2011  Matthias Koch
;
;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;    (at your option) any later version.
;
;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.
;
;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
;

; Vergleichsoperatoren

;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_2, "u<="
  cmp 2(r4), 0(r4)
  drop_sr
  jmp +
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_2, "u>="
  cmp @r4+, @r4
+ subc @r4, @r4
  inv @r4
  ret  

;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_2, "u>"
  cmp 2(r4), 0(r4)
  drop_sr
  jmp +
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_opcodierbar_rechenlogik, "u<"
  cmp @r4+, @r4
+ subc @r4, @r4
  ret

;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_2, "<="
  cmp 2(r4), 0(r4)
  drop_sr
  jmp +
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_2, ">="
  cmp @r4+, @r4
+ clr @r4 
  jl +
  mov #-1, @r4
+ ret
    
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_2, ">"
  cmp 2(r4), 0(r4)
  drop_sr
  jmp +
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_2, "<"
  cmp @r4+, @r4
+ clr @r4
  jge +
  mov #-1, @r4
+ ret
 
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_1, "0<"  ; Ist die Zahl negtativ ?
  xor #08000h, @r4
  bit #n, sr        ; N-Flag ist gesetzt, wenn beide Operaden negativ waren.
  subc @r4, @r4
  ret
  
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_1, "0<>"  ; Ist die Zahl nicht Null ?
  cmp #0, @r4   ; Null bleibt Null
  jz +
  mov #-1, @r4  ; Ansonsten ein sauberes -1 = True hineinlegen.
+ ret
    
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_foldable_1, "0="
  bit #-1, @r4   ; C gesetzt, wenn Ergebnis von "and" NICHT Null ist
  subc @r4, @r4
  ret

;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_opcodierbar_rechenlogik, "<>"
  cmp @r4+, @r4
  bit #2, sr ; Z-Flag prüfen und in Carry holen
  subc @r4, @r4
  ret
 
;------------------------------------------------------------------------------
  Wortbirne Flag_visible|Flag_opcodierbar_rechenlogik, "="
  xor @r4+, @r4  ; Ergibt Null, wenn beide gleich waren.
  subc @r4, @r4
  ret
