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

Please convert this C code into assembly: #include <avr/io.h> #define F_CPU 1600

ID: 2246624 • Letter: P

Question

Please convert this C code into assembly:
#include <avr/io.h> #define F_CPU 16000000UL #define BAUD 9600 #define MYUBRR F_CPU/16/BAUD-1
#include "util/delay.h"
void adc_init() { // AREF = AVcc ADMUX = (1<<REFS0); // ADC Enable and prescaler of 128 // 16000000/128 = 125000 ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); }
void USART_Init( unsigned int ubrr) { UBRR0H = (unsigned char)(ubrr>>8); UBRR0L = (unsigned char)ubrr; /*Enable receiver and transmitter */ UCSR0B = (1<<RXEN0)|(1<<TXEN0); /* Set frame format: 8data, 2stop bit */ UCSR0C = (1<<USBS0)|(3<<UCSZ00); }
void USART_Transmit( unsigned char data ) { while(!(UCSR0A & (1<<UDRE0))); UDR0 = data; }
void SendString(char *StringPtr) { while(*StringPtr != 0x00) { USART_Transmit(*StringPtr); StringPtr++; } }


uint16_t adc_read(uint8_t ch) { // select the corresponding channel 0~7 // ANDing with ’7? will always keep the value // of ‘ch’ between 0 and 7 ch &= 0b00000111; // AND operation with 7 ADMUX = (ADMUX & 0xF8)|ch; // clears the bottom 3 bits before ORing // start single conversion // write ’1? to ADSC ADCSRA |= (1<<ADSC); // wait for conversion to complete // ADSC becomes ’0? again // till then, run loop continuously while(ADCSRA & (1<<ADSC)); return (ADC); }
int main(void) { adc_init(); DDRC = 0b00000000; USART_Init(MYUBRR); unsigned int adc_value;
while(1) { adc_value=adc_read(0x00); StringPtr *adc_valueStr = itoa(adc_value,adc_valueStr,10); SendString(adc_value+""); SendString(" "); _delay_ms(1000); }
} Please convert this C code into assembly:
#include <avr/io.h> #define F_CPU 16000000UL #define BAUD 9600 #define MYUBRR F_CPU/16/BAUD-1
#include "util/delay.h"
void adc_init() { // AREF = AVcc ADMUX = (1<<REFS0); // ADC Enable and prescaler of 128 // 16000000/128 = 125000 ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); }
void USART_Init( unsigned int ubrr) { UBRR0H = (unsigned char)(ubrr>>8); UBRR0L = (unsigned char)ubrr; /*Enable receiver and transmitter */ UCSR0B = (1<<RXEN0)|(1<<TXEN0); /* Set frame format: 8data, 2stop bit */ UCSR0C = (1<<USBS0)|(3<<UCSZ00); }
void USART_Transmit( unsigned char data ) { while(!(UCSR0A & (1<<UDRE0))); UDR0 = data; }
void SendString(char *StringPtr) { while(*StringPtr != 0x00) { USART_Transmit(*StringPtr); StringPtr++; } }


uint16_t adc_read(uint8_t ch) { // select the corresponding channel 0~7 // ANDing with ’7? will always keep the value // of ‘ch’ between 0 and 7 ch &= 0b00000111; // AND operation with 7 ADMUX = (ADMUX & 0xF8)|ch; // clears the bottom 3 bits before ORing // start single conversion // write ’1? to ADSC ADCSRA |= (1<<ADSC); // wait for conversion to complete // ADSC becomes ’0? again // till then, run loop continuously while(ADCSRA & (1<<ADSC)); return (ADC); }
int main(void) { adc_init(); DDRC = 0b00000000; USART_Init(MYUBRR); unsigned int adc_value;
while(1) { adc_value=adc_read(0x00); StringPtr *adc_valueStr = itoa(adc_value,adc_valueStr,10); SendString(adc_value+""); SendString(" "); _delay_ms(1000); }
}
#include <avr/io.h> #define F_CPU 16000000UL #define BAUD 9600 #define MYUBRR F_CPU/16/BAUD-1
#include "util/delay.h"
void adc_init() { // AREF = AVcc ADMUX = (1<<REFS0); // ADC Enable and prescaler of 128 // 16000000/128 = 125000 ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); }
void USART_Init( unsigned int ubrr) { UBRR0H = (unsigned char)(ubrr>>8); UBRR0L = (unsigned char)ubrr; /*Enable receiver and transmitter */ UCSR0B = (1<<RXEN0)|(1<<TXEN0); /* Set frame format: 8data, 2stop bit */ UCSR0C = (1<<USBS0)|(3<<UCSZ00); }
void USART_Transmit( unsigned char data ) { while(!(UCSR0A & (1<<UDRE0))); UDR0 = data; }
void SendString(char *StringPtr) { while(*StringPtr != 0x00) { USART_Transmit(*StringPtr); StringPtr++; } }


uint16_t adc_read(uint8_t ch) { // select the corresponding channel 0~7 // ANDing with ’7? will always keep the value // of ‘ch’ between 0 and 7 ch &= 0b00000111; // AND operation with 7 ADMUX = (ADMUX & 0xF8)|ch; // clears the bottom 3 bits before ORing // start single conversion // write ’1? to ADSC ADCSRA |= (1<<ADSC); // wait for conversion to complete // ADSC becomes ’0? again // till then, run loop continuously while(ADCSRA & (1<<ADSC)); return (ADC); }
int main(void) { adc_init(); DDRC = 0b00000000; USART_Init(MYUBRR); unsigned int adc_value;
while(1) { adc_value=adc_read(0x00); StringPtr *adc_valueStr = itoa(adc_value,adc_valueStr,10); SendString(adc_value+""); SendString(" "); _delay_ms(1000); }
} #include <avr/io.h> #define F_CPU 16000000UL #define BAUD 9600 #define MYUBRR F_CPU/16/BAUD-1
#include "util/delay.h"
void adc_init() { // AREF = AVcc ADMUX = (1<<REFS0); // ADC Enable and prescaler of 128 // 16000000/128 = 125000 ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); }
void USART_Init( unsigned int ubrr) { UBRR0H = (unsigned char)(ubrr>>8); UBRR0L = (unsigned char)ubrr; /*Enable receiver and transmitter */ UCSR0B = (1<<RXEN0)|(1<<TXEN0); /* Set frame format: 8data, 2stop bit */ UCSR0C = (1<<USBS0)|(3<<UCSZ00); }
void USART_Transmit( unsigned char data ) { while(!(UCSR0A & (1<<UDRE0))); UDR0 = data; }
void SendString(char *StringPtr) { while(*StringPtr != 0x00) { USART_Transmit(*StringPtr); StringPtr++; } }


uint16_t adc_read(uint8_t ch) { // select the corresponding channel 0~7 // ANDing with ’7? will always keep the value // of ‘ch’ between 0 and 7 ch &= 0b00000111; // AND operation with 7 ADMUX = (ADMUX & 0xF8)|ch; // clears the bottom 3 bits before ORing // start single conversion // write ’1? to ADSC ADCSRA |= (1<<ADSC); // wait for conversion to complete // ADSC becomes ’0? again // till then, run loop continuously while(ADCSRA & (1<<ADSC)); return (ADC); }
int main(void) { adc_init(); DDRC = 0b00000000; USART_Init(MYUBRR); unsigned int adc_value;
while(1) { adc_value=adc_read(0x00); StringPtr *adc_valueStr = itoa(adc_value,adc_valueStr,10); SendString(adc_value+""); SendString(" "); _delay_ms(1000); }
}

Explanation / Answer

There is a compilation error that is

#include <avr/io.h>

#define F_CPU 16000000UL

#define BAUD 9600

#define MYUBRR F_CPU/16/BAUD-1

#include "util/delay.h"

void adc_init()

{

    // AREF = AVcc

    ADMUX = (1<<REFS0);

    

    // ADC Enable and prescaler of 128

    // 16000000/128 = 125000

    ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

}

void USART_Init( unsigned int ubrr)

{

UBRR0H = (unsigned char)(ubrr>>8);

UBRR0L = (unsigned char)ubrr;

/*Enable receiver and transmitter */

UCSR0B = (1<<RXEN0)|(1<<TXEN0);

/* Set frame format: 8data, 2stop bit */

UCSR0C = (1<<USBS0)|(3<<UCSZ00);

}

void USART_Transmit( unsigned char data )

{

    while(!(UCSR0A & (1<<UDRE0)));

    UDR0 = data;

}

void SendString(char *StringPtr)

{

    

    while(*StringPtr != 0x00)

    {

        USART_Transmit(*StringPtr);

        StringPtr++;

    }

}


uint16_t adc_read(uint8_t ch)

{

    // select the corresponding channel 0~7

    // ANDing with ’7? will always keep the value

    // of ‘ch’ between 0 and 7

    ch &= 0b00000111; // AND operation with 7

    ADMUX = (ADMUX & 0xF8)|ch; // clears the bottom 3 bits before ORing

    

    // start single conversion

    // write ’1? to ADSC

    ADCSRA |= (1<<ADSC);

    

    // wait for conversion to complete

    // ADSC becomes ’0? again

    // till then, run loop continuously

    while(ADCSRA & (1<<ADSC));

    

    return (ADC);

}

int main(voi

d)

{

    

    adc_init();

    DDRC = 0b00000000;

    USART_Init(MYUBRR);

    unsigned int adc_value;

    

    while(1)

    {   

        adc_value=adc_read(0x00);

        StringPtr *adc_valueStr = itoa(adc_value,adc_valueStr,10);

        SendString(adc_value+"");

        SendString(" ");

        _delay_ms(1000);

    }

    

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote