我想在Cygwin 32位上使用nasm進行彙編(第四部分Dandamudi,Sivarama P. Linux中彙編語言編程指南 New York:Springer, 2005)。nasm/ld未能做到%include在cygwin上
不過,我得到以下錯誤:
$ nasm -f win32 sample.asm
$ nasm -f win32 io.mac
$ ld -m i386pe io.obj -lc sample.obj -o sample.exe
sample.obj:sample.asm:(.text+0x7): undefined reference to `proc_PutStr'
sample.obj:sample.asm:(.text+0x19): undefined reference to `proc_GetStr'
sample.obj:sample.asm:(.text+0x26): undefined reference to `proc_PutStr'
sample.obj:sample.asm:(.text+0x2e): undefined reference to `proc_GetInt'
sample.obj:sample.asm:(.text+0x3e): undefined reference to `proc_PutStr'
sample.obj:sample.asm:(.text+0x49): undefined reference to `proc_PutInt'
sample.obj:sample.asm:(.text+0x56): undefined reference to `proc_PutStr'
sample.obj:sample.asm:(.text+0x63): undefined reference to `proc_GetCh'
sample.obj:sample.asm:(.text+0x80): undefined reference to `proc_PutStr'
sample.obj:sample.asm:(.text+0x8c): undefined reference to `proc_PutStr'
sample.obj:sample.asm:(.text+0x92): undefined reference to `proc_nwln'
$
現在,io.mac有參考外部程序(如proc_GetStr和proc_GetCh,我以爲來自外部庫),但我做不到找到如何引用這些外部信息。
任何人都可以建議我該怎麼辦?
下面是各種代碼/闡述:
$ cat sample.asm
;An example assembly language program SAMPLE.ASM
;
; Objective: To demonstrate the use of some I/O
; routines and to show the structure
; of assembly language programs.
; Inputs: As prompted.
; Outputs: As per input.
%include "io.mac"
.DATA
name_msg db 'Please enter your name: ',0
query_msg db 'How many times to repeat welcome message? ',0
confirm_msg1 db 'Repeat welcome message ',0
confirm_msg2 db ' times? (y/n) ',0
welcome_msg db 'Welcome to Assembly Language Programming ',0
.UDATA
user_name resb 16 ; buffer for user name
response resb 1
.CODE
.STARTUP
PutStr name_msg ; prompt user for his/her name
GetStr user_name,16 ; read name (max. 15 characters)
ask_count:
PutStr query_msg ; prompt for repeat count
GetInt CX ; read repeat count
PutStr confirm_msg1 ; confirm repeat count
PutInt CX ; by displaying its value
PutStr confirm_msg2
GetCh [response] ; read user response
cmp byte [response],'y' ; if 'y', display welcome message
jne ask_count ; otherwise, request repeat count
display_msg:
PutStr welcome_msg ; display welcome message
PutStr user_name ; display the user name
nwln
loop display_msg ; repeat count times
.EXIT
$ cat io.mac
extern proc_nwln, proc_PutCh, proc_PutStr
extern proc_GetStr, proc_GetCh
extern proc_PutInt, proc_GetInt
extern proc_PutLInt, proc_GetLInt
;;-------------------------------------------------------------------
%macro .STARTUP 0
;group dgroup .data .bss
global _start
_start:
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro .EXIT 0
mov EAX,1
xor EBX,EBX
int 0x80
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro .DATA 0
segment .data
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro .UDATA 0
segment .bss
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro .CODE 0
segment .data
segment .bss
segment .text
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro nwln 0
call proc_nwln
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro PutCh 1
push AX
mov AL,%1
call proc_PutCh
pop AX
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro PutStr 1
push ECX
mov ECX,%1
call proc_PutStr
pop ECX
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro GetStr 1-2 81
push ESI
push EDI
mov EDI,%1
mov ESI,%2
call proc_GetStr
pop EDI
pop ESI
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro GetCh 1
push SI
xor SI,SI
%ifidni %1,AL
;inc SI
call proc_GetCh
%elifidni %1,AH
mov SI,1
call proc_GetCh
%else
push AX
call proc_GetCh
mov %1,AL
pop AX
%endif
pop SI
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro PutInt 1
push AX
mov AX,%1
call proc_PutInt
pop AX
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro GetInt 1
%ifnidni %1,AX
push AX
call proc_GetInt
mov %1,AX
pop AX
%else
call proc_GetInt
%endif
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro PutLInt 1
push EAX
mov EAX,%1
call proc_PutLInt
pop EAX
%endmacro
;;-------------------------------------------------------------------
;;-------------------------------------------------------------------
%macro GetLInt 1
%ifnidni %1,EAX
push EAX
call proc_GetLInt
mov %1,EAX
pop EAX
%else
call proc_GetLInt
%endif
%endmacro
;;-------------------------------------------------------------------
$ objdump -t io.obj
io.obj: file format pe-i386
SYMBOL TABLE:
[ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x00000000 io.mac
File
[ 2](sec -1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 .absolut
[ 3](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_nwln
[ 4](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_PutCh
[ 5](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_PutStr
[ 6](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_GetStr
[ 7](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_GetCh
[ 8](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_PutInt
[ 9](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_GetInt
[ 10](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_PutLInt
[ 11](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_GetLInt
[ 12](sec -1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000001 @feat.00
$ objdump -t sample.obj
sample.obj: file format pe-i386
SYMBOL TABLE:
[ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x00000000 sample.asm
File
[ 2](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .data
AUX scnlen 0x95 nreloc 0 nlnno 0
[ 4](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .bss
AUX scnlen 0x11 nreloc 0 nlnno 0
[ 6](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .text
AUX scnlen 0xa1 nreloc 20 nlnno 0
[ 8](sec -1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 .absolut
[ 9](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_nwln
[ 10](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_PutCh
[ 11](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_PutStr
[ 12](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_GetStr
[ 13](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_GetCh
[ 14](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_PutInt
[ 15](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_GetInt
[ 16](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_PutLInt
[ 17](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 proc_GetLInt
[ 18](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 name_msg
[ 19](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000019 query_msg
[ 20](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000044 confirm_msg1
[ 21](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x0000005c confirm_msg2
[ 22](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x0000006b welcome_msg
[ 23](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 user_name
[ 24](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000010 response
[ 25](sec 3)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _start
[ 26](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x0000001f ask_count
[ 27](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000079 display_msg
[ 28](sec -1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000001 @feat.00
$
我(這在Cygwin/NASM作品)決定放棄從_Guide的I/O方案到Linux_中的彙編語言編程,並使用Paul Carter的PC彙編語言(適用於Cygwin/nasm)。北卡羅來納州羅利:露露出版社,2007年 – boardrider 2014-12-07 15:17:21