News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

compiling masm to intel... and loops

Started by whakamaru, November 28, 2011, 10:04:16 PM

Previous topic - Next topic

whakamaru

The following is an instruction in a program, where SymSIZE has previously been defined as EQU 4*10
add eax, [esp][ecx*4][SymSIZE]

I wonder what the Intel instructions are?  Several?
Also, I have not seen the LOOP instruction used.  People seem to prefer to set ECX, then DEC ECX and JNZ or JNS
Is there a reason for this?  Are the jumps still restricted to +/- 80h?

qWord

Quote from: whakamaru on November 28, 2011, 10:04:16 PM
The following is an instruction in a program, where SymSIZE has previously been defined as EQU 4*10
add eax, [esp][ecx*4][SymSIZE]

I wonder what the Intel instructions are?  Several?
This is a instruction, which is using SIB-Addressing (Scale Index Base). ESP is the base, ECX the index which is scaled by 4 and SymSIZE is a displacement (=Offset). A syntax variantion:
add eax,[esp+ecx*4+4*10]

Quote from: whakamaru on November 28, 2011, 10:04:16 PM
Also, I have not seen the LOOP instruction used.  People seem to prefer to set ECX, then DEC ECX and JNZ or JNS
Is there a reason for this?
This instruction is obsolete (and slow) and should not be used (see AMD'S optimization Manual)

Quote from: whakamaru on November 28, 2011, 10:04:16 PM
Are the jumps still restricted to +/- 80h?
16 and 32 bit offset are also possible.
FPU in a trice: SmplMath
It's that simple!

FORTRANS

Quote from: whakamaru on November 28, 2011, 10:04:16 PM
Also, I have not seen the LOOP instruction used.  People seem to prefer to set ECX, then DEC ECX and JNZ or JNS
Is there a reason for this?  Are the jumps still restricted to +/- 80h?

Hi,

   The choice of using or lot using LOOP is personal preference.
As qWord said, it is slower.  I tend to use it as it saves on some
typing.  As to jumps, no you are not limited to 80H (SHORT).
If you enable 32-bit instructions, you can use NEAR jumps.
But if in real mode (MS-DOS), you have to be careful not to
jump out of the current segment.

Regards,

Steve N.

MichaelW

Short jumps are not restricted to +/- 80h but to -128/+127, the range of a signed byte.
eschew obfuscation

clive

Quote from: MichaelWShort jumps are not restricted to +/- 80h but to -128/+127, the range of a signed byte.

But it's relative to the NEXT instruction, so fun like "JMP $+81h" is valid, and "JMP $-80h" is not encodable with 8-bits, and uses the 32-bit form instead.

Quote from: whakamaruThe following is an instruction in a program, where SymSIZE has previously been defined as EQU 4*10
add eax, [esp][ecx*4][SymSIZE]

I wonder what the Intel instructions are?  Several?

Well technically it's a SINGLE instruction, but the opcode/machine-code spans several bytes. Use the -Fl option of MASM to generate a listing to see the codes.

00000000  EB 7F         JMP $+81h
00000002  E9 FFFFFF7B         JMP $-80h

= 00000028 SymSIZE equ 4*10

00000007  03 44 8C 28         add     eax, [esp][ecx*4][SymSIZE]
It could be a random act of randomness. Those happen a lot as well.

hutch--

Hi whakamura,

Good to see another Kiwi in the place.

With the notation,


add eax, [esp][ecx*4][SymSIZE]


the paired square brackets function like an addition operator.


add eax, [esp][ecx*4][SymSIZE]
add eax, [esp+ecx*4+SymSIZE]


The capacity is useful for readability when for example you need to correct ESP for changes in the stack with PUSH or POP.


mov eax, [esp+4][4]
push eax
mov ecx, [esp+4][8]


RE: The use of the old LOOP instruction, it is rarely ever used these days as it is much slower than a CMP or TEST then branching back to a label. On modern processors you have the difference between preferred instructions that are hard coded in silicon and old instructions that are constructed in microcode which work as documented but perform poorly, LOOP is one of those old instructions.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php