In: Electrical Engineering
Write an assembly program for the MSP430 to calculate the number of zeros and ones in an array. If the number of zeros is more than the number of ones, the red LED(connected to P1.0 on the MSP430 launchpad) will turn on. Otherwise, the green LED (connected to P1.6 on the MSP430 launchpad) will turn on.
#include<msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD
P1.0 = 0x00;
P1.6 = 0x00;
int j=31, i, count = 0, count = 1;
unsigned int num;
int b[32] = {0};
for ( ; ; )
{
if (num & 1 == 1)
{
count1++;
}
else
{
count++;
}
}
if (count1 > count)
{
P1.0 = 0X01;
}
else
{
P1.6 = 0x01;
}
}
b bit
#include "msp430.h" ; #define controlled include file
NAME main ; module name
PUBLIC main ; make the main label visible outside this
module
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP ; set up stack
main: NOP ; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog
timer MOV.W #0000h,R4
MOV.W #0000h,R5
MOV.W #0008h,R6
MOV.W #0097h,R7
AGAIN:RRC R7
JC NEXT
INC R4
JMP
HERE
NEXT:INC R5
HERE:DEC R6
JNZ
AGAIN
LOOP : JMP COMPARE
COMPARE:CMP R4,R5
JGE ZERO
CMP R5,R4
JGE ONE
ZERO:
; P1.0 = 0x01
ONE :
; P1.6 = 0x01
JMP LOOP
END