Question

In: Electrical Engineering

Write an assembly program for the MSP430 to calculate the number of zeros and ones in...

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.

Solutions

Expert Solution

#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


Related Solutions

Write a program in Java to: Read a file containing ones and zeros into a two-dimensional...
Write a program in Java to: Read a file containing ones and zeros into a two-dimensional int array. Your program must (1) read the name of the file from the command-line arguments, (2) open the file, (3) check that each line has the same number of characters and (4) check that the only characters in a line are ones and zeros. If there is no such command-line argument or no such file, or if any of the checks fail, your...
Write an MSP430 assembly language program that implements the following algorithm: a macro called "vdot" that...
Write an MSP430 assembly language program that implements the following algorithm: a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13. I have another file where I save my vectors called, "vars.c" here I save: int a[] = { 14, 65, 9} int b[] =...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called 'numadd' that...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called 'numadd' that sums up all the numeric characters present in a phrase ("string" that follows the "C" language convention). By For example, if the phrase is "Today is the 28th of month 9", the subroutine must perform the following sum: 2 + 8 + 9 = 19. The subroutine must receive the address of the first character of the corresponding phrase in the "stack", and return...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called ‘numadd’ that...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called ‘numadd’ that sums up all the numeric characters present in a sentence (“string” that follows the “C” language convention). For example, if the phrase is "Today is the 21st of month 5", the subroutine must perform the following sum: 2 + 1 + 5 = 8. The subroutine must receive the address of the first character of the corresponding phrase in the " stack ”, and...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13.
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence...
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … what is the initialization of a, b, and d? - a b d 1 ? ? 1 2 ? ? 1 3 1 1 2 4 1 2 3 5 2 3 5 6 3 5 8 7 5 8 13 wrong initialization - a b d 1 0 1 1 2...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT