nasm calling subroutine from another file

风流意气都作罢 提交于 2019-12-01 08:32:23

You want to call a routine in another asm file or object file? if you are Assembling prt_dec.asm and are linking multiple asm files to use in your main program, here is a sample, 2 asm files Assembled and linked together... * NOTE * hello.asm *DOES NOT * have a start label!

Main asm file: hellothere.asm

sys_exit    equ 1

extern Hello 
global _start 

section .text
_start:
    call    Hello

    mov     eax, sys_exit
    xor     ebx, ebx
    int     80H

Second asm file: hello.asm

sys_write   equ 4
stdout      equ 1

global Hello

section .data
szHello     db  "Hello", 10
Hello_Len   equ ($ - szHello)

section .text
Hello:
        mov     edx, Hello_Len
        mov     ecx, szHello
        mov     eax, sys_write
        mov     ebx, stdout
        int     80H   
    ret

makefile:

APP = hellothere

$(APP): $(APP).o hello.o
    ld -o $(APP) $(APP).o hello.o

$(APP).o: $(APP).asm 
    nasm -f elf $(APP).asm 

hello.o: hello.asm
    nasm -f elf hello.asm

Now, if you just want to separate your code into multiple asm files, you can include them into your main source: with %include "asmfile.asm" at the beginning of your main source file and just assemble and link your main file.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!