Seite 1 von 1

UnsignedCompare

Verfasst: 08.12.2009 21:21
von mk-soft
Ein Variable von Type Long kann man auch als Unsigned betrachten und so mit rechnen und ausgeben (StrU(... , #PB-Long).
Es fehlen nur die Vergleichsoperationen für Unsigned.

Habe mal was dafür gebastelt.

Code: Alles auswählen

;-TOP
; Kommentar     : 
; Author        : mk-soft
; Second Author : 
; Datei         : UnsignedCompare.pb
; Version       : 1.01
; Erstellt      : 
; Geändert      :
; 
; Compilermode  :
;
; ***************************************************************************************

Procedure Above(a.l, b.l)

EnableASM
; If a > b
  MOV    ebx,dword [p.v_a]
  CMP    ebx,dword [p.v_b]
  JBE   l_not_above
; ProcedureReturn #True
  MOV    eax,1
  ProcedureReturn
not_above:
; ProcedureReturn #False
  XOr    eax,eax
  ProcedureReturn
DisableASM

EndProcedure

; ***************************************************************************************

Procedure AboveEqual(a.l , b.l)

EnableASM
; If a >= b
  MOV    ebx,dword [p.v_a]
  CMP    ebx,dword [p.v_b]
  JB   l_not_above_equal
; ProcedureReturn #True
  MOV    eax,1
  ProcedureReturn
not_above_equal:
; ProcedureReturn #False
  XOr    eax,eax
  ProcedureReturn
DisableASM
  
EndProcedure

; ***************************************************************************************

Procedure Below(a.l, b.l)

EnableASM
; If a < b
  MOV    ebx,dword [p.v_a]
  CMP    ebx,dword [p.v_b]
  JAE   l_not_below
; ProcedureReturn #True
  MOV    eax,1
  ProcedureReturn
not_below:
; ProcedureReturn #False
  XOr    eax,eax
  ProcedureReturn
DisableASM
  
EndProcedure

; ***************************************************************************************

Procedure BelowEqual(a.l, b.l)

EnableASM
; If a <= b
  MOV    ebx,dword [p.v_a]
  CMP    ebx,dword [p.v_b]
  JA   l_not_below_equal
; ProcedureReturn #True
  MOV    eax,1
  ProcedureReturn
not_below_equal:
; ProcedureReturn #False
  XOr    eax,eax
  ProcedureReturn
DisableASM
  
EndProcedure

; ***************************************************************************************

; test

Debug "Unsigned grösser"
Debug Above( -1, 1)
Debug Above( 1, 1)

Debug "Unsigned grösser gleich"
Debug AboveEqual( -1, 1)
Debug AboveEqual( 1, 1)

Debug "Unsigned kleiner"
Debug Below( 1, -1)
Debug Below( 1, 1)

Debug "Unsigned kleiner gleich"
Debug BelowEqual( 1, -1)
Debug BelowEqual( 1, 1)
FF :wink:

Re: UnsignedCompare

Verfasst: 08.12.2009 22:06
von mk-soft
Kleines Problem bei X64 Version. Es kommt ein falsches Ergebnis herraus

Code: Alles auswählen

  Procedure Above(a.i, b.i)
  
  
  EnableASM
  ; If a > b
    MOV    rbx,qword [p.v_a]
    CMP    rbx,qword [p.v_b]
    JBE   l_not_above
  ; ProcedureReturn #True
    MOV    rax,1
    ProcedureReturn
  not_above:
  ; ProcedureReturn #False
    XOr    rax,rax
    ProcedureReturn
  DisableASM
  
  EndProcedure
  
??? :|

Re: UnsignedCompare

Verfasst: 10.12.2009 11:41
von andi256
hast du das von "remi_meier" mal gelesen / getestet ?

weis nicht ob Dir dieses Thread hilft -> http://forums.purebasic.com/german/view ... 6fe2731926

Code: Alles auswählen

Procedure.l UINT_Greater(a.l, b.l) 
  !XOR Eax,Eax 
  !MOV Ebx,[p.v_a] 
  !CMP Ebx,[p.v_b] 
  !SETA al 
  ProcedureReturn 
EndProcedure
aber obs auf 64bit maschinen läuft keine Ahnung ... bin ein ASM noop ... und hab kein 64bit rechner :-(

mfg andi

Re: UnsignedCompare

Verfasst: 10.12.2009 17:31
von mk-soft
Habe den Fehler gefunden und im englischen Forum gemeldet.

Hier jetzt auch mit 64bit Version.

Code: Alles auswählen

;-TOP
; Kommentar     : 
; Author        : mk-soft
; Second Author : 
; Datei         : UnsignedCompare.pb
; Version       : 1.02
; Erstellt      : 
; Geändert      : 10.12.2009
; 
; Compilermode  :
;
; ***************************************************************************************

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 

  ; X86 ************************************************************************************
 
  Procedure Above(a.i, b.i)
  
  EnableASM
  ; If a > b
    MOV    ebx,dword [p.v_a]
    CMP    ebx,dword [p.v_b]
    JBE   l_not_above
  ; ProcedureReturn #True
    MOV    eax,1
    ProcedureReturn
  not_above:
  ; ProcedureReturn #False
    XOr    eax,eax
    ProcedureReturn
  DisableASM
  
  EndProcedure
  
  ; ***************************************************************************************
  
  Procedure AboveEqual(a.i , b.i)
  
  EnableASM
  ; If a >= b
    MOV    ebx,dword [p.v_a]
    CMP    ebx,dword [p.v_b]
    JB   l_not_above_equal
  ; ProcedureReturn #True
    MOV    eax,1
    ProcedureReturn
  not_above_equal:
  ; ProcedureReturn #False
    XOr    eax,eax
    ProcedureReturn
  DisableASM
    
  EndProcedure
  
  ; ***************************************************************************************
  
  Procedure Below(a.i, b.i)
  
  EnableASM
  ; If a < b
    MOV    ebx,dword [p.v_a]
    CMP    ebx,dword [p.v_b]
    JAE   l_not_below
  ; ProcedureReturn #True
    MOV    eax,1
    ProcedureReturn
  not_below:
  ; ProcedureReturn #False
    XOr    eax,eax
    ProcedureReturn
  DisableASM
    
  EndProcedure
  
  ; ***************************************************************************************
  
  Procedure BelowEqual(a.i, b.i)
  
  EnableASM
  ; If a <= b
    MOV    ebx,dword [p.v_a]
    CMP    ebx,dword [p.v_b]
    JA   l_not_below_equal
  ; ProcedureReturn #True
    MOV    eax,1
    ProcedureReturn
  not_below_equal:
  ; ProcedureReturn #False
    XOr    eax,eax
    ProcedureReturn
  DisableASM
    
  EndProcedure

CompilerElse 

 ; X64 ************************************************************************************
 
  Procedure Above(a.q, b.q)

  EnableASM
  ; If a >= b
    MOV    r15,qword [p.v_a]
    CMP    r15,qword [p.v_b]
    !JBE   l_not_above
  ; ProcedureReturn #True
    MOV    rax,1
    ProcedureReturn
  not_above:
  ; ProcedureReturn #False
    XOr    rax,rax
    ProcedureReturn
  DisableASM
  
  EndProcedure
  
  ; ***************************************************************************************
  
  Procedure AboveEqual(a.i , b.i)
  
  EnableASM
  ; If a >= b
    MOV    r15,qword [p.v_a]
    CMP    r15,qword [p.v_b]
    !JB   l_not_above_equal
  ; ProcedureReturn #True
    MOV    rax,1
    ProcedureReturn
  not_above_equal:
  ; ProcedureReturn #False
    XOr    rax,rax
    ProcedureReturn
  DisableASM
    
  EndProcedure
  
  ; ***************************************************************************************
  
  Procedure Below(a.i, b.i)
  
  EnableASM
  ; If a < b
    MOV    r15,qword [p.v_a]
    CMP    r15,qword [p.v_b]
    !JAE   l_not_below
  ; ProcedureReturn #True
    MOV    rax,1
    ProcedureReturn
  not_below:
  ; ProcedureReturn #False
    XOr    rax,rax
    ProcedureReturn
  DisableASM
    
  EndProcedure
  
  ; ***************************************************************************************
  
  Procedure BelowEqual(a.i, b.i)
  
  EnableASM
  ; If a <= b
    MOV    r15,qword [p.v_a]
    CMP    r15,qword [p.v_b]
    !JA   l_not_below_equal
  ; ProcedureReturn #True
    MOV    rax,1
    ProcedureReturn
  not_below_equal:
  ; ProcedureReturn #False
    XOr    rax,rax
    ProcedureReturn
  DisableASM
    
  EndProcedure
  
  ; ***************************************************************************************

CompilerEndIf
; test

Debug "Unsigned grösser"
Debug Above( -1, 1)
Debug Above( 1, 1)

Debug "Unsigned grösser gleich"
Debug AboveEqual( -1, 1)
Debug AboveEqual( 1, 1)

Debug "Unsigned kleiner"
Debug Below( 1, -1)
Debug Below( 1, 1)

Debug "Unsigned kleiner gleich"
Debug BelowEqual( 1, -1)
Debug BelowEqual( 1, 1)

FF :wink:

Re: UnsignedCompare

Verfasst: 22.07.2010 16:27
von NicTheQuick
Kann man sowas auch in Makros packen?

Re: UnsignedCompare

Verfasst: 22.07.2010 20:06
von mk-soft
Schwierig wegen der Zuweisung des Ergebnisses... :cry: