Answered step by step
Verified Expert Solution
Question
1 Approved Answer
To practice writing assembly and passing parameters, you will implement the math functions of a calculator. The add.S and sub.S files will be trivial to
To practice writing assembly and passing parameters, you will implement the math functions of a calculator.
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:
You should strive to complete this functionality in as few instructions as possible.
Only write your solution in the provided assembly files inside the func directory
Use repeated addition to calculate the result of multiplication. You will need to construct a loop yourself!
Use repeated subtraction to calculate the quotient. Again, you will need to construct a loop yourself!
Do not simply generate assembly using the compiler and submit it I will know.
Only worry about negative numbers for add subtract multiply and divide
Parameter Passing
Parameters are passed to functions in the registers r r r and r in that order something special happens if there are more than arguments to a function The functions you are implementing are receiving the first number left of operator in r and the second number right of operator in r Remember, when the microcontroller executes the ret instruction at the end of a function, the return value should be in r
Assembly Instructions
Here are some useful instructions you might need:
mov src dst ; move the contents of src to dst
sub src dst ; subtract the value in src from dst and store the result in dst
add src dst ; add the value in src to the value in dst and store the result in dst
clr dst ; zero out destination same as mov # dst
cmp a b ; make the comparison: b a
jl label ; jump to label if b a
jge label ; jump to label if b a
jeq label ; jump to label if b a
jne label ; jump to label if b a
jn 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 of the Family User's Guide.
Registers
You can use any of the registers r r however do not use registers r r for anything in your function. These registers serve special purposes on the MSP
CalleeSaved Registers
Furthermore, a called function is required to preserve the calleesaved registers r r so that they have the same value on return from a function as they had at the point of the call.
All other generalpurpose registers are callersave; 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
printfHello World
;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started