如何检查寄存器是否可以被 7 整除? [英] How can I check if a register is evenly divisible by 7?

查看:43
本文介绍了如何检查寄存器是否可以被 7 整除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查寄存器 ax 的值是否可以被 7 整除,余数 = 0.我该怎么做?

I want to check if the value of the register ax is divisible by 7, with remainder = 0. How can I do it?

推荐答案

您可以使用与此答案中所示相同的方法,当然有不同的常数.

You can use the same way as shown in this answer, with different constants of course.

7 mod 216 的模乘逆是 0x6db7,这(根据定义)意味着 x = n * 7 形式的数字将服从 x * 0x6db7 = n,其中 n 将小于或等于 0xffff/7.所以如果你从 x * 0x6db7 中得到更大的东西,你知道它不是 7 的倍数.此外,非 7 的倍数也不能映射到低结果,因为乘以一个奇数模 a二的幂是双射的.

The modular multiplicative inverse of 7 mod 216 is 0x6db7, which (by definition) means that numbers of the form x = n * 7 will obey x * 0x6db7 = n, where n will be less than or equal to 0xffff / 7. So if you get something bigger out of x * 0x6db7, you know it's not a multiple of 7. Also, non-multiples of 7 cannot also map to low results, because multiplication by an odd number modulo a power of two is bijective.

所以你可以使用(未​​测试)

So you can use (not tested)

imul ax, ax, 0x6db7
cmp ax, 0x2492
ja not_multiple_of_7

这当然适用于无符号数.

This is for unsigned numbers of course.

作为奖励,ax 将是原始值除以 7 iff 它是 7 的倍数.

As a bonus, ax will be the original value divided by 7 iff it was a multiple of 7.

这篇关于如何检查寄存器是否可以被 7 整除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆