我正在做一个项目,该项目将我编写的子例程附加到老师包含的主文件中。他给了我们使子程序全局化的说明,但显然我是个白痴。这两个 asm 文件位于同一文件夹中,我正在使用nasm -f elf -g prt_dec.asm,ld prt_dec然后对 main.asm 执行相同的操作。main.asm中的相关代码如下:
SECTION .text ; Code section.
global _start ; let loader see entry point
extern prt_dec
_start:
mov ebx, 17
mov edx, 214123
mov edi, 2223187809
mov ebp, 1555544444
mov eax, dword 0x0
call prt_dec
call prt_lf
Run Code Online (Sandbox Code Playgroud)
当我使用时,该行call prt_dec抛出“对 prt_dec 的未定义引用”ld main.o
这是我的 prt_dec.asm 中的代码段:
Section .text
global prt_dec
global _start
start:
prt_dec:
(pushing some stuff)
L1_top:
(code continues)
Run Code Online (Sandbox Code Playgroud)
您想调用另一个 asm 文件或目标文件中的例程吗?如果您正在组装 prt_dec.asm 并链接多个 asm 文件以在主程序中使用,这里有一个示例,2 个 asm 文件已组装并链接在一起... * 注意 * hello.asm * 没有 *有一个开始标签!
主asm文件:hellothere.asm
sys_exit equ 1
extern Hello
global _start
section .text
_start:
call Hello
mov eax, sys_exit
xor ebx, ebx
int 80H
Run Code Online (Sandbox Code Playgroud)
第二个 asm 文件: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
Run Code Online (Sandbox Code Playgroud)
生成文件:
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
Run Code Online (Sandbox Code Playgroud)
现在,如果您只想将代码分成多个 asm 文件,您可以将它们包含到您的主源代码中: with%include "asmfile.asm"位于主源文件的开头,然后汇编并链接您的主文件。
| 归档时间: |
|
| 查看次数: |
4753 次 |
| 最近记录: |