Skip to main content
Engineering LibreTexts

4.6: Problems

  • Page ID
    83029
  • \( \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. Write the function mod that calculates a modulus (remainder) of a division. This is the % operation in Java and C. For example, 14%3 = 2 (quotient is 4, remainder is 2).
    2. Using only multiplication and integer numbers (no floating point numbers allowed) calculate 60% of 9. Use this trick on the following problems to get get
    3. Write a program to convert temperature from Celsius to Fahrenheit and from Fahrenheit to Celsius. How close to the actual values are your answers? What changes can you make to improve your program? Rewrite your program to include these changes.
    4. Write a program to convert feet to inches and inches to feet (output your answer using the format 5’ 3”).
    5. Write a program to convert kilometers to miles and miles to kilometers.
    6. Write a program to accept miles and hours, and calculate an approximate miles/hour.
    7. Write a program that loads the character ‘A’ (upper case A) into a register, and using only logical operations convert the character to ‘a’ (lower case a).
    8. Write a program that inverts the bits in a register using the eor (not the mvn) instructions.
    9. Write a program that swaps two values using a temporary variable.
    10. Write a program that swaps two values without using any temporary variables. Note that this program will use the eor instruction.
    11. Write a program that reads an integer number from a user and calculates the 2’s complement of the number, e.g., inverts the number (e.g., positive → negative or negative → positive).
    12. Write a program using only shift and add operations that multiplies a number by 8.
    13. Write a program using only shift and add operations that multiplies a number by 10.
    14. Write a program using only shift and add operations that multiplies a number by 7.
    15. A constant value can be more expensive to use than an immediate value. Why? Assume that the value at the address of cons is a constant variable. What is strange about the following statement? Would you ever see such a statement in a program?
                  LDR r1, =cons
                  STR r1, [r1, #0]
                  cons: .word 12
      

    What you will learn (Chapter 5)

    In this chapter you will learn:

    1. using the MSCPU to run ARM instructions
    2. why the ARM flexible operand, or operand2, exists
    3. the differences between Rs and Rn
    4. how a multi-cycle CPU functions
    5. ARM instructions that use operand2
    6. pre and post indexed load and store instructions

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

    • Was this article helpful?