简体   繁体   中英

MASM (8086) assembly language line continuation

I'm learning assembly language for 8086, and I want to know whether there's a line continuation character, for example:

    mov ah,\
    09
    mov dx,offset msg
    int 21h

I've read once that the '\\' sign is used in line continuation but I'm getting an error in MASM, as the '\\' sign isn't working.

The line-continuation character was introduced in MASM 5.1. It is a single backslash character ( \\ ), and must be placed as the last non-space character on the line. This is essentially the same syntax as you suggest in the question, breaking up a single logical line into two or more physical lines.

Starting with MASM 6.1 (possibly 6.0; I can't find a copy of the manual for that version), you were allowed to place comments after the line-continuation backslash. These were effectively treated as whitespace, allowing you to write code like this:

mov ah,  \          ; continue onto the next line
    09
mov dx, offset msg
int 21h

But I agree with the commenters—this is very unlikely to increase the readability of your code. I've written a lot of code in assembly language and never found the need for this. Assembly-language mnemonics are short enough that I cannot imagine why you would ever run out of room for an instruction, even when keeping to an 80-column width.

Note, also, that in MASM 6.1, a trailing comma in initializers implies that the line continues onto the next line. Therefore, the following declarations are legal:

EvenNumbers DB  02h, 04h, 06h, 08h,
                0Ah, 0Ch, 0Eh, 0Fh

OutputStr DB  "Hello ",
              "world!"

This is the only place where wrapping onto a second line might make sense, and it is supported without the need for cumbersome syntax.

This version also raised the maximum number of characters per line from 128 to 512. There is really no reason to be using a version of MASM older than 6.1. Even if you need to compile segmented DOS programs, MASM 6.1 will do it and is fully compatible with older programs written in MASM 5.1.

At any rate, if an instructor asks about this type of syntactical esoterica on an exam, they are really scraping the bottom of the barrel in terms of questions. And if you know everything else so well that you're worried about this, then you are going to nail the exam.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM