2017-01-30 8 views
1

Fasm의 설명서를 읽었지만 이해할 수 없습니다.Fasm 어셈블리의 구조 선언 및 초기화 정보

section ".bss" 

    struc my_struct 
     .a resw 1 
     .b resw 1 
     .c resb 1 
     .d resb 1 
    endstruc 

    section ".data" 

    my_struct_var1 istruc my_struct 
     at my_struct.a, dw 123 
     at my_struct.b dw, 0x123 
     at my_struct.c db, "fdsfds" 
     at my_struct.d db 2222 
    endstruc 

을 내가 정확히 FASM에서이 작업을 수행 할 수 있습니다 방법 : NASM에서 내가 먼저 ".DATA"에서 정의하고 ".bss라고"에서 구조체를 선언하고거야?

; declaring 

struct my_struct 
    .a rw 1 
    .b rw 1 
    .c rb 1 
    .d rb 1 
ends 

; or maybe this way? 
; what's the difference between these 2? 

struct my_struct 
    .a dw ? 
    .b dw ? 
    .c db ? 
    .d db ? 
ends 

1) 첫째, 맞습니까? 아니면 매크로 "sturc {...}"를 사용해야합니까? 그렇다면 정확히 어떻게해야합니까?

2) 둘째, 어떻게 ".data"로 초기화 할 수 있습니까?

3) 또한 FASM의 struc 거의 유일한 전면 레이블로 이름, macro와 같은 리눅스 (64)

+1

내가 FASM 메세지를 지정하지 않고 보드에 https를 추천 할 것입니다 : 당신이 매크로 FASM struct을 사용하지 않으려면

, 당신은 여전히 ​​방법에 따라 기본 FASM 구문을 사용하여 초기화 된 구조를 정의 할 수 있습니다 //board.flatassembler을 .net 더 나은 대답을 위해서 – Slai

+0

나는 nasm을 모른다. 그러나 보통 "rb/rw/rd"는 바이트/단어/더블 워드를 "예약"하고 전혀 건드리지 않는다 (초기화되지 않았다). "db?/dw?/dd?"도 마찬가지입니다. 초기화하려면 "db/dw/dd 값"을 사용해야합니다. 'dw 2000' (VALUE 2000의 단어) 또는'db 20' (바이트 20). 'rw 2000'은 2000 단어의 블록을 예약 할 것입니다 – Tommylee2k

+0

@ 토리 토 (Torito) 나는 모든 엉덩이와 잘 어울리지 않아 일반화하지 않습니다. 나는 그것들 모두 (대부분?)에 대해 동일하다고 생각할 수 있습니다. – Tommylee2k

답변

2

을위한 응용 프로그램입니다 내 코드

주에 질문이있다.

struct은 실제로 매크로를 사용하므로 쉽게 정의 할 수 있습니다.

당신이 FASM를 사용하는 경우

struct 매크로가 정의 파일을 포함, 다음 코드는 구조를 초기화 할 수 있습니다 :

; declaring (notice the missing dots in the field names!) 

struct my_struct 
    a dw ? 
    b dw ? 
    c db ? 
    d db ? 
ends 

; using: 

MyData my_struct 123, 123h, 1, 2 

당신은 FASM structWindows programming headers 설명서에 매크로 구현에 대한 자세한 내용을보실 수 있습니다.

; definition (notice the dots in the field names!) 

struc my_struct a, b, c, d { 
    .a dw a 
    .b dw b 
    .c db c 
    .d db d 
} 

; in order to be able to use the structure offsets in indirect addressing as in: 
; mov al, [esi+mystruct.c] 

virtual at 0 
    my_struct my_struct ?, ?, ?, ? 
end virtual 

; using: 

MyData my_struct 1, 2, 3, 4