这段代码没有解决哪两种情况?

Which 2 cases aren't solved with this code?

问题是找出序列 101b 在一个 16 位数字中出现了多少次,包括旋转。

示例:在数字 1001011001010110b 中,序列出现了 4 次。 3 你可以直接看到(包括一对共享 1 位的重叠对)和一个从低到高的环绕。特别是位索引 1、0、15(其中位 0 是最右边的位)

希伯来语版本:(请求)

nibble הוא מספר בגודל מילה המורכבת מארבעה Fournibble של אבעה תווים שקולטים בסדר הבא: מהתו הראשון קולטים לוקחים את 4 סיביות שמאליות. מהתו השני שקולטים קולטים לוקחים את 4 סיביות ימניות. מהתו השלישי שקולטים קולטים לוקחים את 4 סיביות שמאליות. מהתו הרביעי שקולטים קולטים לוקחים את 4 סיביות ימניות. .ארבעה תווים N צריך לקלוט .אחד FourNibbleמכל ארבעה תווים רצופים שקולטים מייצרים .fournibbles את המספרים שמייצרים שומרים במערך עבור כל מספר שקלטנו צריך למצוא כמה פעמים הרצף 101נמצא במספר. הערה: צריך לבדוק את הרצף בצורה מעגלית. במספר הבינארי 010000101 הרצף מופיע פעמיים.

在用希伯来语版本编写的示例中,我的老师写道该序列出现了两次。

这段代码对我有用,我用一些数字对其进行了测试。我不明白 在什么情况下它不起作用。

DATASEG
N equ 3
address dw ?        ;a variable that stores address of a function
address2 dw ?       ;a variable that stores address of a function inside other function
msg1 db 'enter 4 characters'
input db 7*N dup (?)      ;The input of the user
FourNibbles dw N dup(0)   ;An array to store the FourNibbles
results db N dup(0)       ;An array to store the results
.
.
.
proc FindResults; A Function that pushes the FourNibble and the results index of this FourNibble to the BinaryCheck function
    pop[address]
    mov di,offset FourNibbles
    mov si,offset results
    mov dx,N
CheckThisFourNibble:
    call SaveRegisters
    push si
    push [di]
    call BinaryCheck
    call GetRegisters
    inc si
    add di,2
    loop CheckThisFourNibble
    push[address]
    ret
endp FindResults

proc BinaryCheck
   pop[address2]    ; the return address
   pop dx           ;The 16 bit input number
   pop bx           ;the result address.
   mov cx,16 
Check:   
   push dx
   and dx,0111b
   cmp dx,101b
   jne Again
   inc[byte ptr bx]
Again:
   pop dx
   rol dx,1
   loop Check
   push[address2]
   ret
endp BinaryCheck

In the example that is written with the Hebrew version,my teacher wrote that the sequence appears twice.

例子是“010000101”。

010000101
      ***  1st
**      *  2nd

但这只有在您在 8 位边界处进行换行时才会发生。作为一个 16 位数字,它是 00000000 010000101 并且您正确地发现它只有一个 101.

I don't understand for what cases it doesn't work.

您没有事先将 [bx] 处的计数器清零。那肯定是它无法正常工作的情况。 (return 寄存器中的计数器值比让调用者传递指针更容易。)

pop 是怎么回事?如果这是一个过程,第一个 pop 将保存 return 地址。在 16 位代码中访问堆栈参数的正常方法是使用 BP 创建一个帧指针。

    push    bp
    mov     bp, sp
    mov     dx, [bp+4] ; The 16 bit number
    mov     bx, [bp+6] ; The results address
    mov     cx, 16
    mov     [bx], ch   ; CH=0
Check:   
    mov     ax, dx
    and     ax, 111b
    cmp     ax, 101b
    sete    al
    add     [bx], al
    ror     dx, 1
    dec     cx
    jnz     Check
    pop     bp
    ret     4

或者,如果您需要此版本的 8086 兼容版本(计算 ZF=1 结果来自 cmp 而没有 sete),请参阅

上的答案

您的号码“1001011001010110”:

1001011001010110
           ***   1st
         ***     2nd
   ***           3rd
*             ** 4th

来自问题中的更新代码

loop CheckThisFourNibble

CX 寄存器未初始化。您已经使用 DX 进行迭代,所以写:

dec dx
jnz CheckThisFourNibble
msg1 db 'enter 4 characters'

我很惊讶 msg1 没有像 0 或“$”这样的终止符。