Get the App
SLTechnology News&Howtos  ›  Development  › 

How to choose C language and Rust for hardware Abstract programming

Shulou Source: shulou.com Published: 2022-06-02 03:20:18 09月11日 Update

Today, I will show you how to choose C language and Rust for hardware abstract programming. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

Using type-level programming in Rust can make hardware abstraction more secure.

Rust is an increasingly popular programming language and is regarded as the best choice for hardware interfaces. It is usually compared to the level of abstraction of C. This article describes how Rust handles bitwise operations in a variety of ways and provides a solution that is both secure and easy to use.

< 如显示不全,请左右滑动 >

The language was born in the official description overview C in 1972 C is a general-purpose programming language with simple expressions, modern control flow and data structures, and a rich set of operators. (source: CS basics) C is an imperative language designed to be compiled in a relatively simple way to provide low-level access to memory. (source: W3schools.in) Rust2010 is a language that gives everyone the ability to build reliable and efficient software (source: Rust website) Rust is a multi-paradigm system programming language that focuses on security (especially security concurrency). (source: Wikipedia) bitwise operation of register values in C language

In the field of system programming, you may often need to write hardware drivers or interact directly with memory-mapped devices, and these interactions are almost always done through memory-mapped registers provided by hardware. Typically, you interact with these registers by performing bitwise operations on certain fixed-width numeric types.

For example, suppose an 8-bit register has three fields:

+-+ | (unused) | Kind | Interrupt | Enabled | +-+ 5-7 2-4 1 0

The number below the field name specifies the bits that the field uses in the register. To enable this register, you will write the value 1 (00000001 in binary) to set the bit of the Enabled field. However, in general, you do not want to interfere with the existing configuration in the register. Suppose you want to enable interrupts on the device, but also make sure the device remains enabled. To do this, you must combine the value of the Interrupt field with the value of the Enabled field. You can do this by bit-by-bit operation:

1 | (1)

Tags: Registers fields types numbers hardware languages security errors programming code offset generation compilation operations binaries programs runs memory parameters methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker OPPO Reno Shulou Tech Info Microsoft