Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone translate this into assembly language #include <msp430.h> #define Re

ID: 3853407 • Letter: C

Question

Can someone translate this into assembly language

#include <msp430.h>
#define Red_Led BIT0
#define Green_Led BIT6

int one;
int zero;
int i;
int a[10]= {0,0,0,0,0,1,0,0,0,1};

void main()
{

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR = Red_Led|Green_Led;
P1OUT=0;

for(i =0;i<=10;i++) // calculate how many zeros and ones are in the array

{
    if( a[i]== 0)
      zero = zero+1;
    else if(a[i]==1)
      +1;
}

if(zero >one) // which light is turned on
    P1OUT= Red_Led;
else P1OUT = Green_Led;
}

Explanation / Answer

Hi I have done the conversion from C to Assembly Language.

But it is disheartning few things are not clear like no data type mentioned for WDTCTL,  P1OUT. So what I have done is I have considered those as "char" data type and I have done the porgram.

Here is the sample C modified to do it // I am provoding this for your better understanding

//#include <msp430.h>
#include<string.h>
#define Red_Led //BIT0
#define Green_Led //BIT6
int one;
int zero;
int i;
int a[10]= {0,0,0,0,0,1,0,0,0,1};
char P1OUT[1];
int main()
{
//WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
//P1DIR = Red_Led|Green_Led;
P1OUT[1]={'0'};
for(i =0;i<=10;i++) // calculate how many zeros and ones are in the array
{
if( a[i]== 0)
zero = zero+1;
else if(a[i]==1)
+1;
}
if(zero >one) // which light is turned on
P1OUT[1]= {'R'};
else P1OUT[1] = {'G'};

return 0;
}

----------------------------------

gcc conversion

-------------------------------

one:
.zero 4
zero:
.zero 4
i:
.zero 4
a:
P1OUT:
.zero 1
main:
push rbp
mov rbp, rsp
mov BYTE PTR P1OUT[rip+1], 48
mov DWORD PTR i[rip], 0
.L5:
mov eax, DWORD PTR i[rip]
cmp eax, 10
jg .L2
mov eax, DWORD PTR i[rip]
cdqe
mov eax, DWORD PTR a[0+rax*4]
test eax, eax
jne .L3
mov eax, DWORD PTR zero[rip]
add eax, 1
mov DWORD PTR zero[rip], eax
jmp .L4
.L3:
mov eax, DWORD PTR i[rip]
cdqe
mov eax, DWORD PTR a[0+rax*4]
cmp eax, 1
jne .L4
mov eax, DWORD PTR one[rip]
add eax, 1
mov DWORD PTR one[rip], eax
.L4:
mov eax, DWORD PTR i[rip]
add eax, 1
mov DWORD PTR i[rip], eax
jmp .L5
.L2:
mov edx, DWORD PTR zero[rip]
mov eax, DWORD PTR one[rip]
cmp edx, eax
jle .L6
mov BYTE PTR P1OUT[rip+1], 82
jmp .L7
.L6:
mov BYTE PTR P1OUT[rip+1], 71
.L7:
mov eax, 0
pop rbp
ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote