-1

我正在尝试使用汇编编写一个凯撒密码程序。没有错误,但是当它运行时什么都没有显示,它会静默退出。这是我写的。。

.MODEL small
.STACK 64
.DATA

  ORG     0000h            ;Start of code   
  MSG1 DB "Please input your string [Max 15 chars]: $"
  int 21h
  KEY1 DB "Please input your required shift  [RANGE 0 -F]: $"
  MSG2 DB "YOUR ENCRYPTED MESSAGE  IS : $"
  ErrorKey DB "Key Value out of range-please renter it range 0-F : $"
  STR1 DW 15 DUP('$') ;store plain text
  KEYV DB ?  ;to store the value of the key 
  STR2 DW 15 DUP(?); store encrypted message

.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX

;to display message 1 
MOV DX, OFFSET MSG1
MOV AH,09H
INT 21H               

;now the user enters the message
mov ax, 0000h
int 16h

mov ax, 0000h ; This key press it just to pause the program so you can see.
Int 16h       ; that you can’t see your own input
mov STR1,ax ;moving the message to be stored in str1

;to display Key message 
MOV DX, OFFSET KEY1
MOV AH,09H
INT 21H           


;now the user enters the key
KEY:
mov al, 0000h
int 16h

mov ax, 0000h ; This key press it just to pause the program so you can see.
Int 16h       ; that you can see your own input
mov KEYV,al ;moving the message to be stored in KEYV        


;now checking that the value of the key is within the correct range
CHECK: 
CMP KEYV,0FH  ;
JG show;       if value greater than F go to show
CMP KEYV,10H  ; if value below or equal F go to encrypt
JB ENCRYPT ; 

show:   
;to display Error Key message 
MOV DX, OFFSET ErrorKey
MOV AH,09H
INT 21H           
;restore the key value         
Jp KEY



 ENCRYPT:   MOV SI,OFFSET STR1  ;put the message in SI
            MOV BL,KEYV
            MOV DI,OFFSET STR2 
            MOV CX,15   

 ENCPROCESS:             
            MOV AL ,BYTE PTR[SI]  ;move first byte of PT in AL
            ADD  AL,BL   ;37 Add to it the key value
            MOV [DI],AL;     ;store the encrypted byte in DI
            INC SI 
            INC DI
            LOOP ENCPROCESS 


 ;to display encrypted message
MOV DX, OFFSET STR2
MOV AH,09H
INT 21H   




MAIN ENDP
END MAIN

我究竟做错了什么?

4

1 回答 1

0

Put breakpoints in it/debug it section by section to narrow down the problem

Then when you find the problem you can be more specific if you can't fix it

Your alternative is to hope that some kind soul will trawl their way through your entire program

于 2013-05-21T00:35:44.093 回答