gpt4 book ai didi

assembly - Windows : "undefined reference to ` print_string'"中的 NASM 汇编程序错误

转载 作者:行者123 更新时间:2023-12-04 03:44:58 25 4
gpt4 key购买 nike

当我试图在 Windows 上编译一个简单的汇编程序时,我遇到了奇怪的错误。这些错误使它看起来好像汇编程序不知道我使用的函数是什么,并且出于某种原因也将 Haskell 引入其中。

这是我在尝试编译时遇到的错误:

 C:\Users\Nick\Documents\COMP2210\>nasm -fwin32 first.asm

C:\Users\Nick\Documents\COMP2210\>gcc first.obj -o first
first.obj:first.asm:(.text+0xb): undefined reference to `print_string'
first.obj:first.asm:(.text+0x10): undefined reference to `read_int'
first.obj:first.asm:(.text+0x1f): undefined reference to `print_string'
first.obj:first.asm:(.text+0x24): undefined reference to `read_int'
first.obj:first.asm:(.text+0x3d): undefined reference to `sub_dump_regs'
first.obj:first.asm:(.text+0x4b): undefined reference to `sub_dump_mem'
first.obj:first.asm:(.text+0x55): undefined reference to `print_string'
first.obj:first.asm:(.text+0x5f): undefined reference to `print_int'
first.obj:first.asm:(.text+0x69): undefined reference to `print_string'
first.obj:first.asm:(.text+0x73): undefined reference to `print_int'
first.obj:first.asm:(.text+0x7d): undefined reference to `print_string'
first.obj:first.asm:(.text+0x84): undefined reference to `print_int'
first.obj:first.asm:(.text+0x89): undefined reference to `print_nl'
C:/Program Files (x86)/Haskell Platform/2012.4.0.0/mingw/bin/../lib/libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status

C:\Users\Nick\Documents\COMP2210\>

这是 NASM 代码:

;
; file: first.asm
; First assembly program. This program asks for two integers as
; input and prints out their sum.
;
; To create executable:
; Using djgpp:
; nasm -f coff -d COFF_TYPE first.asm
; gcc -o first first.o driver.c asm_io.o
;
; Using Borland C/C++
; nasm -f obj -d OBJ_TYPE first.asm
; bcc32 first.obj driver.c asm_io.obj

%include "asm_io.inc"
;
; initialized data is put in the .data segment
;
segment .data
;
; These labels refer to strings used for output
;
prompt1 db "Enter a number: ", 0 ; don't forget nul terminator
prompt2 db "Enter another number: ", 0
outmsg1 db "You entered ", 0
outmsg2 db " and ", 0
outmsg3 db ", the sum of these is ", 0


;
; uninitialized data is put in the .bss segment
;
segment .bss
;
; These labels refer to double words used to store the inputs
;
input1 resd 1
input2 resd 1


;
; code is put in the .text segment
;
segment .text
global _asm_main
_asm_main:
enter 0,0 ; setup routine
pusha

mov eax, prompt1 ; print out prompt
call print_string

call read_int ; read integer
mov [input1], eax ; store into input1

mov eax, prompt2 ; print out prompt
call print_string

call read_int ; read integer
mov [input2], eax ; store into input2

mov eax, [input1] ; eax = dword at input1
add eax, [input2] ; eax += dword at input2
mov ebx, eax ; ebx = eax
dump_regs 1
dump_mem 2, outmsg1, 1
;
; next print out result message as series of steps
;
mov eax, outmsg1
call print_string ; print out first message
mov eax, [input1]
call print_int ; print out input1
mov eax, outmsg2
call print_string ; print out second message
mov eax, [input2]
call print_int ; print out input2
mov eax, outmsg3
call print_string ; print out third message
mov eax, ebx
call print_int ; print out sum (ebx)
call print_nl ; print new-line

popa
mov eax, 0 ; return back to C
leave
ret

最佳答案

尝试:gcc driver.c first.obj asm_io.obj -o first.exe。如果尚未完成,则必须从 asm_io.asm 创建 asm_io.obj

driver.c 调用 asm_main(在您的代码中声明为 global)。 asm_io.inc 声明这些函数 extern(并提供宏来调用它们)。 asm_io.obj 包含函数。

博士。 Carter 的工作第一次开始工作有点棘手。它变得更容易。

关于assembly - Windows : "undefined reference to ` print_string'"中的 NASM 汇编程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15181871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com