我输入了四个ASCII字符:
ch1, ch2, ch3, ch4
.
我想检查4个字母的单词是否构成回文。
算法是正确的,但无法编译。你知道为什么吗?
;
; isPalindrom.asm
;
.MODEL SMALL
.STACK 100h
.DATA
ch1 DB ? ;var dec
ch2 DB ? ;var dec
ch3 DB ? ;var dec
ch4 DB ? ;var dec
PrintUSER DB 13,10
DB 'Pls enter 4 chars:',13,10,'$'
;Print 4 chars string
PaliExists DB 13,10
DB 'Palindrome permutation exists',13,10,'$'
;Print msg that pali exists
PaliNOTExists DB 13,10
DB 'There is no possible solution',13,10,'$'
;Print msg that pali does not exist
.CODE
ProgStart:
MOV AX,@DATA ; DS can be written to only through a register
MOV DS,AX ; Set DS to point to data segment
MOV AH,9
MOV DX, Offset PrintUSER
INT 21h
MOV AH,1
INT 21h ; Input to ch1
MOV ch1,AL
MOV AH,1
INT 21h ; Input to ch2
MOV ch2,AL
MOV AH,1
INT 21h ; Input to ch3
MOV ch3,AL
MOV AH,1
INT 21h
MOV ch4,AL ; Input to ch4
;////////////////////////////////
CMP ch1, ch2 ; Compare ch1,ch2
JE checkThreeFour ; jump to label checkTwoThree
JMP Skip1 ;Skip compare ch3,ch4
checkThreeFour: ;label
CMP ch3, ch4 ; Compare ch3,ch4
JE Exists ; Jump to Exists
JMP notExists
Skip1:
CMP ch1, ch3 ;Compare ch1,ch3
JE checkTwoFour ;Jump
JMP Skip2:
checkTwoFour:
CMP ch2, ch4 ;Compare ch2,ch4
JE Exists ; Jump to Exists
JMP notExists
Skip2:
CMP ch1, ch4 ;Compare ch1,ch4
JE checkTwoThree ;Jump
JMP notExists
checkTwoThree:
CMP ch2, ch3 ;Compare ch2,ch3
JMP Exists ; Jump to Exists
JMP notExists
Exists: ;print message for Existing pali
MOV AH,9
MOV DX, Offset PaliExists
INT 21h
JMP DisplayGreeting
notExists: ; print messasge palindrom does not exist
MOV AH,9
MOV DX, Offset PaliNOTExists
INT 21h
DisplayGreeting:
MOV AH,9 ; Set print option for int 21h
INT 21h ; Print chosen message
MOV AH,4Ch ; Set terminate option for int 21h
INT 21h ; Return to DOS (terminate program)
END ProgStart