Page 1 of 1

Some procedures for working with unsigned variables

Posted: Sat Aug 03, 2013 7:28 am
by wilbert
Convert an unsigned quad to a string

Code: Select all

Procedure.s UStrQ(n.q)
  Protected tmp.l
  !mov ecx, 10
  !xor edx, edx
  !mov eax, [p.v_n + 4]
  !div ecx
  !mov [p.v_n + 4], eax
  !mov eax, [p.v_n]
  !div ecx
  !mov [p.v_n], eax
  !mov [p.v_tmp], edx
  If n
    ProcedureReturn Str(n) + Str(tmp)
  Else
    ProcedureReturn Str(tmp)
  EndIf
EndProcedure



Debug UStrQ($ffffffffffffffff)


Unsigned compare

Code: Select all

Procedure.i UComL(n1.l, n2.l); returns -1 if n1 < n2, 0 if n2 = n2, 1 if n1 > n2 
  !mov eax, [p.v_n1]
  !sub eax, [p.v_n2]
  !jz ucoml_exit
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !sbb rax, rax
  CompilerElse
    !sbb eax, eax
  CompilerEndIf
  !jnz ucoml_exit
  !inc eax
  !ucoml_exit:
  ProcedureReturn
EndProcedure

Procedure.i UComQ(n1.q, n2.q); returns -1 if n1 < n2, 0 if n2 = n2, 1 if n1 > n2 
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov rax, [p.v_n1]
    !sub rax, [p.v_n2]
    !jz ucomq_exit
    !sbb rax, rax
    !jnz ucomq_exit
  CompilerElse
    !mov ecx, [p.v_n1]
    !mov edx, [p.v_n1 + 4]
    !sub ecx, [p.v_n2]
    !sbb edx, [p.v_n2 + 4]
    !sbb eax, eax
    !jnz ucomq_exit
    !or ecx, edx
    !jz ucomq_exit
  CompilerEndIf
  !inc eax
  !ucomq_exit:
  ProcedureReturn
EndProcedure



If UComL($7fffffff, $ffffffff) < 0
  Debug "$7fffffff < $ffffffff"
EndIf

Re: Some procedures for working with unsigned variables

Posted: Sat Aug 03, 2013 12:29 pm
by Fred
StrU() should work as well:

Code: Select all

Debug StrU($ffffffffffffffff, #PB_Quad)

Re: Some procedures for working with unsigned variables

Posted: Sat Aug 03, 2013 12:44 pm
by wilbert
Fred wrote:StrU() should work as well:

Code: Select all

Debug StrU($ffffffffffffffff, #PB_Quad)
Thanks. I didn't know StrU existed.
Has that always been there ? I must have overlooked it.

Re: Some procedures for working with unsigned variables

Posted: Sat Aug 03, 2013 1:26 pm
by Fred
Yep, almost since the beginning :)