coding a calculator in msp430 Assembly language

I have included the pdf with calc.c and calc.h and all the functions files , YOU HAVE THE CALC.C AND CALC.H READY DONT CHANGE ANYTHING ON THEM AND THE ADD AND SUB ARE ALREADY WRITTEN I WANT YOU TO DO THE (DIVIDE ,POWER,MULTIBLE,AND MOD) .To practice writing assembly and passing parameters, you will implement the math functions of a calculator.When you finish the coding send to me the output also to check if the are correct

The add.S and sub.S files will be trivial to complete, but mul.S and divd.S will take some careful planning. You must either repeatedly add or repeatedly subtract (and count) the first input number by the second. mod.S might be trivial, but pow.S will be challenging.

When finished the calculator should be able to add +, subtract -, multiply *, divide /, modulo % and power ^.

Here is an example session:

> 2 + 35> 5 - 14> 1 - 5-4> -3 + 2-1> 6 / 32> 7 / 32> 5 / 31> -5 / 3-1> -6 / -32> -6 * -318> 6 * 318> -6 * 3-18> 3 ^ 29> 2 ^ 416> 7 % 31> 6 / 00
  1. You should strive to complete this functionality in as few instructions as possible.
  2. Only write your solution in the provided assembly files (inside the func/ directory).
  3. Use repeated addition to calculate the result of multiplication. You will need to construct a loop yourself!
  4. Use repeated subtraction to calculate the quotient. Again, you will need to construct a loop yourself!
  5. Do not simply generate assembly using the compiler and submit it. I will know.
  6. Only worry about negative numbers for add +, subtract -, multiply * and divide /.

Parameter Passing

Parameters are passed to functions in the registers r15, r14, r13 and r12 in that order (something special happens if there are more than 4 arguments to a function). The functions you are implementing are receiving the first number (left of operator) in r15 and the second number (right of operator) in r14. Remember, when the microcontroller executes the ret instruction at the end of a function, the return value should be in r15!

Assembly Instructions

Here are some useful instructions you might need:

mov     src, dst    ; move the contents of src to dstsub     src, dst    ; subtract the value in src from dst and store the result in dstadd     src, dst    ; add the value in src to the value in dst and store the result in dstclr     dst         ; zero out destination (same as mov #0, dst)cmp     a, b        ; make the comparison: b [<, >=, ==, !=] ajl      label       ; jump to label if b < ajge     label       ; jump to label if b >= ajeq     label       ; jump to label if b == ajne     label       ; jump to label if b != ajn      label       ; jump to label if N is set (result of previous instruction was negative)jmp     label       ; jump to label unconditionally (always)

A more complete listing can be found on page 56 of the .

Registers

You can use any of the registers r4 - r15, however do not use registers r0 - r3 for anything in your function. These registers serve special purposes on the MSP430.

Callee-Saved Registers

Furthermore, a called function is required to preserve the callee-saved registers (r4 - r10) so that they have the same value on return from a function as they had at the point of the call.

All other general-purpose registers are caller-save; that is, they are not preserved across a call, so if thier value is needed following the call, the caller is responsible for saving and restoring their contents. For example:

int main() {    printf("Hello, Worldn");    return 0;}
main() is the caller and printf() is the callee
× How can I help you?