;multi-segment executable file template.
.model small
assume cs: code, ds: data
data segment
player db 0
startText1 db "Hello and welcome to 'Submarines'"
startText2 db "Please enter a game code 5 characters long"
streamRead db 7 dup(0)
fileName db 6 dup (0)
fileOpenError1 db "1 invalid funtion number"
fileOpenError2 db "Game not found, you're the host...."
fileOpenError3 db "3 path not found"
fileOpenError4 db "4 all available handles in use"
fileOpenError5 db "5 access denied"
fileOpenError6 db "6 invalid file handler"
fileOpenSucs db "Succsessfully joined game!"
fileHandler dw ?
readInfo db 405 dup(0)
writeInfo db 405 dup(0)
errors db "error ",'$' ;;
data ends
.stack
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
;;end of setting registers
call xorAll;; clearing all registers
call newScreen ;;setting up a screen for start screen 640x200
call borderOfScreen
;; start screen text:
mov bp, offset startText1
mov bl,0Eh
mov dx,0218h
mov cx,33
call colorTextDisplay
mov bp, offset startText2
mov bl,0Eh
mov dx,0412h
mov cx,42
call colorTextDisplay
;; end of start screen text
;; start reading file name and working with playerity
call xorAll
mov streamRead,6
mov dx, offset streamRead
mov ah, 0Ah
int 21h
call preapreFileName
call openFile;; error is handled inside the open file code
;; players are set and messages have been sent
mov cx,1
mov writeInfo,'1'
call writeBytes; when i use this the first byte of my file doesnt change to 1......
mov cx,1
call readBytes;l;; and this ready method doesnt work, btw there is no error output
mov dl,readInfo
mov ah,2
int 21h
call closeFile
call terminate
;; procedures:
proc terminate
mov ax, 4c00h
int 21h
ret
endp terminate
proc showErrorMsg
mov ah,09
mov dx, offset errors
int 21h
ret
endp showErrorMsg
proc preapreFileName
mov cx,5
mov bx,offset streamRead
add bx,2
loopFileName:
push [bx]
inc bx
loop loopFileName
mov cx,5
mov bx,offset fileName
add bx,4
loopFileName1:
pop ax
mov [bx],al
dec bx
loop loopFileName1
add bx,6
mov [bx],0
ret
endp preapreFileName
proc delay
mov dx,0FFFFh
startBig:
dec dx
mov ax,1
mov ax,2
mov ax,3
cmp dx,0
jne startBig
ret
endp delay
proc newScreen ;;640x200 ;; debugging use 3
mov ax, 000Eh
int 10h
ret
endp newScreen
proc colorTextDisplay;; BL is color as BACK|FORE BP is offset of text DX is as ROW|COL CX is length of string
mov ah, 13h
mov al ,01
mov bh,0
int 10h
ret
endp colorTextDisplay
proc createFile
mov ah, 13h
mov al, 01
mov bh, 0
mov bl,02h
mov dx, 0615h
int 10h
call xorAll
mov ah,3Ch
mov cl,2
mov dx, offset fileName
int 21h
mov fileHandler, ax
mov player,1
ret
endp createFile
proc borderOfScreen
call xorAll
mov bh,0
mov ah,0Ch
mov al,0Eh
mov cx,639
mov dx,199
rightSide:
int 10h
dec dx
cmp dx,0
jne rightSide
topSide:
int 10h
dec cx
cmp cx,0
jne topSide
leftSide:
int 10h
inc dx
cmp dx,199
jne leftSide
botSide:
int 10h
inc cx
cmp cx,639
jne botSide
mov cx,638
mov dx,198
rightSide1:
int 10h
dec dx
cmp dx,1
jne rightSide1
topSide1:
int 10h
dec cx
cmp cx,1
jne topSide1
leftSide1:
int 10h
inc dx
cmp dx,198
jne leftSide1
botSide1:
int 10h
inc cx
cmp cx,638
jne botSide1
ret
endp borderOfScreen
proc openFile
call xorAll
mov ah,3Dh
mov al,2
mov dx, offset fileName
int 21h
jc error
mov fileHandler, ax;; if there arent any errors display message:
mov player,2
mov bp, offset fileOpenSucs
mov ah, 13h
mov cx, 26
mov al, 01
mov bh, 0
mov bl,02h
mov dx, 0615h
;;end of message display
int 10h
jmp noError1
error:
call displayError
noError1:
ret
endp openFile
proc closeFile
call xorAll
mov ah,10h
mov bx, fileHandler
int 21h
ret
endp closeFile
proc failOpenFile
mov ah, 13h
mov al, 01
mov bh, 0
mov bl,04h
mov dx, 0615h
int 10h
ret
endp failOpenFile
proc xorAll
xor ax,ax
xor bx,bx
xor cx,cx
xor dx,dx
ret
endp xorAll
proc waitForClick
mov ah,0
int 16h
ret
endp waitForClick
proc readBytes;; cl is bytes to read
call xorAll
mov ah,3Fh
mov bx,fileHandler
mov dx,offset readInfo
int 21h
jc error
ret
endp readBytes
proc writeBytes;; cl is bytes to read
call xorAll
mov ah,40h
mov bx,fileHandler
mov dx,offset writeInfo
int 21h
jc error
ret
endp writeBytes
proc displayError
mov fileHandler, ax
cmp fileHandler,1
je error1
cmp fileHandler,2
je error2
cmp fileHandler,3
je error3
cmp fileHandler,4
je error5
cmp fileHandler,6
je error6
error1:
mov bp, offset fileOpenError1
mov cx, 24
call failOpenFile
ret
error2:
mov bp, offset fileOpenError2
mov cx,35
call createFile
ret
error3:
mov bp, offset fileOpenError3
mov cx,16
call failOpenFile
ret
error4:
mov bp, offset fileOpenError4
mov cx,30
call failOpenFile
ret
error5:
mov bp, offset fileOpenError5
mov cx,15
call failOpenFile
ret
error6:
mov bp, offset fileOpenError6
mov cx,22
call failOpenFile
ret
endp displayError
;; end of procedures.
code ends
end start ; set entry point and stop the assembler.
答案 0 :(得分:3)
这是您写入文件的方式:
mov cx,1
mov writeInfo,'1'
call writeBytes; when i use this the first byte of my file doesnt change to 1......
一切看起来都很好:字符串'1'
位于变量writeInfo
中,cx
是1
,因此应该将一个字符写入文件,但这是writeBytes
:
proc writeBytes;; cl is bytes to read
call xorAll ;◄■■ CX IS ZERO !!!
mov ah,40h
mov bx,fileHandler
mov dx,offset writeInfo
int 21h
jc error
ret
endp writeBytes
cx
为零(xor cx,cx
),这就是为什么零字节被写入文件的原因。只需删除call xorAll
。
顺便说一句,我发现了另一个错误:
proc closeFile
call xorAll
mov ah,10h ;◄■■ THIS VALUE SHOULD BE 3EH.
mov bx, fileHandler
int 21h
ret
endp closeFile