2014-12-08 3 views
0

키보드 입력에서 파일 이름을 읽은 다음 화면에이 파일의 짝수 라인을 인쇄해야합니다. int의 3dh 함수를 사용하여 파일을 열었습니다 21h,하지만 내 질문에 짝수 라인을 인쇄하기 위해 한 줄씩 읽는 방법은 무엇입니까? 캐리지 리턴이나 라인 피드를 사용하는 방법을 정확히 이해하지 못했습니다. 여기에 내가 지금까지 한 일이다 :어셈블리의 파일에서 짝수 행을 읽습니다.

assume cs:code, ds:data 
data segment 
    msg db 'Give the name of the file: $' 
    fileName db 12,?,13 dup (?) 
    buffer db 21 dup (?) 
    openErrorMsg db 'The file does not exist.$' 
    handler dw 0 
data ends 
code segment 
start: 
    mov ax, data 
    mov ds, ax 

    mov ah, 09h 
    mov dx, offset msg 
    int 21h 

    mov ah, 0ah 
    mov dx, offset fileName 
    int 21h 

    mov bl, fileName[1] 
    mov bh, 0 
    add bx, offset fileName 
    add bx, 2 
    mov byte ptr [bx], 0 

    mov ah, 3dh 
    mov al, 0 
    mov dx, offset fileName+2 
    int 21h 

    jc openError 
    ; ?? - 

openError: 
     mov ah, 09h 
     mov dx, offset openErrorMsg 
     int 21h 
     jmp endPrg 
    endPrg: 
     mov ah, 3eh 
     mov bx, handler 
     int 21h 

     mov ax,4c00h 
     int 21h 

code ends 
end start 
+0

INTERRUP.F 당신이 Apparantly 히 붙어있는 시점에서 첫 번째 작업으로 반환 된 핸들을 저장하는 것을 잊지 마십시오. 그런 다음 Dirk Wolfgang Glomp가 제공 한 조언을 사용하여 파일을 처리하십시오. –

답변

1

캐리지 리턴 (0DH)과 라인 피드 (0AH)는 ASCII 코드에서 제어 문자의 일부입니다. 캐리지 리턴은 프린터 또는 디스플레이와 같은 다른 출력 시스템에 명령하여 커서 위치를 동일한 행의 첫 번째 위치로 이동합니다. 그리고 줄 넘김은 커서를 다음 줄로 이동시켜 함께 새로운 줄을 시작합니다. 출력이 마지막 줄에 있으면 화면의 내용이 위쪽으로 스크롤되고 출력은 새로운 빈 마지막 줄에서 시작됩니다.

텍스트 파일의 짝수 라인 만 인쇄하려는 경우 "0Dh, 0Ah"또는 최소한 "0Dh"의 바이트를 찾기 위해 바이트 단위로 텍스트를 비교해야합니다. 참고 : Linux 텍스트 파일에는 "0Ah"없이 "0Dh"만 포함됩니다. DOS 텔레타이프 출력 함수를 사용하려면 인쇄 할 텍스트 뒤에 "$"를 넣어야합니다.

파일을로드하려면 DOS 읽기 기능을 사용할 수 있습니다. 나는 한 단계에서 램에 전체 텍스트 파일을로드하고 다른 단계에서 비교하고 짝수 라인을 인쇄하는 것을 선호한다. 그러나 대안으로 한 단계에서 비교 및 ​​인쇄하고 다음 단계에서 다음 단일 바이트를로드하는 등의 작업을 위해 단일 바이트 만로드 할 수 있습니다.

RBIL-> inter61b.zip->

--------D-213F------------------------------- 
INT 21 - DOS 2+ - "READ" - READ FROM FILE OR DEVICE 
AH = 3Fh 
BX = file handle 
CX = number of bytes to read 
DS:DX -> buffer for data 
Return: CF clear if successful 
    AX = number of bytes actually read (0 if at EOF before call) 
CF set on error 
    AX = error code (05h,06h) (see #01680 at AH=59h/BX=0000h) 
Notes: data is read beginning at current file position, and the file position 
    is updated after a successful read 
the returned AX may be smaller than the request in CX if a partial 
    read occurred 
if reading from CON, read stops at first CR 
under the FlashTek X-32 DOS extender, the pointer is in DS:EDX 
BUG: Novell NETX.EXE v3.26 and 3.31 do not set CF if the read fails due to 
    a record lock (see AH=5Ch), though it does return AX=0005h; this 
    has been documented by Novell 
SeeAlso: AH=27h,AH=40h,AH=93h,INT 2F/AX=1108h,INT 2F/AX=1229h 
관련 문제