Skip to main content
Engineering LibreTexts

8.7: Problems

  • Page ID
    83053
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    1. If an instruction has both the S bit and condition code set in the instruction, what happens if the condition code is not met? For example, what is the result of the following code fragment? Is the branch taken or not? Explain your answer.

    MOV r1, #5 
    MOV r2 #12 
    CMP r1, r2 
    SUBNES r1, r1, r2 
    BLT function
    

    2. Write a program to prompt a user to enter numbers until a -1 is entered. As the numbers are entered keep track of the largest, smallest, entries, and total of the values entered. At the end of the program print the value of the largest, smallest, and average for the numbers entered by the user.

    3. Write a program to find prime numbers from 3 to n in a loop by dividing the number n by all numbers from (2..n/2) in an inner loop. Using the remainder (rem) operation, determine if n is divisible by any number. If n is divisible, leave the inner loop. If the limit of (n/2) is reached and the inner loop has not been exited, the number is prime and you should output the number. So, if the user were to enter 25, your program would print out “2, 3, 5, 7, 11, 13, 17, 19, 23”.

    4. Write a program to prompt the user for a number, and determine if that number is prime. Your program should print out “Number n is prime” if the number is prime, and “Number n is not prime” if the number is not prime. The user should be able to enter input a “-1” is entered. It should print an error if 0, 1, 2 or any negative number other than -1 is entered.

    5. Write a program to allow a user to guess a random number generated by the computer from 1 to maximum (the user should enter the maximum value to guess). In this program the user will enter the value of maximum, and the syscall service 42 will be used to generate a random number from 1 to maximum. The user will then enter guesses and the program should print out if the guess is too high or too low until the user guesses the correct number. The program should print out the number of guesses the user took.

    6. Write a program to guess a number chosen by the user. In this program a user will choose a secret number from 1..maximum. The program will prompt the user for the maximum value, which the user will enter. The program will then make a guess as to the value of the secret number, and prompt the user to say if the actual number is higher, lower, or correct. The computer will then guess another number until it guesses the correct secret number. The program should use a binary search to narrow its guesses to select its next guess after each attempt.

    Run this program for maximum = {100, 1,000, and 10,000}, and graph the result. What can you say about the number of guesses used by the computer?

    7. Prompt the user for a number from 3..100, and determine the prime factors for that number. For example, 15 has prime factors 3 and 5. 60 has prime factors 2, 3, and 5. You only have to print out the prime factors, not how many times they occur (for example, in the number 60, 2 occurs twice).

    8. Change the prime factors program in question 10 to print out how many times a prime factor occurs in a number. For example, given the number 60 your program should print out “2,2,3,5”.

    9. Prompt the user for a number n, 0<n<100. Print out the smallest number of coins (quarters, dimes, nickels, and pennies) which will produce n. For example, if the user enters “66”, your program should print out “2 quarters, 1 dime, 1 nickel, and 1 penny”.

    10. Using only LSL and RSL, implement a program to check if a user input value is even or odd. The program should read a user input integer, and print out “The number is even” if the number is even, or “The number is odd” if the number is odd.

    11. Implement integer division with rounding (not truncation) in MIPS assembly. This can be done by taking the remainder from the division and dividing the original divisor by this number. If the new quotient is greater than or equal to 1, add 1 to the original quotient. Otherwise, do not change the original quotient.

    12. Why is there a signed and unsigned load for a half-word and byte, but not a word?

    13. State if the following addresses are valid for the alignment that is required? (Note: just because it might compile on your chip does not mean it is properly aligned).

    14. Translate the following B and BL statements into machine code.

    15. Show the following hexadecimal values in Big Endian and Little Endian notation.

    16. For each of the following addresses, state if it is a valid byte, half-word, word, or double word boundary for the 32=bit arm instruction set we are using. Some may be valid for multiple types of alignment, so check all boxes representing a valid alignment.

    What you will learn. (Chapter 9)

    In this chapter you will learn:

    1. Register conventions in ARM, and how to use the registers correctly.
    2. The standard form for implementing a function.
    3. How to store local variables on the stack
    4. Recursive programs and implementing them in ARM assembly

    8.7: Problems is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?