Das Purebasic alles (bis auf die neuen Typen C und U) asigned betrachtet ist doch schon lange bekannt.
Ist auch kein Problem bei Addtion, Subtration, Multiplikation, etc ... Kommt immer da richtige raus wenn man nicht gerade einen völligen überlauf verursacht.
Es ist immer eine frage wie das Ergebnis betrachtet wird. Signed oder Unsigned.
Für die Ausgabe als Unsigned gibt es "StrU(...)"
Für Vergleich habe ich mal dieses gebastelt.
Code: Alles auswählen
;-TOP
; Kommentar :
; Author : mk-soft
; Second Author :
; Datei : UnsignedCompare.pb
; Version : 1.01
; Erstellt :
; Geändert :
;
; 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
