시스템 호출을 사용하여 Ubuntu 11.04의 NASM에서 cat>filename
명령을 구현하려고합니다. 내 프로그램이 성공적으로 컴파일되고 성공적으로 실행된다. 하지만 언제든지 cat filename
명령을 실행하려고하면 "No such file or directory"라는 메시지가 표시되지만 디렉토리에있는 파일을 볼 수 있습니다. 더블 클릭으로 파일을 열려고하면 "파일을 여는 데 필요한 권한이 없습니다."라는 메시지가 나타납니다. 내 코드에서 오류를 찾도록 도와 주시겠습니까?NASM에서 cat> fileName 명령을 구현하십시오.
코드는 다음입니다 :
section .data
msg: dd "%d",10,0
msg1: db "cat>",0
length: equ $-msg1
section .bss
a resb 100
len1 equ $-a
b resd 1
c resb 100
len2 equ $-c
section .txt
global main
main:
mov eax,4 ;;it will print cat>
mov ebx,1
mov ecx,msg1
mov edx,length
int 80h
start:
mov eax,3 ;;it will take the file name as input
mov ebx,0
mov ecx,a
mov edx,len1
int 80h
mov eax,5 ;;it will create the file by giving owner read/write/exec permission
mov ebx,a
mov ecx,0100
mov edx,1c0h
int 80h
cmp eax,0
jge inputAndWrite
jmp errorSegment
inputAndWrite:
mov [b],eax
mov eax,3 ;;take the input lines
mov ebx,0
mov ecx,c
mov edx,len2
int 80h
mov edx,eax ;;write the input lines in the file
mov eax,4
mov ebx,[b]
mov ecx,c
int 80h
jmp done
errorSegment:
jmp done
done:
mov eax, 1
xor ebx, ebx
int 80h
추신을 위의 코드는 RageD에서 제안을 받아서 다시 편집합니다. 그러나, 내가 만든 파일에는 "inputAndWrite"세그먼트에서 주어진 입력 줄이 포함되어 있지 않습니다. 나는 너의 제안을 찾고있다.
'cat'을 다시 구현하려합니까 (즉, 파일을 연결하고 STDOUT에 인쇄하십시오) 아니면'cp '와 같은 파일을 복사하는 프로그램을 만드시겠습니까? 두 경우 모두'cat filename'으로 프로그램을 테스트하기 전에'which cat'을 체크 했습니까? 데비안 Wheezy에서'cat'은'/ bin/cat'을 출력합니다. – nrz
@nrz : 구현하려고합니다 : cat> file1. 이 명령을 실행 한 후 file1은 명령 행에서 주어진 입력 행을 포함합니다. 하지만 내 프로그램을 실행 한 후 file1이 만들어졌지만 whenevr "파일을 여는 데 필요한 권한이 없습니다."라는 파일을 열려고 시도했습니다. – sabu