How can i solve this problem in assembly language: using only SUB, M开发者_Go百科OV, AND instructions, show how to calculate x = n mod y
, assuming that you are given the values of n and y. n is any 16-bit unsigned integer, and y is power of 2.
There are two main steps to solving a problems like this:
determine the algorithm and express it in pseudocode or a language such as C
implement (1) in assembler.
For step (1) you need to know that n mod y
, where y is a power of 2, is equivalent to n AND (y - 1)
.
精彩评论