2014-09-13 99 views
-1

我對這段代碼有一些問題。我需要計算連續數字的連續數字。我使用masm彙編語言。這裏是我的代碼:查找連續的最大連續位數

Extrn OutInt:Far  
data segment 
string db 100 dup ('$') 
string2 db 'Input the string!', 0dh,0ah, '$' 
string3 db 'Count - $' 
data ends 
code segment 
assume cs:code,ds:data 
start: 
    mov ax, data 
    mov ds, ax 
    mov ah,9 
    lea dx,string2 
    int 21h  
    mov ah,0ah 
    lea dx,string 
    int 21h  
    mov ah,9 
    lea dx,string3 
    int 21h 

    mov si,offset A 
    mov BX,0 
    mov DX,0 
    mov CX,100 
    looperunda: 
    lodsb 
    test AL,10000000b 
    je nosigno 
    cmp BX,DX 
    jnb neatral 
    mov BX,DX 
    xor DX,DX 
    jmp neatral 
    nosigno: 
    inc DX 
    neatral: 
    loop looperunda 

    mov ax, 16 
    Call OutInt 

code ends 
end start 

OutInt:

Title OutInt 
CodeSg Segment PARA 'Code' 
OutInt Proc FAR 
Assume CS:CodeSg 
Public OutInt 
aam 
add ax,3030h 
mov dl,ah 
mov dh,al 
mov ah,02 
int 21h 
mov dl,dh 
int 21h 

mov ah, 10h 
int 16h 
mov ax, 4c00h 
int 21h 
OutInt endp 
CodeSg ENDS 
END OutInt 

程序必須運行這樣的: 「 輸入字符串

aa23333c

計數 - 4 」

但是我的c頌歌不起作用。有誰能幫助我嗎?錯誤在哪裏?

回答

1

這可以通過一個簡單的循環完成:從字符串中取出每個字符,並將其ASCII碼作爲數組的索引。使用相應的數組索引來計算每個字符的數量並檢查最常用的字符。假設:沒有字符出現超過255次,只使用標準ASCII字符。

.data 

    myString byte "aa23333c", 0 
    countArray byte 255 DUP(0) 

.code 
    main PROC 

    mov bx, 0 ;// Exchange bx with eax in this line when using a 32 bit system 
    mov si, -1 
    STRING_LOOP: 
     inc si 
     movzx ax, BYTE PTR [myString+si] 
     add BYTE PTR [countArray+ax], 1 
     cmp BYTE PTR [countArray+ax], bl 
     jb NEXT_CHAR 
     mov bl, BYTE PTR [countArray+ax] 
     mov bh, BYTE PTR [myString+si] 
     NEXT_CHAR: 
     and ax, 0FFh 
    jnz STRING_LOOP 
    ;// character code is now in bh 
    ;// numer of iterations is now in bl 

main ENDP 

END main