General > The Laboratory

SDWORD PTR in comparisons

(1/8) > >>

jj2007:
Note the different encoding. There is apparently no reason to use the long encoding, but both ML and UAsm do it 8)


--- Code: ---include \masm32\include\masm32rt.inc

.code
start:
  or ebx, -1
  .Repeat
print str$(ebx), " ebx", 13, 10
.if ebx<=sdword ptr 0 ; 81FB 00000000
print "le", 13, 10
.else
print "gt", 13, 10
.endif
.if sdword ptr ebx<=0 ; 83FB 00
print "le", 13, 10
.else
print "gt", 13, 10
.endif
inc  ebx
  .Until ebx>1
  inkey
  exit
end start
--- End code ---

habran:
Good spot JJ :t
Nobody noticed that because it is logical to do the second version, I myself would do this:

 .if (sdword ptr ebx <= 0)

I'll see if it can be done the same with otherway round

nidud:

--- Quote from: habran on August 28, 2017, 08:15:15 AM ---Good spot JJ :t
Nobody noticed that because it is logical to do the second version, I myself would do this:

 .if (sdword ptr ebx <= 0)

I'll see if it can be done the same with otherway round

--- End quote ---

The hll definition of if (…) is always signed, so the Asmc implementation is .ifs (…).


--- Code: ---include stdio.inc

.code

main proc
    or ebx,-1
    .repeat
        printf("%d\n", ebx)
        .ifs ebx <= 0
            printf("le\n")
        .else
            printf("gt\n")
        .endif
        ;.ifs ebx <= 0
        ;    printf("le\n")
        ;.else
        ;    printf("gt\n")
        ;.endif
        inc ebx
    .until ebx > 1
    ret

main endp

    end

--- End code ---


--- Code: ---        cmp     ebx, 0  ; 0013 _ 83. FB, 00
        jg      ?_001   ; 0016 _ 7F, 0F

--- End code ---

habran:
Here are some variation what is happening:

--- Code: ---   174: .if (ebx <= 0)
000000000103103d 83 FB 00                         cmp ebx, 0x0 
0000000001031040 77 01                            jnbe 0x1031043 
   175:   nop
0000000001031042 90                               nop 
   176: .endif
   177: .if ebx <= 0
0000000001031043 83 FB 00                         cmp ebx, 0x0 
0000000001031046 77 01                            jnbe 0x1031049 
   178:   nop
0000000001031048 90                               nop 
   179: .endif
   180: .if (sdword ptr ebx <= 0)
0000000001031049 83 FB 00                         cmp ebx, 0x0 
000000000103104c 7F 01                            jnle 0x103104f 
   181:   nop
000000000103104e 90                               nop 
   182: .endif
   183: .if ( ebx <= sdword ptr 0)
000000000103104f 81 FB 00 00 00 00                cmp ebx, 0x0 
0000000001031055 7F 01                            jnle 0x1031058 
   184:   nop
0000000001031057 90                               nop 
   185: .endif
   186:
   187: .if ebx <= sdword ptr 0
0000000001031058 81 FB 00 00 00 00                cmp ebx, 0x0 
000000000103105e 7F 01                            jnle 0x1031061 
   188:   nop
0000000001031060 90                               nop 
   189: .endif

--- End code ---

jj2007:

--- Quote from: nidud on August 28, 2017, 08:39:06 AM ---The hll definition of if (…) is always signed

--- End quote ---

"always" is a big word - there are many hll out there...

Navigation

[0] Message Index

[#] Next page

Go to full version