Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly MASM:检查4个字符是否是回文_Assembly_Masm - Fatal编程技术网

Assembly MASM:检查4个字符是否是回文

Assembly MASM:检查4个字符是否是回文,assembly,masm,Assembly,Masm,我输入四个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

我输入四个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

您正在比较内存中的两个内存操作数

CMP chX, chY ;Compare ch2,ch3
指示。在英特尔ISA上,您不能这样做。一个参数必须始终是寄存器,有关详细信息,请参阅

因此,解决方案是先将
MOV
一个参数放入寄存器,然后应用
CMP

注意:检查4字符字符串是否为回文的一个简单解决方案是:

mov eax, dword ptr [string]
mov edx, eax
bswap edx
cmp eax, edx
je palindrome
no_palindrome:
...
jmp end
palindrome:
...
end:

非常感谢你投了一个巨大的代码块,没有提到哪一行有错误,或者错误消息是什么。如果你要发布一个“修复我的编译错误”的问题,至少把编译错误放在这个问题上,这样以后人们在搜索错误消息时可能会发现这个问题。