News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Long version of add reg32 encoding

Started by jj2007, September 16, 2013, 05:42:37 PM

Previous topic - Next topic

jj2007

  mov edx, MbQsAsc   ; addr of sort proc; default is ascending
  test eax, eax
  .if Sign?
   add edx, MbQsDesc-MbQsAsc
  .endif
...
MbQsAsc proc
...
MbQsDesc proc


Olly says this is add edx, 16h
However, all ML versions and JWasm use the long form, i.e.
81C2 16000000          add edx, 16

Is that because the difference in offsets becomes known only at runtime? But that would apply also to jmp instructions... :(

japheth

Quote from: jj2007 on September 16, 2013, 05:42:37 PM
Is that because the difference in offsets becomes known only at runtime? But that would apply also to jmp instructions... :(

The difference of two local labels is known at assembly-time. It has to be, because there is no relocation type to tell the linker how to compute the difference.

Additionally, the local labels must be in the same section.

If they aren't


.386
.model flat

.code x1
lbl1:
.code x2
lbl2:
mov eax, lbl2 - lbl1

end


you'll get error 'operands must be in the same segment'

jj2007

Quote from: japheth on September 16, 2013, 06:09:44 PM
The difference of two local labels is known at assembly-time.

So the assembler could choose the shorter encoding?

japheth

Quote from: jj2007 on September 16, 2013, 07:35:52 PM
So the assembler could choose the shorter encoding?

Actually, jwasm does and masm could.


                                .386
                                .model flat

                                .code

00000000                        start:

00000000  83C001                add eax, lbl2-lbl1
00000003  0501000000            add eax, dword ptr (lbl2-lbl1)
00000008  83C001                add eax, 1
0000000B  0501000000            add eax, dword ptr 1
00000010                        lbl1:
00000010  00                    db 1 dup (0)
00000011                        lbl2:

                                end start


dedndave

don't suppose you tried to override it
   add edx,byte ptr (MbQsDesc-MbQsAsc)
or
   add edx,sbyte ptr (MbQsDesc-MbQsAsc)
or maybe
   add edx,sdword ptr (MbQsDesc-MbQsAsc)

maybe just the parens - they could force evaluation before the size is determined
   add edx,(MbQsDesc-MbQsAsc)

qWord

a small macro should do MASM's job:
add_imm macro a,b
    IF b GE -128 AND b LE 127
        add a,0
        org $-1
        db b
    ELSE
        add a,b
    ENDIF
endm
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

another idea...
MbQsDescAsc = MbQsDesc-MbQsAsc
   add edx,MbQsDescAsc

jj2007

Quote from: qWord on September 16, 2013, 10:37:40 PM
a small macro should do MASM's job:

You are cheating :eusa_naughty:
But it works :t

However, it complains if the label is defined after the add_imm call. No problem ;-)

Quote from: dedndave on September 16, 2013, 10:46:05 PM
another idea...
MbQsDescAsc = MbQsDesc-MbQsAsc
   add edx,MbQsDescAsc


No luck, unfortunately ...

As to JWasm, it seems I had tried an add edx, dword ptr (MbQsDesc-MbQsAsc), which forces the long encoding. The standard version is indeed short :t

daydreamer

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

dedndave

not if you need 16h of them   :biggrin:
loop00: inc     edx
        cmp     edx,offset MbQsDesc
        jb      loop00