Solve the following problems using the MSP430 IAR Compiler/Assembler . Develop a
ID: 3875378 • Letter: S
Question
Solve the following problems using the MSP430 IAR Compiler/Assembler.
Develop a mixed-language program to perform the following calculations in assembly language subroutines:
Addition
Subtraction
Product
Division (ratio + remainder)
The C portion of the program should declare the input and output variables, and confirm the results (i.e. compare with the equivalent results in C). For parts a, b, and c, your output variables should be of type long (32 bits in size), input variables should be of type int (16 bits in size). For part d all variables should be of type int. HINT: You will need to pass a pointer when calculating part c, because only a single return value is allowed.
Additional requirements:
- For the above problems that combine C and assembly, the input data should be declared in the C portion of the program.
- For the above problems that only use assembly language, the input data should be stored in RAM.
- Code needed to test each problem should be included.
Explanation / Answer
ASSEMBLY LANGUAGE: (MSP430 GCC 6.2.1)
.LC0:
.string "Enter a,b values"
.LC1:
.string "%d%d"
.LC2:
.string "the addition value is:%ld"
.LC3:
.string " the subtraction value is:%ld"
.LC4:
.string " the product value is:%ld"
.LC5:
.string " Enter d,e values"
.LC6:
.string "the division value is:%d"
main:
; start of function
; framesize_regs: 2
; framesize_locals: 14
; framesize_outgoing: 6
; framesize: 22
; elim ap -> fp 4
; elim fp -> sp 20
; saved regs: R4
; start of prologue
PUSHM.W #1, R4
MOV.W R1, R4
SUB.W #20, R1
; end of prologue
MOV.W #.LC0, @R1
CALL #printf
MOV.W R4, R12
ADD.W #-10, R12
MOV.W R12, 4(R1)
MOV.W R4, R13
ADD.W #-8, R13
MOV.W R13, 2(R1)
MOV.W #.LC1, @R1
CALL #scanf
MOV.W -8(R4), R12
MOV.W -10(R4), R13
CALL #addition(int, int)
MOV.W R12, R13 { MOV.W R12, R14 { RPT #15 { RRAX.W R14
MOV.W R13, -4(R4)
MOV.W R14, -2(R4)
MOV.W -4(R4), 2(R1)
MOV.W -2(R4), 4(R1)
MOV.W #.LC2, @R1
CALL #printf
MOV.W -8(R4), R12
MOV.W -10(R4), R13
CALL #subtraction(int, int)
MOV.W R12, R13 { MOV.W R12, R14 { RPT #15 { RRAX.W R14
MOV.W R13, -4(R4)
MOV.W R14, -2(R4)
MOV.W -4(R4), 2(R1)
MOV.W -2(R4), 4(R1)
MOV.W #.LC3, @R1
CALL #printf
MOV.W -8(R4), R12
MOV.W -10(R4), R13
CALL #product(int, int)
MOV.W R12, R13 { MOV.W R12, R14 { RPT #15 { RRAX.W R14
MOV.W R13, -4(R4)
MOV.W R14, -2(R4)
MOV.W -4(R4), 2(R1)
MOV.W -2(R4), 4(R1)
MOV.W #.LC4, @R1
CALL #printf
MOV.W #.LC5, @R1
CALL #printf
MOV.W R4, R14
ADD.W #-14, R14
MOV.W R14, 4(R1)
MOV.W R4, R12
ADD.W #-12, R12
MOV.W R12, 2(R1)
MOV.W #.LC1, @R1
CALL #scanf
MOV.W -12(R4), R12
MOV.W -14(R4), R13
CALL #division(int, int)
MOV.W R12, -6(R4)
MOV.W -6(R4), 2(R1)
MOV.W #.LC6, @R1
CALL #printf
MOV.B #0, R12
; start of epilogue
ADD.W #20, R1
POPM.W #1, r4
RET
addition(int, int):
; start of function
; framesize_regs: 2
; framesize_locals: 8
; framesize_outgoing: 0
; framesize: 10
; elim ap -> fp 4
; elim fp -> sp 8
; saved regs: R4
; start of prologue
PUSHM.W #1, R4
MOV.W R1, R4
SUB.W #8, R1
; end of prologue
MOV.W R12, -6(R4)
MOV.W R13, -8(R4)
MOV.W -6(R4), R12
ADD.W -8(R4), R12
MOV.W R12, R13 { MOV.W R12, R14 { RPT #15 { RRAX.W R14
MOV.W R13, -4(R4)
MOV.W R14, -2(R4)
MOV.W -4(R4), R12
; start of epilogue
ADD.W #8, R1
POPM.W #1, r4
RET
subtraction(int, int):
; start of function
; framesize_regs: 2
; framesize_locals: 8
; framesize_outgoing: 0
; framesize: 10
; elim ap -> fp 4
; elim fp -> sp 8
; saved regs: R4
; start of prologue
PUSHM.W #1, R4
MOV.W R1, R4
SUB.W #8, R1
; end of prologue
MOV.W R12, -6(R4)
MOV.W R13, -8(R4)
MOV.W -6(R4), R12
SUB.W -8(R4), R12
MOV.W R12, R13 { MOV.W R12, R14 { RPT #15 { RRAX.W R14
MOV.W R13, -4(R4)
MOV.W R14, -2(R4)
MOV.W -4(R4), R12
; start of epilogue
ADD.W #8, R1
POPM.W #1, r4
RET
product(int, int):
; start of function
; framesize_regs: 2
; framesize_locals: 8
; framesize_outgoing: 0
; framesize: 10
; elim ap -> fp 4
; elim fp -> sp 8
; saved regs: R4
; start of prologue
PUSHM.W #1, R4
MOV.W R1, R4
SUB.W #8, R1
; end of prologue
MOV.W R12, -6(R4)
MOV.W R13, -8(R4)
MOV.W -8(R4), R13
MOV.W -6(R4), R12
CALL #__mspabi_mpyi
MOV.W R12, R13 { MOV.W R12, R14 { RPT #15 { RRAX.W R14
MOV.W R13, -4(R4)
MOV.W R14, -2(R4)
MOV.W -4(R4), R12
; start of epilogue
ADD.W #8, R1
POPM.W #1, r4
RET
division(int, int):
; start of function
; framesize_regs: 2
; framesize_locals: 6
; framesize_outgoing: 0
; framesize: 8
; elim ap -> fp 4
; elim fp -> sp 6
; saved regs: R4
; start of prologue
PUSHM.W #1, R4
MOV.W R1, R4
SUB.W #6, R1
; end of prologue
MOV.W R12, -4(R4)
MOV.W R13, -6(R4)
MOV.W -6(R4), R13
MOV.W -4(R4), R12
CALL #__mspabi_divi
MOV.W R12, -2(R4)
MOV.W -2(R4), R12
; start of epilogue
ADD.W #6, R1
POPM.W #1, r4
RET
C LANGUAGE:
#include <stdio.h>
int addition(int a,int b);
int subtraction(int a,int b);
int product(int a,int b);
int division(int d,int f);
int main()
{
int a,b;
long int c;
int d,e,f;
printf("Enter a,b values");
scanf("%d%d",&a,&b);
c=addition(a,b);
printf("the addition value is:%ld",c);
c=subtraction(a,b);
printf(" the subtraction value is:%ld",c);
c=product(a,b);
printf(" the product value is:%ld",c);
printf(" Enter d,e values");
scanf("%d%d",&d,&e);
f=division(d,e);
printf("the division value is:%d",f);
return 0;
}
int addition(int a,int b)
{
long int c;
c=a+b;
return c;
}
int subtraction(int a,int b)
{
long int c;
c=a-b;
return c;
}
int product(int a,int b)
{
long int c;
c=a*b;
return c;
}
int division(int d,int e)
{
int f;
f=d/e;
return f;
}
OUTPUT:
Enter a,b values3 4
the addition value is:7
the subtraction value is:-1
the product value is:12
Enter d,e values4 2
the division value is:2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.