Discussion:
locals and jumps
(too old to reply)
Madhur
2003-06-29 20:14:12 UTC
Permalink
hello
I usually program in MASM, in every tasm file , i encounter with 2 words
locals,jumps.
what these directives do.
what are masm equivalents to these.

--
Madhur
India

Any fool can write code that a computer can understand. Good programmers
write code that humans can understand.
Beth
2003-06-30 03:46:03 UTC
Permalink
Post by Madhur
hello
Hi :)
Post by Madhur
I usually program in MASM, in every tasm file , i encounter with 2 words
locals,jumps.
[ Tip: try not to use the word "word" but rather "directive" or
"instruction" or "text" or something for a question like
this...because, of course, "word" means "16-bit quantity" and, well,
for a while, I was slightly confused about what you were asking
here...until I realised you meant "word" in its plain English meaning
:) ]
Post by Madhur
what these directives do.
--------------------

LOCALS Enable local symbols
Directive

LOCALS [prefix]

Enables block-scoped symbols, and optionally sets the
two-character
local symbol prefix.

Local symbols are automatically enabled in Ideal mode.

Example: locals __
;...
test ax,1
jnz __odd
dec ax
__odd:

Example: Ideal ; Default local symbol prefix
@@
lab1: ; Start of scope
@@a: ; Belongs to scope starting at
lab1
@@b = 1 ; Ditto
lab2: ; Start of scope
@@a: ; Belongs to scope starting at
lab2
@@b:

--------------------

--------------------

JUMPS Stretch conditional jumps
Directive

JUMPS

Causes TASM to look at the destination address of a conditional
jump
instruction, and if it is too far away to reach with the SHORT
dis-
placement that these instructions use, it generates a conditional
jump
of the opposite sense around an ordinary jump instruction to the
desired target address.

Example: je equal_place ; If short jump out of
range

jne ??0001 ; ...this code is
generated
jmp equal_place
??0001:

This directive has the same effect as using /jJUMPS on the command
line.
To avoid generating extra NOPs, you can use the /m# switch
(multiple
assembly passes) or specify a SHORT override.

--------------------
Post by Madhur
what are masm equivalents to these.
For "LOCALS", these are the nearest things:

--------------------

Syntax: OPTION SCOPED

OPTION NOSCOPED

Description:

The SCOPED option causes a label (defined with the "label:"
syntax)
to be local to the procedure in which it is defined. Labels
defined
with the LABEL directive or the "label::" syntax are not affected
by
this option.

Using NOSCOPED will cause all labels to be global to the module.
SCOPED is the default. The NOSCOPED option is enabled with the
M510 option, if the .MODEL directive is used without a language
type
specification. Specifying .MODEL with a language type enables
OPTION SCOPED.

Without a language type, MASM 5.1 assumes code labels in
procedures have
no scope--that is, the labels are not local to the procedure.
When not
in compatibility mode, MASM 6.1 always gives scope to code
labels, even
without a language type.

To force MASM 5.1 behavior, specify either OPTION M510 or OPTION
NOSCOPED

in your code. To selectively enable MASM 6.1 behavior, place the
dir-
ective OPTION SCOPED after OPTION M510.

To determine which labels require change, assemble the module
without the
OPTION NOSCOPED directive. For each reference to a label that is
not
local, the assembler generates error A2006.

--------------------

Plus:

--------------------

Local Code Labels

Syntax: [instruction] @F
.
.
.
@@: [statement]
.
.
.
[instruction] @B

Description:

The @@: label defines a local code label, which is in effect
until
the next instance of @@:. The @F and @B operands can be used in
conditional and unconditional jump statements to jump to the next

and previous @@: label respectively.

The @@: label is useful for defining a nearby jump point where a
full label is not appropriate.

Example:

cmp ax, 18h
jg @F
- ;Less than or equal
-
-
@@: ;Greater than


mov cx, 640 ;Set count

@@:
- ;Loop statements
-
-

loop @B ;Loop back

--------------------

MASM doesn't seem to have the exact 100% direct equivalent
functionality because, unlike TASM, you can't specify your own two
character prefixes...but it's close enough to call these "equivalent",
I think :)

Anyway, as for MASM's equivalent for "JUMPS", there _is_ a direct
equivalent:

--------------------

Syntax: OPTION LJMP

OPTION NOLJMP

Description:

The LJMP option enables automatic conditional-jump lengthening.
LJMP is the default.

Enabling LJMP allows the assembler to generate code that emulates
a conditional jump of greater than -128 to +127 bytes. If the
jump
is within this range, no special code is generated. It does not
affect unconditional jumps or the control-flow directives.

The assembler will generate an A6003 warning for a lengthened
jump
so that you can identify it for later optimization.

--------------------

Any use to you?

Beth :)
Madhur
2003-06-30 07:18:33 UTC
Permalink
Excellent answer Beth, Thank you very much.
Sometimes i wonder how you people devote so much time just to answer a
simple single question.

--
Madhur
India

Any fool can write code that a computer can understand. Good programmers
write code that humans can understand.
Post by Beth
Post by Madhur
hello
Hi :)
Post by Madhur
I usually program in MASM, in every tasm file , i encounter with 2
words
Post by Madhur
locals,jumps.
[ Tip: try not to use the word "word" but rather "directive" or
"instruction" or "text" or something for a question like
this...because, of course, "word" means "16-bit quantity" and, well,
for a while, I was slightly confused about what you were asking
here...until I realised you meant "word" in its plain English meaning
:) ]
Post by Madhur
what these directives do.
--------------------
LOCALS Enable local symbols
Directive
LOCALS [prefix]
Enables block-scoped symbols, and optionally sets the
two-character
local symbol prefix.
Local symbols are automatically enabled in Ideal mode.
Example: locals __
;...
test ax,1
jnz __odd
dec ax
Example: Ideal ; Default local symbol prefix
@@
lab1: ; Start of scope
@@a: ; Belongs to scope starting at
lab1
@@b = 1 ; Ditto
lab2: ; Start of scope
@@a: ; Belongs to scope starting at
lab2
--------------------
--------------------
JUMPS Stretch conditional jumps
Directive
JUMPS
Causes TASM to look at the destination address of a conditional
jump
instruction, and if it is too far away to reach with the SHORT
dis-
placement that these instructions use, it generates a conditional
jump
of the opposite sense around an ordinary jump instruction to the
desired target address.
Example: je equal_place ; If short jump out of
range
jne ??0001 ; ...this code is
generated
jmp equal_place
This directive has the same effect as using /jJUMPS on the command
line.
To avoid generating extra NOPs, you can use the /m# switch
(multiple
assembly passes) or specify a SHORT override.
--------------------
Post by Madhur
what are masm equivalents to these.
--------------------
Syntax: OPTION SCOPED
OPTION NOSCOPED
The SCOPED option causes a label (defined with the "label:"
syntax)
to be local to the procedure in which it is defined. Labels
defined
with the LABEL directive or the "label::" syntax are not affected
by
this option.
Using NOSCOPED will cause all labels to be global to the module.
SCOPED is the default. The NOSCOPED option is enabled with the
M510 option, if the .MODEL directive is used without a language
type
specification. Specifying .MODEL with a language type enables
OPTION SCOPED.
Without a language type, MASM 5.1 assumes code labels in
procedures have
no scope--that is, the labels are not local to the procedure.
When not
in compatibility mode, MASM 6.1 always gives scope to code
labels, even
without a language type.
To force MASM 5.1 behavior, specify either OPTION M510 or OPTION
NOSCOPED
in your code. To selectively enable MASM 6.1 behavior, place the
dir-
ective OPTION SCOPED after OPTION M510.
To determine which labels require change, assemble the module
without the
OPTION NOSCOPED directive. For each reference to a label that is
not
local, the assembler generates error A2006.
--------------------
--------------------
Local Code Labels
.
.
.
@@: [statement]
.
.
.
until
conditional and unconditional jump statements to jump to the next
full label is not appropriate.
cmp ax, 18h
- ;Less than or equal
-
-
@@: ;Greater than
mov cx, 640 ;Set count
- ;Loop statements
-
-
--------------------
MASM doesn't seem to have the exact 100% direct equivalent
functionality because, unlike TASM, you can't specify your own two
character prefixes...but it's close enough to call these "equivalent",
I think :)
Anyway, as for MASM's equivalent for "JUMPS", there _is_ a direct
--------------------
Syntax: OPTION LJMP
OPTION NOLJMP
The LJMP option enables automatic conditional-jump lengthening.
LJMP is the default.
Enabling LJMP allows the assembler to generate code that emulates
a conditional jump of greater than -128 to +127 bytes. If the
jump
is within this range, no special code is generated. It does not
affect unconditional jumps or the control-flow directives.
The assembler will generate an A6003 warning for a lengthened
jump
so that you can identify it for later optimization.
--------------------
Any use to you?
Beth :)
Loading...