2016-04-10 10 views
0

Ich versuche, meine Quellen in besser organisierte Dateien aufzuteilen, aber ich stoße auf einige Probleme, einschließlich dieser Quellen.So fügen Sie andere Quellen in FASM ein

Wie schließe ich diese Quellen ein? Meine Hauptprogramme sind im PE64-Format, aber wenn ich das Format meiner Sub-Quellen einstelle, will Fasm es nicht kompilieren. Wenn ich es entferne, sagt Fasm etwas über das Ending includes (wie kernel64.inc) und schon vorhandene Symbole.

So versuche ich in die Hauptdatei include printInt.asm aufzunehmen. ich den Export mit:

export 'printLib.dll',\ 
    printInt, 'printInt' 

Dies ist die Unter Quelle:

;format PE64 

include 'win64a.inc' 

;entry start 

section '.code' code readable executable 
start: 
    mov rcx, 1234567 
    call printInt 
    call newline 
    mov rcx, -54321 
    call printInt 

; invoke ExitProcess, 0 

printInt: 
    push r10 
    push r11 
    push r12 
    push r13 
    push r14 
    sub rsp, 32 

    mov r12, rcx 
    mov r13, 10 
    xor r14, r14 

    test r12, r12 
    jns .e1 
     neg r12 
     mov rcx, 45 
     call [putchar]  
    .e1: 

    .l1: 
     mov rax, r12 
     mov rdx, 0 
     div r13 

     mov rcx, rdx 
     add rcx, 0x30 
     mov r12, rax 
     push rcx 
     inc r14 
     test r12, r12 
     jnz .l1 

    mov r12, r14  
    .l2: 
     pop rcx 
     sub rsp, 32 
     call [putchar] 
     add rsp, 32 
     dec r14 
     jnz .l2 

    add rsp, 32 
    pop r14 
    pop r13 
    pop r12 
    pop r11 
    pop r10 
ret 

newline: 
    sub rsp, 32 
    mov rcx, 0xa 
    call [putchar] 
    mov rcx, 0xd 
    call [putchar] 
    add rsp, 32 
ret 

rdtsc64x: 
    rdtsc 
    shl rdx, 32 
    add rax, rdx 
    mov rdx, 0 
ret 

;section '.rdata' data readable writeable 
; print1 db 'printInt downwards: ', 0 
; print2 db 'printInt upwards: ', 0 

section '.idata' import data readable writeable 

library kernel, 'kernel32.dll',\ 
    msvcrt, 'msvcrt.dll' 

;import kernel, ExitProcess, 'ExitProcess' 
import msvcrt, printf, 'printf',\ 
    putchar, 'putchar' 

Was ich darüber gefunden ist: FASM- passing parameters to an external procedure

Aber das ist für mich nicht funktioniert, und auch ist über ein anderes Format.

Wie kann ich meine eigenen Quellen im PE64-Format einbinden?

Antwort

0

Sie können Ihre .asm Dateien mit der include-Direktive, beispiels umfassen .:

include 'your_subroutines.asm' 

Der Inhalt Ihrer .asm Datei genau an der Position Ihrer Include-Direktive enthalten ist. Für Ihr Beispiel würde ich so etwas wie dies empfehlen:

section '.code' code readable executable 
start: 
    ;your code here 

printInt: 
    ;your code here 
    ret 

include 'your_subroutines.asm' 

section '.rdata' data readable writeable 
;... 

Aufgrund dieser Tatsache Ihre Subroutinen sind Teil des Codeabschnitts. Darüber hinaus ist 'win64a.inc' nur einmal am Anfang von main.asm und nicht in jeder Ihrer subroutine.asm-Dateien enthalten.

Verwandte Themen