CIT593 LC4 Assembly
4) {15 points} Write an LC4 assembly subroutine that takes 16-bit number as an argument and returns
a 0 if the number has an even number of 1’s and a 1 if the number has an odd number of 1’s. As an
Copyright By PowCoder代写 加微信 powcoder
example, if the input is: 1011 0101 1110 1010, the subroutine will return: O because the input has
ten #1s in it. Note: x0000 would return a 0.
Here is a pseudocode version of the subroutine:
SUB EVEN ODD (num to test)
(i =0 : i < 16; i++ )
( most significant bit of num to test
num to test
= num to test << 1 ;
return (count MODULO 2)
As an example of its use, if the subroutine was called as follows:
num to test = xB5EA
SUB EVEN ODD (num to test)
returns a 0 in this case
Requirements:
You must use RO to take in the argument and RO hold the return value
You must write assembly instructions to initialize RO and "call" your subroutine
You must use labels, your last label must be "END"
You must comment your code, so we can grade it more easily!
Remember the golden rules of the NP register: when you write something to the register file,
the NP register stores whether that number was negative/zero/positive
o Consider the effect of shifting a number one place to the left and the NP register
The branch instructions have the ability to read the NP register
Modulo is like division, except it is the remainder instead of the quotient:
6 divided by 4 = 1, remainder 2. 6 modulo 4 = 2
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com