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

write an equivalent C code for assembly #include <msp430.h> int main(void) { WDT

ID: 3785025 • Letter: W

Question

write an equivalent C code for assembly

#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0x07;
P1OUT = 0;
while(1)
{
__delay_cycles(1500000);
P1OUT ^= 0x01;//p1.0 s on
__delay_cycles(1500000);
P1OUT ^= 0x01;//1.0 is off
P1OUT ^= 0x02;//p1.1 is on
__delay_cycles(1500000);
P1OUT ^= 0x01;//p1.0 is on
__delay_cycles(1500000);
P1OUT ^= 0x01;//p1.0 is off
P1OUT ^= 0x02;//p1.1 s off
P1OUT ^= 0x04;//p1.2 is on
__delay_cycles(1500000);
P1OUT ^= 0x01;//p1.0 is on
__delay_cycles(1500000);
P1OUT ^= 0x01;//p1.0 is off
P1OUT ^= 0x02;//p1.1 is on.
__delay_cycles(1500000);
P1OUT ^= 0x01;//p1.0 is on
__delay_cycles(1500000);
P1OUT ^= 0x01;//p1.0 is off
P1OUT ^= 0x02;//p1.0 is off
P1OUT ^= 0x04;//p1.0 is off
}

}

Explanation / Answer

#include #include #include void chk_label(); void chk_opcode(); void READ_LINE(); struct optab {     char   code[10],objcode[10]; }myoptab[3]={                    {"LDA","00"},                    {"JMP","01"},                    {"STA","02"}              }; struct symtab{     char symbol[10];     int addr;     }mysymtab[10]; int startaddr,locctr,symcount=0,length; char line[20],label[8],opcode[8],operand[8],programname[10]; /*ASSEMBLER PASS 1 */                   void PASS1() {      FILE *input,*inter;                                       input=fopen("input.txt","r");                                 inter=fopen("inter.txt","w");      printf("LOCATION LABEL OPERAND OPCODE ");      printf("_____________________________________");                           fgets(line,20,input);      READ_LINE();      if(!strcmp(opcode,"START"))      {         startaddr=atoi(operand);         locctr=startaddr;                            strcpy(programname,label);         fprintf(inter,"%s",line);         fgets(line,20,input);         }         else         {            programname[0]='';            startaddr=0;            locctr=0;            }            printf(" %d %s %s %s",locctr,label,opcode,operand);            while(strcmp(line,"END")!=0)            {              READ_LINE();              printf(" %d %s %s %s",locctr,label,opcode,operand);              if(label[0]!='')chk_label();              chk_opcode();              fprintf(inter,"%s %s %s ",label,opcode,operand);              fgets(line,20,input);              }              printf(" %d %s",locctr,line);              fprintf(inter,"%s",line); fclose(inter); fclose(input); } /*Assesmbler pass 2 */                  void PASS2() {     FILE *inter,*output;     char record[30],part[8],value[5];/*Part array was defined as part[6] previously*/     int currtxtlen=0,foundopcode,foundoperand,chk,operandaddr,recaddr=0;     inter=fopen("inter.txt","r");     output=fopen("output.txt","w");     fgets(line,20,inter);     READ_LINE();     if(!strcmp(opcode,"START")) fgets(line,20,inter);     printf(" Corresponding Object code is.. ");     printf(" H^ %s ^ %d ^ %d ",programname,startaddr,length);     fprintf(output," H^ %s ^ %d ^ %d ",programname,startaddr,length);     recaddr=startaddr; record[0]='';     while(strcmp(line,"END")!=0)     {        operandaddr=foundoperand=foundopcode=0;        value[0]=part[0]= '';        READ_LINE();        for(chk=0;chk