64 bit assembler > ASMC Development

Signed compare in HLL

(1/2) > >>

nidud:
Added signed compare .IFS, .IFSB, .IFSW, and .IFSD

Test case for 16/32/64-bit.

Basically turns an .IF <statement> to "signed" if the first operand is a register. Was intended for functions normally returning [R|E]AX, but will work on other registers as well.

Qsort example using a prototype defined in stdlib.inc

--- Code: ---include stdlib.inc
include string.inc

.code

qsort PROC USES esi edi ebx p:PVOID, n:SIZE_T, w:SIZE_T, compare:LPQSORTCMD

local stack_level

mov eax,n
.if eax > 1

dec eax
mul w
mov esi,p
lea edi,[esi+eax]
mov stack_level,0

.while 1

mov ecx,w
lea eax,[edi+ecx] ; middle from (hi - lo) / 2
sub eax,esi

.if !ZERO?

sub edx,edx
div ecx
shr eax,1
mul ecx
.endif

lea ebx,[esi+eax]
.ifs compare( esi, ebx ) > 0

memxchg( esi, ebx, w )
.endif
.ifs compare( esi, edi ) > 0

memxchg( esi, edi, w )
.endif
.ifs compare( ebx, edi ) > 0

memxchg( ebx, edi, w )
.endif

mov p,esi
mov n,edi

.while 1

mov eax,w
add p,eax
.if p < edi

.continue .ifs compare( p, ebx ) <= 0
.endif

.while 1

mov eax,w
sub n,eax

.break .if n <= ebx
.break .ifs compare( n, ebx ) <= 0
.endw

mov edx,n
mov eax,p
.break .if edx < eax

memxchg( edx, eax, w )

.if ebx == n

mov ebx,p
.endif
.endw

mov eax,w
add n,eax

.while 1

mov eax,w
sub n,eax

.break .if n <= esi
.break .if compare( n, ebx )
.endw

mov edx,p
mov eax,n
sub eax,esi
mov ecx,edi
sub ecx,edx

.ifs eax < ecx

mov ecx,n

.if edx < edi

push edx
push edi
inc stack_level
.endif

.if esi < ecx

mov edi,ecx
.continue
.endif
.else
mov ecx,n

.if esi < ecx

push esi
push ecx
inc stack_level
.endif

.if edx < edi

mov esi,edx
.continue
.endif
.endif

.break .if !stack_level

dec stack_level
pop edi
pop esi
.endw
.endif
ret

qsort ENDP

END

--- End code ---

jj2007:
What is the difference between

--- Code: ---.ifs compare( esi, ebx ) > 0
--- End code ---
and

--- Code: ---.if sdword ptr esi>ebx
--- End code ---
?

nidud:

--- Quote from: jj2007 on January 25, 2017, 08:29:59 PM ---What is the difference between

--- Code: ---.ifs compare( esi, ebx ) > 0
--- End code ---
and

--- Code: ---.if sdword ptr esi>ebx
--- End code ---
?

--- End quote ---


--- Code: ---0000003B                .ifs compare( esi, ebx ) > 0
0000003B  53                *    push ebx
0000003C  56                *    push esi
0000003D  FF5514            *    call compare
00000040  83F800            *   cmp eax , 0
00000043  7E0A              *   jng @C0004

--- End code ---


--- Code: ---00000000                        .if sdword ptr esi>ebx
00000000  3BF3              *   cmp sdword ptr esi, ebx
00000002  7E00     * jng @C0001

--- End code ---

same as:

--- Code: ---00000000                        .ifs esi > ebx
00000000  3BF3              *   cmp esi , ebx
00000002  7E00              *   jng @C0001
00000004                        .endif
00000004                    *   @C0001:

--- End code ---

nidud:
HLL directives for pre-existing flag conditions added (same as Jxx)


--- Code: --- .IFA - if Above
.IFB - if Below
.IFG - if Greater (signed)
.IFL - if Less (signed)
.IFO - if Overflow (signed)
.IFP - if Parity
.IFS - if Signed (signed)
.IFZ - if Zero
.IFNA - if Not Above
.IFNB - if Not Below
.IFNG - if Not Greater (signed)
.IFNL - if Not Less (signed)
.IFNO - if Not Overflow (signed)
.IFNP - if No Parity
.IFNS - if Not Signed (signed)
.IFNZ - if Not Zero

--- End code ---

Note overlap of existing directive .IFB and .IFS:

Compare (returned) register from expression

--- Code: --- .IFB <expression> - cmp al, 16/32/64
.IFW <expression> - cmp ax, 32/64
.IFD <expression> - cmp eax, 64

--- End code ---

Signed compare

--- Code: --- .IFS <expression> - cmp reg, 16/32/64
.IFSB <expression> - cmp al, 16/32/64
.IFSW <expression> - cmp ax, 32/64
.IFSD <expression> - cmp eax, 64

--- End code ---

Test case:

https://github.com/nidud/asmc/blob/master/source/asmc/regress/src/bin/ifx.asm

nidud:
added HLL directives for .UNTILxx

Test case:

https://github.com/nidud/asmc/blob/master/source/asmc/regress/src/bin/hlljxx64.asm

Navigation

[0] Message Index

[#] Next page

Go to full version