2016-11-27 33 views
2

我正在爲我的計算機體系結構類的任務,我不明白大會。我應該從鍵盤上輸入一個字符串,並檢查它是否是迴文。我不允許使用INT 21h。我編寫的程序爲db string value而不是鍵盤輸入,但我仍然無法讓我的CMP正常工作。我很確定我做錯了。希望有人能幫助。檢查字符串迴文沒有INT 21h在em 8086

#make_COM# 

include emu8086.inc 


org 100h 

jmp init  

    msg db  "kayak",0   

init: 
    Mov SI,5 
    mov di,0 
start: 

    mov al,msg[si] 
    dEC si 
    inc di 

    mov ah ,0eh 
    int 10h 
    cmp si, -1 
    jg start 

check: 

    mov al, msg[si] 
    mov ah, msg[di] 
    cmp al, ah 
    jmp notpalin 
    inc si 
    dec di 
    cmp si, 5 
    jl check 

palin: 

    call pthis 
    db "This is a palindrome", 0 
    jmp stop 

notpalin: 

    call pthis 
    db "This is not a palindrome", 0 
    jmp stop 

stop: 
    mov  ah, 0 
    int  16h  ; wait for any key.... 
    ret ; return to operating system. 

DEFINE_PTHIS 

回答

3
  • 你必須在4開始SI寄存器中的5代替有了你理線,你不希望顯示與BIOS電傳打字機的功能NULL字符數5。

  • 你的程序開始檢查部分將一個SI寄存器包含-1。這顯然不是mov al, msg[si]的正確內存參考。

  • 當您比較2個字符時,您需要使用條件跳轉。你用了一個總是跳躍的跳躍!

    cmp al, ah 
    jNE notpalin 
    
  • 您可以停止一旦指標檢查SIDI彼此交錯。

解決辦法:

mov si, 0 
    mov di, 4 
check: 
    mov al, msg[si] 
    mov ah, msg[di] 
    cmp al, ah 
    jne notpalin 
    inc si 
    dec di 
    cmp si, di 
    jb check 
+0

哇哦,我很多接近然後我意識到。監督失誤。感謝您的解決方案@Sep Roland,幫助我瞭解自己出錯的地方。 – remedy