汇编程序无法正常打开和读取文本文件。它只是退出而没有做任何事情

时间:2018-01-16 11:27:45

标签: assembly dos tasm

有人可以告诉我,我做错了什么吗?我正在尝试打开一个文本文件,该文件与我的.asm文件位于同一目录中。文本文件包含一个短句作为消息,最多可包含200个字符。程序应该从.txt文件中读取消息,然后使用读取的句子进行进一步的工作。问题是它只是退出而没有做任何事情。我正在使用TASM进行编译。这是代码:

JUMPS
masm
model small
.data
handle  dw  0 
filename     db 'the_message.txt',0
point_fname dd  filename

string  db  200 dup (" ")
point_buffer dd string

errorMes db  0ah,0dh,'Not allowed any more!','$'
mes    db   0ah,0dh,'Type 1 to crypt, type 2 to decrypt!','$'
mes1   db   0ah,0dh,'Crypted one time ','$'
mes2   db   0ah,0dh,'Crypted two times ','$'
mes3   db   0ah,0dh,'Decrypted','$'
count  db   0
.stack  256
.code
main:
;open
mov ax,@data 
mov ds,ax 
mov al,0 
lds dx,point_fname 
mov ah,3dh 
int 21h
jc  exit 
mov [handle],ax
;read
mov bx,[handle]
mov cx,200
lds dx,point_buffer
mov ah,3fh 
int 21h
jc  exit
mov bp,ax 
nop
;close
mov ah,3eh 
int 21h
jc  exit
nop
;Now crypt and decrypt
jmp ask
crypt1: 
;test
cmp count,0
jg  crypt2

xor ax,ax   
mov cx,bp   
mov si,0    
go1:        
add string[si],1    
inc si  
loop    go1 
inc count
;print on the screen
mov cx,bp
mov si,0
mov ah,09h
lea dx,mes1
int 21h
jmp show


crypt2: 
;test
cmp count,1
jg  notAllowed

xor ax,ax 
mov cx,bp   
mov si,0    
go2:        
add string[si],2    
inc si  
loop    go2 
inc count
;print on the screen
mov cx,bp
mov si,0
mov ah,09h
lea dx,mes2
int 21h
jmp show


decrypt2:   
;test
cmp count,2
jl  decrypt1

xor ax,ax   
mov cx,bp   
mov si,0    
goDecr2:        
sub string[si],2    
inc si  
loop    goDecr2 
dec count
;print on the screen
mov cx,bp
mov si,0
mov ah,09h
lea dx,mes3
int 21h
jmp show


decrypt1:   
;test
cmp count,1
jl  notAllowed

xor ax,ax   
mov cx,bp   
mov si,0    
goDecr1:        
sub string[si],1    
inc si  
loop    goDecr1 
dec count
;print on the screen
mov cx,bp
mov si,0
mov ah,09h
lea dx,mes3
int 21h
;jmp show

show:
mov ah,02h  
mov dl,string[si]
int 21h
inc si
loop    show
ask:
mov ah,09h
lea dx,mes
int 21h

mov ah, 01h 
int 21h

cmp al, 31h
je  crypt1
jmp decrypt2

notAllowed:
mov ah,09h
lea dx,errorMes
int 21h
;jmp exit
exit: 
mov ax,4c00h 
int 21h 
end main

0 个答案:

没有答案