Microsoft KB Archive/111474

From BetaArchive Wiki
Knowledge Base


Article ID: 111474

Article Last Modified on 10/14/2003



APPLIES TO

  • Microsoft Macro Assembler 6.0 Standard Edition
  • Microsoft Macro Assembler 6.0a
  • Microsoft Macro Assembler 6.0b
  • Microsoft Macro Assembler 6.1 Standard Edition
  • Microsoft Macro Assembler 6.1a
  • Microsoft Macro Assembler 6.11 Standard Edition



This article was previously published under Q111474

SUMMARY

Beginning with MASM version 6.0, an ORG directive is permitted in a structure declaration. This enables the generation of a template that can ease references to the internals of data structures that are predefined, for example by the operating system, the operating platform, or a high- level language compiler. A consequence of declaring an ORG in a STRUCT is that an instance is not intended to be defined in the source file, and in fact will generate the following error:

error: A2159: structure cannot be instanced

This is the expected behavior.

MORE INFORMATION

For additional information about the usage of an ORG directive inside a structure declaration, please see the following article(s) in the Microsoft Knowledge Base:

111473 BUG: ORG in STRUCT Affects Current Segment Size with -Sf


The following code sample illustrates the usage of an ORG in a structure declaration. The sample declares a structure that is used as a template to refer to video memory for the last two lines of a text mode display. Possible usage includes easing the display of status information of an application running in text mode. This is not necessarily the best method to accomplish this task, but is presented to demonstrate a point.

This code sample assumes a color video adapter running in the 80X25 text display mode with the processor running in real mode, and must be modified for another configuration.

Sample Code

; Assemble options needed: none
.MODEL SMALL,C
.386
 
VIDEOMEM     EQU 0B800h   ; segment address of video memory
NUMLINES     EQU 25
NUMCOLS      EQU 80
BLACKONWHITE EQU  70h     ; display attributes
YELLOWONBLUE EQU  1Eh
 
status STRUCT
    org (NUMLINES - 2) * NUMCOLS * 2
    line1   db ?
    attrib1 db ?
    org (NUMLINES - 1) * NUMCOLS * 2
    line2   db ?
    attrib2 db ?
status ENDS
 
.STACK
 
.DATA
    msg1    db "This is the first status line, "
            db "with yellow characters on a blue background."
    lenmsg1 dw $-msg1

    msg2    db "This is the second status line, "
            db "with black characters on a white background."
    lenmsg2 dw $-msg2
 
.CODE
.STARTUP
 
    mov ax, VIDEOMEM
    mov es, ax
 
    mov cx, NUMCOLS
    xor di, di
@@:
    mov es:[di].status.attrib1, YELLOWONBLUE
    mov es:[di].status.attrib2, BLACKONWHITE
    inc di
    inc di
    loop @B

    xor si, si
    xor di, di
    mov cx, lenmsg1
@@:
    mov al, msg1[si]
    mov es:[di].status.line1, al
    inc si
    inc di
    inc di
    loop @B

    xor si, si
    xor di, di
    mov cx, lenmsg2
@@:
    mov al, msg2[si]
    mov es:[di].status.line2, al
    inc si
    inc di
    inc di
    loop @B

.EXIT
 
END
                


Additional query words: 6.00 6.00a 6.00b 6.10 6.10a 6.1x

Keywords: KB111474