Question

In: Computer Science

The following 3 instances of code was provided by my embedded systems course. Can you explain...

The following 3 instances of code was provided by my embedded systems course. Can you explain what is happening in each code segment?

=== code 1 ===

void foo() {
uint8_t a=2;
uint8_t b[]={b0, b1, b2}; // They are the last three digits of your A#
uint8_t* c=b;
uint8_t* d=&a;
}


=== code 2 ===

__extension__ typedef struct tagT1CONBITS {
union {
struct {
unsigned :1;
unsigned TCS:1;
unsigned TSYNC:1;
unsigned :1;
unsigned TCKPS:2;
unsigned TGATE:1;
unsigned :6;
unsigned TSIDL:1;
unsigned :1;
unsigned TON:1;
};
struct {
unsigned :4;
unsigned TCKPS0:1;
unsigned TCKPS1:1;
};
uint8_t T1CON[2];
};
} T1CONBITS;
volatile T1CONBITS foo;


=== code 3 ===

b6: 00 e0 ldi r16, 0x00
b8: 10 e0 ldi r17, 0x00
ba: 0c c0 rjmp .+24
bc: 81 2f mov r24, r17
be: 90 e0 ldi r25, 0x00
c0: 29 81 ldd r18, Y+1
c2: 3a 81 ldd r19, Y+2
c4: 82 0f add r24, r18
c6: 93 1f adc r25, r19
c8: fc 01 movw r30, r24
ca: 80 81 ld r24, Z
cc: 08 0f add r16, r24
ce: 81 2f mov r24, r17
d0: 11 e0 ldi r17, 0x01
d2: 18 0f add r17, r24
d4: 13 30 cpi r17, 0x03
d6: 90 f3 brcs .-28

Solutions

Expert Solution

=== code 1 ===

void foo() {
uint8_t a=2;
uint8_t b[]={b0, b1, b2}; // They are the last three digits of your A#
uint8_t* c=b;
uint8_t* d=&a;
}

  • in the above code 1 section, unit_8_t is integer of 1 byte. note: when just int is declared it generally occupies 4 bytes of memory across all platforms.
  • The function foo() is defined , line number 1 tells, variable a of type int(1 byte) is used and value 2 has been assigned to variable a
  • line number 2 tells, integer(1 byte) array b is defined and the 3 integers b0,b1 and b2 are stored in array b.
  • line number 3 tells, the pointer c of type integer(1 byte) is declared and integer array b is assigned to pointer c. this suggests the pointer c is storing the address of first element of array that is b0.
  • line number 4 tells, the pointer d of type integer(1 byte) is declared and storing the address of variable a. here &a suggests the address of variable a.

=== code 2 ===

__extension__ typedef struct tagT1CONBITS {
union {
struct {
unsigned :1;
unsigned TCS:1;
unsigned TSYNC:1;
unsigned :1;
unsigned TCKPS:2;
unsigned TGATE:1;
unsigned :6;
unsigned TSIDL:1;
unsigned :1;
unsigned TON:1;
};
struct {
unsigned :4;
unsigned TCKPS0:1;
unsigned TCKPS1:1;
};
uint8_t T1CON[2];
};
} T1CONBITS;
volatile T1CONBITS foo;

  • in this code snippet, typedef is a reserved keyword in the programming languages C and C++. It is used to create an additional name for another data type, but does not create a new type i.e new name to exisiting data type.for example, struct tagT1CONBITS is renamed to T1CONBITS with the help of typedef.
  • struct, union are are derived data types these contain int, float, double,char type varibles etc.
  • unsigned TCS:1 here ":value" represents bitfield and it is used to manage memory effciently. bitfiled is maximum number of bits that varible can use for getting value. for example, unsigned TCS:1 here the variable can take value 0 or 1 .it can't take more than value 1 becuase maximum number of bits allowed is 1.
  • volatile keyword tells value of variable can be changed at any time.

Related Solutions

Embedded computer systems: Configure and code clock for Pic24e referring to the example C code given...
Embedded computer systems: Configure and code clock for Pic24e referring to the example C code given below. a) Write code on how to configure bits that uses its fast RC oscillator with PLL to run at 40MHz. Assume the RC's frequency is 7.5MHz. b) Write code on how to configure bits that uses its primary crystal (XT) with PLL to run at 40MHz. Assume the external clock is a crystal oscillator of 8MHz. ====== Given C Code ======= #include "ConfigurationBits.h"...
hacking Embedded Operating Systems: The Hidden Threat EXPLAIN WINDOWS IoT (INTERNET OF THINGS) AND OTHER EMBEDDED...
hacking Embedded Operating Systems: The Hidden Threat EXPLAIN WINDOWS IoT (INTERNET OF THINGS) AND OTHER EMBEDDED SYSTEMS. WHAT ARE NIX EMBEDDED OPERATING SYSTEMS? HOW DO YOU PATCH EMBEDDED OPERATING SYSTEMS?.
Hello sir below is my code can you plz explain it line by line in details...
Hello sir below is my code can you plz explain it line by line in details #include<stdio.h> #include<stdlib.h> #include<stdbool.h> #include<string.h> #include<time.h> struct patient { int id; int age; bool annualClaim; int plan; char name[30]; char contactNum[15]; char address[50]; }; #define MAX_LENGTH 500 struct patient patients[100]; int patientCount = 0; struct claim { int id; int claimedYear; int amountClaimed; int remaininigAmount; }; struct claim claims[100]; void subscribe() { system("cls"); patients[patientCount].id = patientCount + 1; printf("Enter age: "); scanf("%d", & patients[patientCount].age); printf("\n\n%-25sHealth...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
My code is supposed to display a stacked bar chart of my average week. Can you...
My code is supposed to display a stacked bar chart of my average week. Can you help me locate my errors and fix them? I'm just so confused <!DOCTYPE html> <html lang = "en"> <head> <meta charset="UTF-8" /> <title>Assignment 3: My Weekly Schedule</title> <script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> <style type="text/css"> svg { font: 10px sans-serif; shape-rendering: crispEdges; } .axis path, .axis line{ fill: none; stroke: #000; } path.domain { stroke: none; } .y .tick line{ stroke: #ddd; } </style> </head> <body> <script...
You are required to develop a computer code that that can solve systems of ODE. The...
You are required to develop a computer code that that can solve systems of ODE. The code should request the user to choose one of the following methods for solving the system: ? Euler ? 4th Order Runge Kutta  
1. You can use my link provided, or you are free to choose another credible link...
1. You can use my link provided, or you are free to choose another credible link for another industry. On the site https://netmarketshare.com/search-engine-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22deviceType%22%3A%7B%22%24in%22%3A%5B%22Desktop%2Flaptop%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22searchEngine%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22searchEnginesDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222017-02%22%2C%22dateEnd%22%3A%222018-01%22%2C%22segments%22%3A%22-1000%22%7D we see market share data for Search engines. If you use another source of market share data please include the citation in the form of a url. a. Would you describe this market as competitive, monopolistic, or oligopolistic. Fully explain why. b. Calculate the 4 firm concentration ratio and the HHI. For the HHI assume the entire...
Consider the following statement: The fewer the uncollectible accounts, the better. Can you think of instances...
Consider the following statement: The fewer the uncollectible accounts, the better. Can you think of instances where this might not be the case? Support your points with an example of why fewer uncollectible accounts may not be better for business.
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T,...
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T, size> extends Throwable { private final T[] S = null ; public StackException(String s) { } public T top() throws StackException { if (isEmpty()) throw new StackException("Stack is empty."); int top = 0; return S[top]; } private boolean isEmpty() { return false; } public T pop() throws StackException { T item; if (isEmpty()) throw new StackException("Stack underflow."); int top = 0; item = S[top];...
Need an outline for my healthcare systems course I want a universal Healthcare system in which...
Need an outline for my healthcare systems course I want a universal Healthcare system in which everyone is given health insurance in the United states in which the government insures everyone. Outline topic is Design a universal health care system for the United State system Here are the elements needed in the essay: Model the system after that of another nation, if you'd like, or design one that is completely original. Make sure to take into consideration that the values...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT