您好*ers!
我对整个linux事物非常陌生,我正在使用Cygwin尝试执行以下操作.
将测试文件通过解析器…
./parser<测试test.asm //工作并生成ASM代码 按照本教程中的描述执行此行,我不确定它到底是做什么的… nasm -f elf test.asm //工作 最后一行创建可执行文件(如果我正确理解了本教程) ld -s -o测试test.o 我收到ld错误:输入文件test.o’的i386体系结构与此行上的i386:x86-64输出不兼容.我知道这是因为我正在尝试从32位升级到64位,但是我不知道该如何解决.我尝试使用elf_i386,但得到ld:无法识别的仿真模式:elf_i386.支持的仿真:i386pep i386pe. 任何和所有建议都非常感谢! 编辑: Test.asm文件
section .data
numbers db "0123456789", 0xA
inputchar db 0
section .text
global F_124565444
F_124565444:
push ebp
mov ebp, esp
sub esp, 4
mov dword [ebp-4], 0
jmp G2
G1:
add dword [ebp-4], 1
push edx
G2:
mov edx, 0
mov eax, [ebp+8]
mov ebx, 10
div ebx
mov [ebp+8], eax
cmp eax, 0
jnz G1
push edx
add dword [ebp-4], 1
jmp G3
G4:
sub dword [ebp-4], 1
pop edx
mov eax, 4
mov ebx, 1
mov ecx, numbers
add ecx, edx
mov edx, 1
int 80h
G3:
cmp dword [ebp-4], 0
jnz G4
mov eax, 4
mov ebx, 1
lea ecx, [numbers+10]
mov edx, 1
int 80h
leave
ret
global F_7362500
F_7362500:
push ebp
mov ebp, esp
sub esp, 4
mov dword [ebp-4], 0
mov byte [inputchar], 0
jmp G6
G5:
mov dword eax, [ebp-4]
mov ebx, 10
mul ebx
xor ecx, ecx
mov byte cl, [inputchar]
sub ecx, 48
add eax, ecx
mov dword [ebp-4], eax
G6:
mov eax, 03h
mov ebx, 00h
mov ecx, inputchar
mov edx, 01h
int 80h
cmp byte [inputchar], 0ah
jne G5
mov dword eax, [ebp-4]
leave
ret
global F_28052
F_28052:
push ebp
mov ebp, esp
push dword [ebp+8]
push dword 0
pop ebx
pop eax
cmp eax, ebx
sete al
movzx eax, al
push dword eax
pop eax
cmp eax, 0
je L1
push dword [ebp+12]
pop eax
leave
ret
jmp L2
L1:
push dword [ebp+8]
push dword [ebp+12]
push dword [ebp+12]
push dword [ebp+8]
pop ebx
pop eax
mov edx, eax
sar edx, 31
idiv ebx
push dword eax
push dword [ebp+8]
pop ebx
pop eax
imul eax, ebx
push dword eax
pop ebx
pop eax
sub eax, ebx
push dword eax
call F_28052
add esp, 8
push dword eax
pop eax
leave
ret
L2:
leave
ret
global _start
_start:
push ebp
mov ebp, esp
sub esp, 4
sub esp, 4
call F_7362500
add esp, 0
push dword eax
lea ebx, [ebp-4]
pop eax
mov dword [ebx], eax
call F_7362500
add esp, 0
push dword eax
lea ebx, [ebp-8]
pop eax
mov dword [ebx], eax
push dword [ebp-4]
push dword [ebp-8]
call F_28052
add esp, 8
push dword eax
call F_124565444
add esp, 8
push dword 0
pop eax
leave
mov ebx, eax
mov eax,1
int 80h
leave
mov ebx, eax
mov eax,1
int 80h
解决方法:
从您的问题和评论看来,您可能已经导致相信Cygwin与Linux相同.事实并非如此. Cygwin是一个类似Unix的posix兼容环境,可以在Windows上本地运行:
Cygwin is a Unix-like environment and command-line interface for Microsoft Windows. Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment. Thus it is possible to launch Windows applications from the Cygwin environment, as well as to use Cygwin tools and applications within the Windows operating context.
特别是在Windows上运行时,所有使用int 80h系统调用的Linux特定代码都将失败,因为它不适用于Windows环境.
如果要创建在Linux上运行的代码,则需要安装Linux.您可以通过在Windows上运行虚拟机软件并在其中安装一种Linux来实现(Ubuntu是很多人的选择).