Share via


Assembly-Language Expressions 

This topic applies to:

Visual Studio Edition

Visual Basic

C#

C++

J#

Express

No

No

Yes

No

Standard

No

No

Yes

No

Pro/Team

No

No

Yes

No

The debugger can correctly evaluate assembly-language expressions, with some restrictions. The syntax used for some assembly-language expressions differs from the syntax used in assembly-language development systems, such as the Microsoft Macro Assembler (MASM).

Memory Operators

Memory operators are unary operators that return the result of a direct memory operation. These operators are used mainly to debug assembly-language code.

{BY | WO | DW} address

The BY operator returns a short integer that contains the first byte at address. This operator simulates BYTE PTR.

The WO operator returns a short integer that contains the value of the word, two bytes, at address. This operator simulates the Microsoft Macro Assembler WORD PTR operation. The DW operator returns a long integer that contains the value of the first four bytes at address. This operator simulates DWORD PTR.

The x format specifier used in some of these examples causes the result to be displayed in hexadecimal.

Examples

  • To display the first byte at the address of the variable sum:

    BY sum

  • To display the first word at the address of the variable new_set:

    WO new_set

  • To display the doubleword at the address of sum:

    DW sum

  • To display the byte pointed to by the EBP register with a displacement of 6:

    BY ebp+6,x

  • To display the word pointed to by the stack pointer, the last word pushed onto the stack:

    WO esp,x

  • To display the doubleword pointed to by the ESI register:

    DW esi,x

Register Indirect

The debugger does not recognize brackets ([ ]) to indicate a memory location pointed to by a register. Instead, use the BY, WO, and DW operators to reference the corresponding byte, word, or doubleword values.

MASM expression Debugger expression C++ expression

BYTE PTR [bx]

BY ebx

*(unsigned char) ebx

WORD PTR [bp]

WO ebp

*(unsigned short *) ebp

DWORD PTR [bp]

DW ebp

*(unsigned long *) ebp

Register Indirect with Displacement

To perform based, indexed, or based-indexed indirect mode operations with a displacement, use the BY, WO, or DW operators with the addition operator.

MASM expression Debugger expression

BYTE PTR [edi+6]

BY edi+6

BYTE PTR Test[ebx]

BY &Test+ebx

WORD PTR [esi][ebp+6]

WO esi+ebp+6

DWORD PTR [ebx][esi]

DW ebx+esi

Address of a Variable

Use the C address-of operator (&) instead of the MASM OFFSET operator.

MASM expression Debugger expression

OFFSET Var

&Var

PTR Operator

Use type casts or the BY, WO, and DW operators with the address-of operator (&) to replace the assembly-language PTR operator.

MASM expression Debugger expression

BYTE PTR Var

BY &Var

*(unsigned char*)

&Var

WORD PTR Var

WO &Var

DWORD PTR Var

DW &Var

*(unsigned long*)

&Var

Assembly-Language Strings

Add the string format specifier ,s after the variable name.


MASM expression Debugger expression

String

String,s

Because C strings end with a null (ASCII 0) character, the debugger displays all characters from the first byte of the variable up to the next null byte in memory when you request a string display. If you intend to debug an assembly-language program, and you want to view strings in the Watch window, you should delimit string variables with a null character. An easy way to view null-terminated or unterminated strings is by using the Memory window.

Array and Structure Elements

Prefix an array name with the address-of operator (&) and add the desired offset. The offset can be an expression, number, register name, or variable.

The following examples show how to do this for byte, word, and doubleword arrays.

MASM expression Debugger expression

String[12]

BY &String+12*(&String+12)

aWords[bx+di]

WO &aWords+bx+di*(unsigned*)(&aWords+bx+di)

aDWords[bx+4]

DW &aDWords+bx+4*(unsigned long*)(&aDWords+bx+4)

See Also

Other Resources

Expressions in Native C++