Struc Problem mit NASM



  • Hi,
    habe folgende struc angelegt:

    struc PMInfoBlock
    
     Signature		db	'PMID' ;Zeile 885
     EntryPoint	   resw	1    ;Zeile 886
     PMInitialize     resw  1      ;Zeile 887
     BIOSDataSel	  resw  1      ;Zeile 888
     A0000Sel		 dw	0A000h ;Zeile 889
     B0000Sel		 dw	0B000h ;Zeile 890
     B8000Sel	     dw    0B800h ;Zeile 891
     CodeSegSel	   dw    0C000h ;Zeile 892
     InProtectMode	db		0      ;Zeile 893
     Checksum		resd	1      ;Zeile 894
    
    endstruc
    

    Wenn ich nun die Datei assemblieren will, gibt NASM folgenden Fehlermeldungen aus:

    Kernel.asm:885: error: attempt to assemble code in [ABSOLUTE] space
    
    Kernel.asm:889: error: attempt to assemble code in [ABSOLUTE] space
    Kernel.asm:890: error: attempt to assemble code in [ABSOLUTE] space
    Kernel.asm:891: error: attempt to assemble code in [ABSOLUTE] space
    Kernel.asm:892: error: attempt to assemble code in [ABSOLUTE] space
    Kernel.asm:893: error: attempt to assemble code in [ABSOLUTE] space
    

    Was genau mache ich falsch, und was bedeutet diese Fehlermeldung im Detail (damit ich das für später mal weiß, falls ich wieder vor so einem Problem stehen sollte) 😕
    Danke schonmal, an alle!



  • Hallo,

    versuch es folgender Massen:
    ganz oben im Quelltext oder im *.inc-Datei schreibst du das:

    struc mytype 
    long_var:  resd 1 
    word_var:  resw 1 
    byte_var:  resb 1 
    buf_var:   resb 32 
    endstruc
    

    dann im Datensegment deklarierst und nach Bedarf initialisierst gleich du die Structur:

    mystruc:  istruc mytype 
              at long_var, dd 123456 
              at word_var, dw 1024 
              at byte_var, db 'x' 
              at buf_var,  db 'Hallo Welt', 13, 10, 0 
              iend
    

    😉



  • Im oberen Code hast du die Structure mytype festgelegt,

    im unteren hast du dann die Structurvariable von Typ mytype deklariert und initialisiert 😉



  • Hi,
    danke erstmal, kannst du mir denn auch ansatzweise sagen, wie ich das auf meine Struktur übertrage oder versteh ich gerade was falsch? Danke 😉



  • hi,
    also zuhächst den Datentyp festlegen:

    struc mystruct_type
    
     Signature        resb  4      ;Zeile 885
     EntryPoint       resw  1      ;Zeile 886
     PMInitialize     resw  1      ;Zeile 887
     BIOSDataSel      resw  1      ;Zeile 888
     A0000Sel         resw  1      ;Zeile 889
     B0000Sel         resw  1      ;Zeile 890
     B8000Sel         resw  1      ;Zeile 891
     CodeSegSel       resw  1      ;Zeile 892
     InProtectMode    resb  1      ;Zeile 893
     Checksum         resd  1      ;Zeile 894
    
    endstruc
    

    dann im Datensegment die Structurvariable deklarieren:

    segment .data
    PMInfoBlock:  istruc mystruct_type
                  at Signature,    db 'PMID'
                  at EntryPoint,   dw 0
                  at PMInitialize, dw 0
                  at BIOSDataSel,  dw 0
                  at A0000Sel,     dw 0A000h
                  at B0000Sel,     dw 0B000h
                  at B8000Sel,     dw 0B800h
                  at CodeSegSel,   dw 0C000h
                  at InProtectMode,db 0
                  at Checksum,     dd 0
                  iend
    

    hoffe du kommst klar damit am sonsten kann ich dir nur NASM-Documentation empfelen:
    http://ovh.dl.sourceforge.net/sourceforge/nasm/nasm-0.98.39-xdoc.zip



  • Aus dem NASM-Docu:

    4.8.5 STRUC and ENDSTRUC : Declaring Structure Data Types
    The core of NASM contains no intrinsic means of defining data structures; instead, the preprocessor
    is sufficiently powerful that data structures can be implemented as a set of macros. The macros
    STRUC and ENDSTRUC are used to define a structure data type.
    STRUC takes one parameter, which is the name of the data type. This name is defined as a symbol
    with the value zero, and also has the suffix _size appended to it and is then defined as an EQU
    giving the size of the structure. Once STRUC has been issued, you are defining the structure, and
    should define fields using the RESB family of pseudo-instructions, and then invoke ENDSTRUC to
    finish the definition.
    For example, to define a structure called mytype containing a longword, a word, a byte and a
    string of bytes, you might code
    struc mytype
    mt_long: resd 1
    mt_word: resw 1
    mt_byte: resb 1
    mt_str: resb 32
    endstruc
    The above code defines six symbols: mt_long as 0 (the offset from the beginning of a mytype
    structure to the longword field), mt_word as 4, mt_byte as 6, mt_str as 7, mytype_size as
    39, and mytype itself as zero.
    The reason why the structure type name is defined at zero is a side effect of allowing structures to
    work with the local label mechanism: if your structure members tend to have the same names in
    more than one structure, you can define the above structure like this:
    struc mytype
    .long: resd 1
    .word: resw 1
    .byte: resb 1
    .str: resb 32
    endstruc
    Thisd efinest heo ffsetst ot hes tructuref ieldsa sm ytype.long ,m ytype.word ,m ytype.byte
    and mytype.str .
    59
    NASM, since it has no intrinsic structure support, does not support any form of period notation to
    refer to the elements of a structure once you have one (except the above local-label notation), so
    code such as mov ax,[mystruc.mt_word] is not valid. mt_word is a constant just like any
    other constant, so the correct syntax is mov ax,[mystruc+mt_word] or
    mov ax,[mystruc+mytype.word] .
    4.8.6 ISTRUC , AT and IEND : Declaring Instances of Structures
    Having defined a structure type, the next thing you typically want to do is to declare instances of
    that structure in your data segment. NASM provides an easy way to do this in the ISTRUC
    mechanism. To declare a structure of type mytype in a program, you code something like this:
    mystruc:
    istruc mytype
    at mt_long, dd 123456
    at mt_word, dw 1024
    at mt_byte, db ’x’
    at mt_str, db ’hello, world’, 13, 10, 0
    iend
    The function of the AT macro is to make use of the TIMES prefix to advance the assembly position
    to the correct point for the specified structure field, and then to declare the specified data. Therefore
    the structure fields must be declared in the same order as they were specified in the structure
    definition.
    If the data to go in a structure field requires more than one source line to specify, the remaining
    source lines can easily come after the AT line. For example:
    at mt_str, db 123,134,145,156,167,178,189
    db 190,100,0
    Depending on personal taste, you can also omit the code part of the AT line completely, and start the
    structure field on the next line:
    at mt_str
    db ’hello, world’
    db 13,10,0


Anmelden zum Antworten