Intro to Microprocessors A C program for the MSP430 to calculate the number of z
ID: 3853138 • Letter: I
Question
Intro to Microprocessors
A C 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 (conected 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.
I have done the above bold problem in C program. Which I will provide below, I just need help in writing it in the assembly language.
#include <msp430.h>
/*
* main.c
*/
#define Red_Led BIT0
#define Green_Led BIT6
int ones;
int zeroes;
int i;
int a[10]= {0,0,0,0,0,1,0,0,0,1};
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR = Red_Led|Green_Led;
P1OUT=0;
for(i =0;i<=10;i++)
{
if( a[i]== 0)
zeroes = zeroes+1;
else if(a[i]==1)
ones = ones +1;
}
if(zeroes >ones)
P1OUT= Red_Led;
else P1OUT = Green_Led;
}
Explanation / Answer
main:
push rbp
mov rbp, rsp
sub rsp, 80
lea rax, [rbp-68]
mov rsi, rax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
mov DWORD PTR [rbp-12], 0
.L3:
mov eax, DWORD PTR [rbp-68]
cmp DWORD PTR [rbp-12], eax
jge .L2
mov eax, DWORD PTR [rbp-12]
cdqe
mov eax, DWORD PTR [rbp-64+rax*4]
mov esi, eax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
add DWORD PTR [rbp-12], 1
jmp .L3
.L2:
mov DWORD PTR [rbp-12], 0
.L7:
mov eax, DWORD PTR [rbp-68]
cmp DWORD PTR [rbp-12], eax
jge .L4
mov eax, DWORD PTR [rbp-12]
cdqe
mov eax, DWORD PTR [rbp-64+rax*4]
test eax, eax
jne .L5
add DWORD PTR [rbp-8], 1
jmp .L6
.L5:
mov eax, DWORD PTR [rbp-12]
cdqe
mov eax, DWORD PTR [rbp-64+rax*4]
cmp eax, 1
jne .L6
add DWORD PTR [rbp-4], 1
.L6:
add DWORD PTR [rbp-12], 1
jmp .L7
.L4:
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-4]
jle .L8
mov BYTE PTR [rbp-13], 82
jmp .L9
.L8:
mov BYTE PTR [rbp-13], 71
.L9:
mov eax, 0
leave
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.