A Device Driver Would Ordinarily Be Written In :__________ A. Machine Language B. Assembly Language C. (2024)

Answer:

1)

for(i = 0; i < NUM_VALS; ++i) {

if(userValues[i] == matchValue) {

numMatches++; } }

2)

for (i = 0; i < NUM_GUESSES; i++) {

scanf("%d", &userGuesses[i]); }

for (i = 0; i < NUM_GUESSES; ++i) {

printf("%d ", userGuesses[i]); }

3)

sumExtra = 0;

for (i = 0; i < NUM_VALS; ++i){

if (testGrades[i] > 100){

sumExtra = testGrades[i] - 100 + sumExtra; } }

4)

for (i = 0; i < NUM_VALS; ++i) {

if (i<(NUM_VALS-1))

printf( "%d,", hourlyTemp[i]);

else

printf("%d",hourlyTemp[i]); }

Explanation:

1) This loop works as follows:

1st iteration:

i = 0

As i= 0 and NUM_VALS = 4 This means for condition i<NUM_VALS is true so the body of loop executes

if(userValues[i] == matchValue) condition checks if element at i-th index position of userValues[] array is equal to the value of matchValue variable. As matchValue = 2 and i = 0 So the statement becomes:

userValues[0] == 2

2 == 2

As the value at 0th index (1st element) of userValues is 2 so the above condition is true and the value of numMatches is incremented to 1. So numMatches = 1

Now value of i is incremented to 1 so i=1

2nd iteration:

i = 1

As i= 1 and NUM_VALS = 4 This means for condition i<NUM_VALS is true so the body of loop executes

if(userValues[i] == matchValue) condition checks if element at i-th index position of userValues[] array is equal to the value of matchValue variable. As matchValue = 2 and i = 1 So the statement becomes:

userValues[1] == 2

2 == 2

As the value at 1st index (2nd element) of userValues is 2 so the above condition is true and the value of numMatches is incremented to 1. So numMatches = 2

Now value of i is incremented to 1 so i=2

The same procedure continues at each iteration.

The last iteration is shown below:

5th iteration:

i = 4

As i= 4 and NUM_VALS = 4 This means for condition i<NUM_VALS is false so the loop breaks

Next the statement: printf("matchValue: %d, numMatches: %d\n", matchValue, numMatches); executes which displays the value of

numMatches = 3

2)

The first loop works as follows:

At first iteration:

i = 0

i<NUM_GUESSES is true as NUM_GUESSES = 3 and i= 0 so 0<3

So the body of loop executes which reads the element at ith index (0-th) index i.e. 1st element of userGuesses array. Then value of i is incremented to i and i = 1.

At each iteration each element at i-th index is read using scanf such as element at userGuesses[0], userGuesses[1], userGuesses[2]. The loop stops at i=4 as i<NUM_GUESSES evaluates to false.

The second loop works as follows:

At first iteration:

i = 0

i<NUM_GUESSES is true as NUM_GUESSES = 3 and i= 0 so 0<3

So the body of loop executes which prints the element at ith index (0-th) index i.e. 1st element of userGuesses array. Then value of i is incremented to i and i = 1.

At each iteration, each element at i-th index is printed on output screen using printf such as element at userGuesses[0], userGuesses[1], userGuesses[2] is displayed. The loop stops at i=4 as i<NUM_GUESSES evaluates to false.

So if user enters enters 9 5 2, then the output is 9 5 2

3)

The loop works as follows:

At first iteration:

i=0

i<NUM_VALS is true as NUM_VALS = 4 so 0<4. Hence the loop body executes.

if (testGrades[i] > 100 checks if the element at i-th index of testGrades array is greater than 100. As i=0 so this statement becomes:

if (testGrades[0] > 100

As testGrades[0] = 101 so this condition evaluates to true as 101>100

So the statement sumExtra = testGrades[i] - 100 + sumExtra; executes which becomes:

sumExtra = testGrades[0] - 100 + sumExtra

As sumExtra = 0

testGrades[0] = 101

So

sumExtra = 101 - 100 + 0

sumExtra = 1

The same procedure is done at each iteration until the loop breaks. The output is:

sumExtra = 8

4)

The loop works as follows:

At first iteration

i=0

i < NUM_VALS is true as NUM_VALS = 4 so 0<4 Hence loop body executes.

if (i<(NUM_VALS-1)) checks if i is less than NUM_VALS-1 which is 4-1=3

It is also true as 0<3 Hence the statement in body of i executes

printf( "%d,", hourlyTemp[i]) statement prints the element at i-th index i.e. at 0-th index of hourlyTemp array with a comma (,) in the end. As hourlyTemp[0] = 90; So 90, is printed.

When the above IF condition evaluates to false i.e. when i = 3 then else part executes which prints the hourlyTemp[3] = 95 without comma.

Same procedure happens at each iteration unless value of i exceeds NUM_VAL.

The output is:

90, 92, 94, 95

The programs along with their output are attached.

A Device Driver Would Ordinarily Be Written In :__________ A. Machine Language B. Assembly Language C. (2024)

FAQs

A Device Driver Would Ordinarily Be Written In :__________ A. Machine Language B. Assembly Language C.? ›

Assembly is used mostly for device drivers and os kernels - and only for small bits of these, most of the code will be written in C (or, since recently, Rust).

What language are device drivers written in? ›

Device drivers are usually written in C, using the driver development kit. There functional and object-oriented ways to program drivers. Most I/O devices drivers for linux/unix systems are written in C. For some operating systems, C++ maybe used..

How are device drivers coded? ›

A driver module is linked into the kernel. The name of each symbol unique to a particular driver must not collide with other kernel symbols. To avoid such collisions, each function and data element for a particular driver must be named with a prefix common to that driver.

Why is driver software written in assembly language? ›

Despite its challenges, assembly language remains important for systems programming and low-level software development. Since it provides direct access to hardware resources and allows for highly optimized code, it is often used in applications such as embedded systems or device drivers.

What is a device driver in a computer? ›

A device driver is a software program without a user interface (UI) that manages hardware components or peripherals attached to a computer and enables them to function with the computer smoothly.

Are drivers written in C or C++? ›

All kernel-mode drivers should be written in C so that they can be recompiled with a system-compatible C compiler, relinked, and run on different Microsoft Windows platforms without rewriting or replacing any code.

How are drivers written? ›

Device drivers are written with standard interfaces that the kernel can call to interface with a device. Device drivers can also be software-only, emulating a device that exists only in software, such as RAM disks, buses, and pseudo-terminals.

What programming language is used for drivers? ›

Writing a Driver

Device drivers are typically written in C, using the Driver Development Kit (DDK). There are functional and object-oriented ways to program drivers, depending on the language chosen to write in. It is generally not possible to program a driver in Visual Basic or other high-level languages.

What is a driver in code? ›

A driver is a software component that lets the operating system and a device communicate. For example, when an app needs to read data from a device, it calls a function implemented by the operating system. The operating system then calls a function implemented by the driver.

Is C an assembly language? ›

C is sometimes incorrectly referred to as a “portable assembly language”. It isn't for three very important reasons: Code in C doesn't provide symbolic equivalents of CPU instructions and their arguments. C doesn't provide a way to access all of the capabilities of a processor's full instruction set.

Is software written in assembly language? ›

Low-level programming languages such as assembly language are a necessary bridge between the underlying hardware of a computer and the higher-level programming languages—such as Python or JavaScript—in which modern software programs are written.

Are graphics drivers written in C? ›

A modern graphics driver is many megabytes of source code, not counting the compilers and stuff to convert graphics shader source code into GPU code, which are even bigger - but not always part of the “driver proper”. Modern drivers are written in C or C++ (or a combination of those).

How do you categorize the device driver? ›

Device drivers are broadly split into two categories; generic and specific. Generic device drivers are used for broad purposes such as keyboard control and mouse interaction. These are generally included as part of an operating system and can be used for basic functionality without any additional input from the user.

What is my device driver? ›

In the Device Manager window, you can expand the categories of hardware devices and see the names of the drivers associated with each device. You can also double-click on a device to open its properties window, where you can find more information about the driver, such as its provider, date, version, and status.

What is defined device driver? ›

A device driver is software that allows your computer's operating system to communicate with a hardware device (such as a printer or a keyboard). It works like a translator between your computer's operating system and what you plug into it — whether it's a mouse, a printer, or a scanner.

What language is used for drivers? ›

Device driver software

Today, most programmers who write device drivers work either in the C or C++ programming languages because they offer excellent access to low-level instructions along with more complex program and data structures.

Can you write device drivers in C++? ›

To summarize: C++ can be used to write a device driver that operates under some basic restrictions.

What language is car software written in? ›

Automotive software is traditionally developed in C and C++, as these languages are most suitable for resource constrained embedded systems. However, these languages are highly prone to issues related to memory safety and data race conditions.

Top Articles
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 6245

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.