TEST指令如何检查汇编语言中的数字是偶数还是奇数
how TEST instruction check if number is EVEN or ODD in assembly language
我知道如果我们这样做,
mov al, 101b
test al, 100b
如果数字是 even 它将把零标志设置为 1,如果它是 odd 它将标志重置为 0 .
but what i dont understand is that if it checks the number is even or
not why it requires two operands?
应该是
test al
我也知道测试类似于操作,只是它不改变第一个操作数,但问题仍然是
How it know if number is even or odd by performing AND?
很难将其格式化为评论...
mov al, 101b ; moves the value 101b (5) into al
test al, 100b ; performs a AND between al and the 100b (4) and sets some flags
所以它应该将零标志设置为 0,将符号标志设置为 0,并将奇偶校验标志设置为 1...
我想我想知道是否有什么奇怪的地方 test al, 1b
然后检查零标志
如果你有一个字节0xff AND 0x1
,结果将为非零的 0x1...零标志将为 0(如果使用 test
),因此它表示奇数。
我想我现在明白了,如何使用测试来判断数字是偶数还是奇数!!!
你只需要检查数字的最低有效位,
示例:
1001 是 奇数,
1110 等于 偶数
I want to check if 101 is even or odd
那我就这样做:
mov al,101b
test al,1b
通过这样做,
test will perform and operation between 101 and 001
所以只检查最少的位,如果它是 '1' 那么数字是 奇数 否则 甚至
最后我们可以使用跳转打印数字是否为偶数:
je ; if number is even
我知道如果我们这样做,
mov al, 101b
test al, 100b
如果数字是 even 它将把零标志设置为 1,如果它是 odd 它将标志重置为 0 .
but what i dont understand is that if it checks the number is even or not why it requires two operands?
应该是
test al
我也知道测试类似于操作,只是它不改变第一个操作数,但问题仍然是
How it know if number is even or odd by performing AND?
很难将其格式化为评论...
mov al, 101b ; moves the value 101b (5) into al
test al, 100b ; performs a AND between al and the 100b (4) and sets some flags
所以它应该将零标志设置为 0,将符号标志设置为 0,并将奇偶校验标志设置为 1...
我想我想知道是否有什么奇怪的地方 test al, 1b
然后检查零标志
如果你有一个字节0xff AND 0x1
,结果将为非零的 0x1...零标志将为 0(如果使用 test
),因此它表示奇数。
我想我现在明白了,如何使用测试来判断数字是偶数还是奇数!!!
你只需要检查数字的最低有效位,
示例:
1001 是 奇数,
1110 等于 偶数
I want to check if 101 is even or odd
那我就这样做:
mov al,101b
test al,1b
通过这样做,
test will perform and operation between 101 and 001
所以只检查最少的位,如果它是 '1' 那么数字是 奇数 否则 甚至
最后我们可以使用跳转打印数字是否为偶数:
je ; if number is even