【发布时间】:2019-11-09 03:26:24
【问题描述】:
问题是找出序列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
【问题讨论】:
-
代码看起来正确。您在标题中指的是哪两种情况?
-
在您的示例中,您指定
10101计为两个匹配项,也许测试用例不允许对多个匹配项使用相同的位? -
@MargaretBloom 她没有告诉我它们是什么。我应该在做我的项目时考虑所有情况(这段代码是其中的一部分),我认为这段代码应该适用于所有这些,所以我不知道我的老师说这对他们不起作用的两种情况是什么意思。她在测试中告诉我,要更改解决方案,这样它就不会出现循环,它会解决它。但是我不知道从哪里开始或做什么,因为我不知道这些情况是什么。
-
@MichaelPetch 我会翻译它。您需要找到序列 101b 在数字中出现的次数。注意:您需要以循环方式检查数字(最后 3 个单词是用谷歌翻译翻译的)。我确定这个例子是正确的,它是不过轮换,因为我不明白作业,让我的老师给我解释一下,她就是这么给我解释的。
-
@MichaelPetch 它是希伯来语的。我应该只发布她给出的例子吗?
标签: assembly binary masm x86-16