我想使用NASM(example)在Linux中进行汇编编程。但是,我想避免在计算机上安装Linux。相反,我有一台安装Cygwin的64位Win7机器。
以下是我的测试程序:
section .data
text1 db "What is your name?"
text2 db "Hello "
section .bss
name resb 30
section .text
global start
start:
; display the prompt
mov rax, 1 ; specify std out
mov rdi, 1 ; specify write opeartion
mov rsi, text1 ; load the address of the variable
mov rdx, 19 ; write sizeof(text1) == 19 bytes
syscall ; tell the processor to accomplish the task
; take input from KB
mov rax, 0 ; specify std in
mov rdi, 0 ; specify read operation
mov rsi, name ; load the address of the variable
mov rdx, 30 ; read sizeof(name) == 30 bytes
syscall ; tell the processor to accomplish the task
; display "Hello "
mov rax, 1 ; specify std out
mov rdi, 1 ; specify write opeartion
mov rsi, text2 ; load the address of the variable
mov rdx, 7 ; write sizeof(text2) == 7 bytes
syscall ; tell the processor to accomplish the task
; display 'name'
mov rax, 1 ; specify std out
mov rdi, 1 ; specify write opeartion
mov rsi, name ; load the address of the variable
mov rdx, 30 ; write sizeof(name) == 30 bytes
syscall ; tell the processor to accomplish the task
; terminate program
mov rax, 60 ; specify program termination
mov rdi, 0 ; return without error
syscall
以下是我的汇编命令和输出:
Acer@Acer-PC ~
$ nasm -f elf64 name_io.asm -o name_io.o
Acer@Acer-PC ~
$ ld name_io.o -o name_io.exe
Acer@Acer-PC ~
$ ./name_io
Illegal instruction
Acer@Acer-PC ~
$
源代码正在汇编中,但未执行。
我该怎么做才能在Cygwin + Windows中正确组装并运行Linux组装程序?