# 程序代写 Exercises for Section 8. – cscodehelp代写

Exercises for Section 8.

Note: some of the questions below are harder than anything you¡¯ll encounter in an exam, but they are worth attempting and the solutions, which will be provided in a few days, are all instructive. Studying them should help improve your assembly language programming and in particular the concepts of bitwise logical operations, shifts, subroutines and stacks. Q1 is easier and may be helpful in the coursework exercise.

1. Using the bitwise AND instruction, write a Sigma16 program to test if a variable x is even or odd. Return the result in a Boolean output variable. This can also be done using the DIV instruction.

2. Write a Sigma16 program to count the number of ¡°1¡± bits set in the value stored in a 16-bit variable, x.

Copyright By cscodehelp代写 加微信 cscodehelp

3. Using your knowledge of Sigma16 instructions, estimate how many memory cycles your program in (2) will take to execute for an input of $FFFF. Remember all RRR instructions take 1 memory cycle; all RX and X instructions except LOAD and STORE take 2 memory cycles; LOAD and STORE take 3 memory cycles.

4. The parity of a codeword is a Boolean value defined as even (0) if the number of ¡°1¡± bits in the word is even (0) and odd (1) if the number of ¡°1¡± bits is odd. Using your code from Q2 above, or otherwise, implement a Sigma16 subroutine to compute the parity of the word in R1, returning a 0 or 1 in R2 as appropriate. Then use the subroutine (with JAL etc) to compute the parity of three input variables x, y and z, storing the results in Px, Py and Pz.

5. Write a Sigma16 subroutine segment to swap the contents of R1 and R2. Test your subroutine by incorporating it into a program which loads R1 and R2 with the values of two input variables and use the emulator to verify that when the program ends the values in R1 and R2 have been swapped. Can you achieve the swap in the subroutine without using any other registers or memory locations?

6. Challenge (this is harder and not examinable). A recursive subroutine is one that calls itself. This concept can be used to compute the factorial of a number in a way different from the solution to the last problem in section 6. Write Sigma16 code to compute the factorial of a input number k >=0, using a recursive subroutine. Note that, as the subroutines will nest k times you will need to set up a stack.

程序代写 CS代考 加微信: cscodehelp QQ: 2235208643 Email: kyit630461@163.com