Question: i got this code to work in c for a project i am doing but i need it in assembly language my S file which

i got this code to work in c for a project i am doing but i need it in assembly language my S file which i have a start was wondering if i could get help implementing this code it works the way i want it to in C #include
const char DISP[]={
0b01111110,// Digit 0
0b00110000,// Digit 1
0b01101101,// Digit 2
0b01111001// Digit 3
};
volatile unsigned int mode =0; // Global variable to track current mode
void updateDisplay(int num){
P3OUT &= ~(BIT7); // Turn off digit select
P2OUT = DISP[num]; // Output the segment pattern for the current mode
switch (num){
case 0:
P3OUT |= BIT7; // Select dig_1
break;
case 1:
P3OUT |= BIT7; // Select dig_2
break;
}
}
int main(void){
// Disable watchdog timer and run at 1MHz
WDTCTL = WDTPW | WDTHOLD;
BCSCTL1= CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P2SEL &= ~(BIT6|BIT7);
P2SEL2 &= ~(BIT6|BIT7);
// Configure LED pins
P1DIR |= BIT0; // P1.0(green LED) as output
P3DIR |= BIT5; // P3.5(blue LED) as output
P3DIR |= BIT6; // P3.6(red LED) as output
// Initialize 7-segment display pins (P2.0 to P2.6)
P2DIR |=0x7F; // Set P2.0 to P2.6 as outputs
P3DIR |= BIT7; // Set P3.7 as output for digit select
// Set up buttons as inputs with interrupts enabled
P1DIR &= ~BIT3; // Set P1.3 as input
P1IE |= BIT3; // Enable interrupt for P1.3
P1IES |= BIT3; // Interrupt on high-to-low transition (button press)
P1IFG &= ~BIT3; // Clear interrupt flag for P1.3
P2DIR &= ~BIT7; // Set P1.3 as input
P2IE |= BIT7; // Enable interrupt for P1.3
P2IES |= BIT7; // Interrupt on high-to-low transition (button press)
P2IFG &= ~BIT7; // Clear interrupt flag for P1.3
// Initialize Timer1 for green LED (3 Hz for mode 1 and mode 2)
TA1CTL = TASSEL_2| MC_1| ID_3; // SMCLK, Up mode, /8
TA1CCR0=41667; // Set frequency for 3 Hz
TA1CCTL0= CCIE; // Enable interrupt
// Initialize Timer0 for blue LED (4 Hz for mode 2)
TA0CTL = TASSEL_2| MC_1| ID_3; // SMCLK, Up mode, /8
TA0CCR0=25000; // Set frequency for 4 Hz
TA0CCTL0|= CCIE; // Enable interrupt
// Enable global interrupts
__eint();
for (;;){
// Display current mode on 7-segment display
updateDisplay(mode);
// Blink LEDs based on mode
if (mode ==0){
// Mode 0: Turn off blue LED, red LED blinks every 1/2 second (execution loop)
P3OUT &= ~BIT5; // Turn off blue LED
P3OUT ^= BIT6; // Toggle red LED
__delay_cycles(500000); // Delay for half a second
} else if (mode ==1){
// Mode 1: Blink red LED every 1/2 second (execution loop)
P3OUT ^= BIT6; // Toggle red LED
__delay_cycles(500000); // Delay for half a second
} else if (mode ==2){
// Mode 2: Turn off red LED
P3OUT &= ~BIT6;
} else if (mode ==3){
// Mode 3: Turn off red and green LEDs
P3OUT &= ~BIT6; // Turn off red LED
P1OUT &= ~BIT0; // Turn off green LED
}
}
return 0;
}
// Button interrupt for mode increment
#pragma vector=PORT1_VECTOR
__interrupt void BUTTON1(void){
while (!(BIT3 & P1IN));
__delay_cycles(32000);
mode =(mode +1)%4; // Increment mode
P1IFG &= ~BIT3; // Clear the interrupt flag for P1.3
}
// Button interrupt for mode decrement
#pragma vector=PORT2_VECTOR
__interrupt void BUTTON2(void){
while (!(BIT7 & P2IN));
__delay_cycles(32000);
mode =(mode -1+4)%4; // Decrement mode
P2IFG &= ~BIT7; // Clear the interrupt flag for P2.7
}
// Timer1 interrupt (green LED control in Mode 2 and Mode 1)
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1(void){
static int count =0;
if (mode ==1){
// Mode 1: Green LED blinks every 1/3 second
P1OUT ^= BIT0; // Toggle green LED
}
if (mode ==2){
// Mode 2: Green LED blinks every 1/3 second
P1OUT ^= BIT0; // Toggle green LED
}
}
// Timer0 interrupt (blue LED control in Mode 2)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0(void){
if (mode ==2){
// Mode 2: Blue LED blinks every 1/4 second
P3OUT ^= BIT5; // Toggle blue LED
}
if (mode ==3){
// Mode 3: Blue LED blinks slower every 1/2 second
P3OUT ^= BIT5; // Toggle blue LED
}
}
i got this code to work in c for a project i am

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!