Severus does the magic

It is not too long after I told you that I was too cheap to pay $10 a month for github copilot and I came up with the idea for Severus, my own AI pair programmer. It was something that went boom. My blog usually doesn’t have more than 20 or 30 viewers a day (at its best) and for almost a week, I had more than 200 views per day. Since people showed interest in yet another AI pair programmer, I have decided to continue working on severus, more seriously.

Severus code generation
Severus is now capable of being accessed as an API

My plans for Severus

So in this article, I may discuss a bunch of problems I may face in the long path of creating Severus and making it available as an end-user software. There are some serious concerns, for example when I talked about the idea of Severus with one of my colleagues, he told me he is concerned about the confidential codes he has written.

Almost all of your concerns are valid (except the one who thinks this whole process is handled by the Illuminati) and those are my concerns as well. The next problem I may face is for the scaling, so I perhaps need to hire a well-educated DevOps engineer.

In this section, I explain all of my serious concerns and needs, and I expect some help from you, the kind readers of the article.

The Community

Creating a community around something which is honestly a weekend project, doesn’t seem like a good idea. You may say this thing happened for the Linux kernel as well. You’re right, but this is a little bit different. There are tons of tools which may work much better than Severus.

Also, it is important to know the place for creating the community. A subreddit? A discord server? A room on Matrix? An internet forum? I have no idea honestly.

So this is the biggest concern for me. The community!

Performance and text-generation glitches

The performance is good, thanks to huggingface inference API. Actually, knowing the fact that huggingface API exists, helped me with the implementation. But I still have some concerns here.

My main concern is that BLOOM starts generating some text which is not or cannot be classified as code. I tried different ways to get better results, but I still need some ways to verify the generated result is code and it’s not a text which includes the code. And this is really the hard part I guess.

For this purpose, I may need some help. Validation must be done on the results in order to get a good AI pair programmer, otherwise it’ll become more like an annoying colleague or an intern who knows something, but can’t gather his/her mind.

The Product

And final concern/plan is the product. For current use, I only have a simple application which runs on port 5000 on my laptop. Nothing more. There is no authentication and no user validation system, no monitoring, no scaling, no infrastructure. Basically a MacBook Pro which runs tons of programs daily and severus is currently one of them.

I had a VS Code extension in mind, also I thought of a web app as the MVP, when you can easily copy your code and then use it in your very own projects (and of course it won’t be the best choice for a confidential piece of code).

Although I have ideas in mind, I still need more brainstorming about how this project should be delivered to you as a product.

Conclusion

I still have a lot to do with this project. There might be some language detection to detect if the generated output is the code or not, and also there might be some more code validation to avoid mixing different programming languages.

Overall, this is one of the most difficult and at the same time the funnest projects I’ve ever done. I won’t give up on this, even if it seems like a painful and expensive hobby to people around me 🙂

 

Analyzing components of an electric circuit with YOLOv5

In past recent weeks, I did a lot with YOLOv5. A few weeks prior to this article, I wrote an article on why I love YOLOv5 and later, I did a project with YOLOv5 which was somehow a try for making something like symbolab or similar software.

I explained that project in details in my Persian blog (link) and I may write an English article on that project soon. But in this article specifically I am going to explain about a newly done project of mine!

Electric Circuit component analysis using YOLOv5

Introduction

After making the math equation OCR I got a few ideas in my head about doing identical projects but in different scopes and areas of my interest. Believe it or not, I am not really the type of person who sticks to only one thing and I tried to many different things in my life. As my job is making computer software and platforms, I have decided to use the knowledge I have in this field to improve my performance in the other fields as well.

I have studied Computer Hardware Engineering in the university and I know a thing or two about electronics. I have never been an electrician or an electronics expert but I have made some cool gear using Arduino, Raspberry Pi and even basic electronic components. I also am a big fan of YouTuber electroboom and like what he does a lot!

So this is the reason I started this project. I decided to make a computer vision program which helps us understand the components in a schematics and in this article, I will explain how I did it.

Who’s the audience of this article?

Since I am not a type of content creator or writer who bombards the audience with complex math and physics (or computer science) concepts, I have to say everyone.

But for being more specific, I have to say that everyone who’s enthusiastic about artificial intelligence, computer vision and electronics and is able to read English is my audience. At least in this particular article. Also if you are a newbie who wants to find their own path in the vast universe of computer science, this article will give you an idea about computer vision projects combined with deep learning.

Nikola Tesla

Previously done works

Although I didn’t want this article to be a thesis/research paper, I had to put this in the article. Honestly, I haven’t search about what people may have done with YOLOv5 (or other tools) to analyze electric or electronic circuitry.

I’m sure there are other minds out there who had thoughts of this and I appreciate their thoughts and also their efforts.

The research procedure

The problem

We have tons of circuit schematics in books or notes which students or enthusiasts can’t understand very well. Unlike math or physics formulas, there is no application or tool to find out what schematic represents what component therefore we need some tool to understand our circuits better.

The possible ways of implementation

  1.  Using OpenCV functions such as contouring and similar stuff to detect which shape is which.
  2. Using a pre-trained model for electrical components.
  3. Developing a CNN or similar network to detect the components.
  4. Fine-tuning YOLOv5 to our need.

Each of these ways, had their own problems. In the following lines, we’ll find out why most of them were inefficient for me.

Using OpenCV functions, although it’s first go-to for most of computer vision programmers but it is really problematic specially when you get pictures which are very close to each other. This is an example of my input data:

Example of input data

and as you can see, I have a battery in series with a capacitor and even to human eyes, these two can be mistaken! And remember, OpenCV doesn’t do magic and it is only a great tool for processing images.

The next way was to Find a pre-trained deep learning model which has the data of the components. It is a nice idea but it also has its own problems. For example, I had no idea which network is used, which libraries are used, etc. Also there is no mediapipe for electric circuitry where you are sure about its functionality in your projects.

Third way was my second favorite by far. Developing our own CNN or identical network for object detection or localization. It is cool, it can be efficient but the amount of work I had to put on it was actually out of my range of tolerance. Specially since I’m not doing these projects for graduation or money, I did not want to put too much effort on my project.

And last but not the least, Fine-tuning YOLOv5 for my needs, was the best solution I could ever think of. YOLOv5 is one of the best tools for quickly implementing your computer vision plus deep learning ideas. It also is a very very accurate and fast tool. So I went with this one.

Data gathering and preparation

YOLOv5 requires a set of labeled images. It means we need to have images of our topic of interest and nothing more.

Nicholas Renotte explains how to get data or images you need in this video. So if you want to do a similar project, I suggest giving that video a watch. But in my case, things were a little different.

I needed tons of schematics and on the other hand, I didn’t really want to spend a very long time labeling and preparing the data. So I have decided to draw a couple of schematics on a piece of A4 paper like this:

Example of my data

and for preparation, I just took photos of these drawings using my phone (Xiaomi Redmi Note 8 Pro) and then moved them to my computer.

For slicing them to small chunks of photos, I just used Adobe Photoshop (I know that might be surprising but I am too lazy to use any other tool) and then saved them in to a folder structure acceptable for YOLOv5.

The next part (which I always call the worst part of an A.I/Data project) was cleaning up the data and then labeling it. I used leabelImg in order to label my images since it has provided a YOLO type of labeling system.

Training YOLOv5

After doing all the hard stuff the time to train our beloved YOLOv5 arrived. Training YOLOv5 is fairly easy! You just have to follow their guide provided in their github repository to train your own version of YOLOv5.

Since the process of training YOLOv5 is easy and well-documented, I don’t really spend so much time explaining the process here. I only point out what I have done in order to get the best results.

I used 416×416 image sizes (if you’re not familiar with YOLOv5, you must know that their training script resizes the images) and a batch size of 32.

At the beginning I used their base weights (which is trained on COCO dataset) called yolov5s which stands for Small YOLOv5 and apparently, it has 7.2 million parameters (according to this table) and it wasn’t really good after almost 200 epochs. So I did reset my training process with yolov5m which stands for Medium YOLOv5 which has 21.2 million parameters.

To be honest, I know the number of parameters isn’t the only thing that matters, but for the love of God, let’s keep things simple.

Finally, with 416×416 images, batch size of 32, 500 epochs and medium model and almost five hours of waiting (since I was doing this process on my Macbook Pro and not in Google Colab), I got my desired results.

The result

The final result

As you can see, I got pretty good confidence levels on my components. Unfortunately, confidence levels for those inductors isn’t fit in the picture so for a better understanding of this resulting photo, I put this table here as well:

Confidence levels and coordinations

Future works

After finishing this project I’ve got a few ideas in my head. The very first thing is to generate a net list for a SPICE software. Imagine if you can draw a circuit on paper (Most of us engineers usually use paper to do our initial designs, right?) and then take a photo of it and boom! you have it in your SPICE software.

The second thing coming to my mind is actually combining this with an OCR software which can understand numbers and units we’ve used in our electrical circuitry. For example understands that 200K besides a resistor, means the resistor has 200 kilo ohms of electrical resistance.

Then, we can apply all these data to some calculator which can help us have a better understanding of our designs and gives us information about the behavior of our circuit in different situations such as changes in current, voltage or frequency.

Conclusion

In conclusion, I believe every kind of OCR can be helpful in our lives. I remember when I was a child there was some sort of pen-like device which could read verses of Quran and I liked the whole idea.

Later when I got older I decided to find out how that magical pen works and can we improve that? Yes Quran is very important for Muslim people and there is no doubt of that but that wasn’t enough in my opinion since that device could be used by visually impaired people. They could use that pen to understand Quran and other types of texts as well.

And now, I have the knowledge to make the world a better place to use the technology to people’s advantage. After making a real-time sign language translation program with A.I, I have decided to just conquer another realms of computer vision as well.

Lastly I have to say there is a very vast world of the unknown we can easily uncover using our knowledge and I try my best to do that.

Regards.

Why I love YOLOv5?

I am a big fan of Nicholas Renotte’s channel on YouTube. I also love computer vision and its combination with deep learning. A few months ago, Nicholas posted this video, which is about YOLOv5. I usually am too lazy to watch videos which are longer than 15 minutes and I watch them in a few episodes. But this video made me sit behind the laptop screen for over an hour and I’m sure I won’t regret it.

So let’s start the article and see where this story begins. As I mentioned earlier, I love computer vision specially when it’s combined with deep learning. I believe it can help us solve very complex problems of our projects with ease. My journey in world of these YOLO models have started almost a year ago, when I wanted to develop a simple object detection for detecting street signs.

Firstly, I found a lot of tutorials on darknet based training but l did not manage to get it to the work, specially since I have a mac, it could be a very realistic nightmare. So I guess YOLOv5 was a miracle. In this article, I am going to explain why I love YOLOv5 and why I prefer it to other YOLO versions.

What is YOLOv5?

According to their github repository, YOLOv5 is a family of deep learning models which is essentially trained on Microsoft’s COCO dataset. This makes it a very very general-purpose object detection tool which is fine for basic research and fun projects.

But I also needed to have my own models because I wanted to develop some domain-specific object detection software. So I realized they also provide a python script which helps you fine-tune and train your own version of YOLOv5.

So I basically fell in love with this new thing I have discovered. In the next sections, I will explain why I love YOLOv5!

Why I love YOLOv5?

Firstly, I invite you to see this chart, which shows the comparison of YOLOv5 with other commonly used object detection models:

And since there’s been a controversy about YOLOv5 claims about training time, inference time, model storage size, etc. I highly recommend you read this article on Roboflow’s blog.

So we can conclude the very first thing which made me happy is the speed and that’s right. The second thing by the way is the fact I am lazy. Yes, I am lazy and I know it.

I always tried to compile darknet and use it for having a YOLOv4 model and make my projects on top of YOLOv4 but when I saw how hard it can get and since I have a mac and I didn’t really want to fire-up an old computer for these projects, I was looking for something which does everything with a bunch of python scripts.

Since I discovered the YOLOv5, I started working with it and the very first project I have done was this pedestrian detection for a self-driving car.

Then, I started doing a lot of research and asking about what I can do with YOLOv5. I find out I can do pretty much anything I want with ease as they provided a lot of stuff themselves. Isn’t that good enough? Fine. Let me show you another youtube video of mine which I solved my crop problem with their internal functions.

If you’re not convinced yet, I have to tell you there is a great method which is called pandas in this family of models.

As the name tells us, it really outputs a pandas dataframe which you can easily use data from that dataframe. Let me set a better example for you. Considering we want to find out which plants are afflicted and which ones are not in a drone footage.

By using this method, we can simply make an algorithm which counts the amount of afflicted ones in a single frame, so we can easily find out how many afflicted plants we have in a certain area. The whole point here is that we have statistically right data for most of our researches.

The other example would be the same as my pedestrian detection system. We can command the car to get data first from the cameras to make sure we’re dealing with pedestrians and second get data from distance measurement system (which can be an Ultrasonic or LiDAR) to make sure when it should send braking command.

Conclusion

Let’s make a conclusion on the whole article. I love YOLOv5 because it made life easier for me, as a computer vision enthusiast. It provided the tools I wanted and honestly, I am really thankful to Ultralytics for this great opportunity they have provided for us.

In general I always prefer easy-to-use tools and YOLOv5 was this for me. I need to focus on the goal I have instead of making a whole object detection algorithm or model from scratch.

I finally can conclude that having a fast, easy-to-use and all-python tool for object detection was what I was always seeking and YOLOv5 was my answer.

I am glad to have you as a reader on my blog and I have to say thank you for the time you’ve spent on my blog reading this article. Stay safe!

How to be a hardware engineer

A computer, is made up of hardware and software. Lots of people like to write and develop software, so the internet is full of topics like “How to be a software engineer” or “how to write a computer program” and also, there is a lot of great and free tutorials on programming languages and frameworks. But, hardware engineering guides on the internet, are not as many as software’s.

In this post, I really want to write about “How to” be “a hardware engineer”. As it’s my favorite field in computer science and I study it in the university. So, if you want to be a computer hardware engineer, just read this and start searching about your favorites.

Definition

A computer engineer in general, is an engineer who designs, develops and tests computers. Both hardware and software. But, there are different types of “Computer engineer”. For example, I am a hardware engineer, my friend is software engineer, my other friend is network engineer, etc.

So, a hardware engineer is a computer engineer, who knows electronic and electrical engineering (I know, some of electronics/electrical engineering courses are taught to students of software engineering). But, if we go further, we’ll find that the “Hardware Engineer” is who “combines computer science and electronics”. So, this is what he/she does, learns computer science and electronics, then combines them and makes computer hardware.

Expertise and Fields

There are these fields in hardware engineering, and people can learn one of them to find a job or start their own business.

  1. Computer architecture :
    a computer architect, is a computer scientist who knows how to design logical level of a computer. In my opinion it’s the most-needed role in a team who design a new computer. When you study computer architecture, you learn mathematics behind the computer hardware, and also you learn how to design different logical circuits, and connect them together and make a computer at the logical level.
    So, if you love mathematics, and love computer programming and in general, computer science, this is your field. to learn more, you also can read my book (link)
  2. Digital Electronics :
    This one, is actually my favorite. Digital electronics is about implementation of logical designs. So, with digital electronics, you can make what you have designed using logic and mathematics.
    But for this field of hardware engineering, you need to know electronics and electrical engineering. So, if you like digital electronics, start studies on electrical engineering today!
  3. Digital Design :
    This part, is also my favorite, and I really like it more than digital electronics. It’s about simulation and synthesis, so you can really ‘feel’ the hardware you have designed.
    But how is it possible? The “Digital Designer” is a person who’s familiar with simulation and synthesis tools. Such as hSpice, LTSpice, ModelSim and languages such as Verilog or VHDL. It’s about design and programming, so if you’re a software engineer who wants to learn hardware engineering, this field is yours! But, usually hardware engineers learn this field after learning digital electronics.
    If you like to be a digital designer, start improving your programming and algorithm design today, it’s important to know how to code, and how to write an algorithm.
  4. Microcontrollers and Programmable devices :
    This field is not actually “Hardware Engineering”. But, it’s still dealing with hardware. Actually, it’s not “design and implementation” of the hardware, it’s “making hardware usable”. When you program an ATMega32 chip for example, you make a piece of silicon usable for driving motors and sensors.
  5. Artificial Intelligence :
    And finally, the common field! Artificial intelligence is the widest field in computer science. It’s applicable and functional in all fields of computer science.
    But how we can use it in hardware engineering? We can use AI to improve our hardware, for example our architectures can be analyzed by AI. We can make a hardware which has AI to solve problems (a.g. ZISC processors). And finally, we can use AI in Signal processing, which is usually referred as a field of hardware/electronics/audio engineering.

Start point

I tried to explain start points in previous part, but now, I explain general start point. To learn hardware engineering, you need to know discrete mathematics and logic. Also, you need to know how to show boolean functions like electrical circuits (a.k.a logical circuits). After learning these, you need to get familiar with computer architecture, and at the end, you can choose your favorite field. I have experiences in all fields (except AI and Signal processing) but my most favorites are digital design and digital electronics.

It all depends on you, to choose which field, but you need those basics and fundamentals to understand it. Also, if you improve your knowledge about computer science in general, you will be a successful computer engineer!

Good Luck 🙂

 

Importance of IoT

For the last 25 years, a ghost is flying over our world, it’s the ghost of “Internet”. From 80’s, internet became one of the most used tools for international communications, such as knowledge sharing. So, a lot of people started using internet to share knowledge, to do research or even to have fun. We can use internet in many different ways and this is why internet is important. You know, humans can’t live without air and water, but actually, electricity and internet are as important as them!

In 1982, a truck connected to the internet, it was the first attempt to connect non-digital things to the internet. Years after that, someone asked people of the world to call “connecting non-digital things to the internet”, Internet of Things or IoT for short. Actually a computer or a mobile phone is designed to be connected to internet, so we can’t call that IoT. But a wheelchair, a cigarette lighter, a coffee maker or even an oven are not designed to be connected to internet, so if we connect them to the internet, it’s IoT!

Concepts and Applications

The concept of IoT is to make everything around us online. You can control your coffee maker from work, and when you arrive home, you can have a cup of warm coffee. But, This is not the only concepts. It comes to make our lives safe, it comes to make our things accessible from everywhere. And about applications? As I told, the online-coffee maker is one of the best examples of IoT applications.

The main application of IoT is controlling everything remotely. Before IoT, remote controls used infrared to control lamps, outlets, TV’s, etc. But today, thanks to IoT, we can do that from longer distances, using the internet. For example, your home is in Iran, and you are in a vacation in Armenia, but you can control everything from Armenia! Everything you need is a reliable internet connection.

The importance

Now, let’s talk about the importance. Why IoT is important? is it anything except connecting devices like ovens and coffee makers to the internet? of course it is! It is actually the future of the hardware engineering and even the online world. Hardware engineers like me should learn IoT, because in near future, every single home accessory will become online, every streets of cities will be online, all farms will be online!

So, we need to learn IoT, but how? learning IoT is easy. You only need to know how to program microcontrollers, how to setup a development board (at all, hardware engineering), how to connect your board to the network and how to implement remote controls and connections. For example, you can use a NodeMCU board and a bunch of LED’s to make a bedside lamp, it’s even easier than writing a simple computer program for daily accounting.

Communication with other fields of computer science

IoT can’t be a complete knowledge/technology alone. All IoT experts have to know about one of fields of computer science. For example, a person who designed a system for traffic control, needs to store data from traffic lights or cameras, and then he/she needs to do data mining on that. Because this thing can be helpful in predictions about traffic. Or, if you design that simple bedside lamp, you have to write at least a good single-page interface for it. These are not basic things, and you can’t do all of them alone. To be honest, an IoT team is made up of some professionals/experts. What they do is cooperating about these issues.

Good Luck 🙂

Reverse engineering of 8086, from a calculator to the most used processor

If you have a laptop or desktop computer, you probably use a 8086-based CPU, or one implementation of x86 family to be exact. For example, I have a Lenovo laptop with a Core i5 CPU, which is based on x86 architecture. In this article, I want to talk about x86 architecture, and to explain how it works, I just start with the simplest one : 8086.

8086, is probably the first general-purpose processor made by Intel. This is why it’s famous, and in a lot of cases, people prefer to use it or study it. Everything is well-documented and also there are billions of tutorials and examples on how to use it! For example, if you search for “Interfacing Circuits”, you will find a lot of 8086-based computers made by people, connected to interface devices such as monitors, keyboards or mice.

Before we start reverse engineering, and make our simple x86-compatible computer, let’s take a look on the machine code structure of 8086. In this case, we just review Register addressing mode, because this mode is easier to understand or re-implement.

In this case, we can only take a look on a two-byte (or 16 bit) instruction code. Our instruction code looks like this :

Byte 1 Byte 0
|Opcode|D|W| |MOD|REG|R/M|

What are these? and why we should learn this? As we want to reverse engineer 8086 architecture and learn how it works, we need to know how this processor can understand programs! So, let’s check what are those fields in these bytes :

  • Opcode : a 6-bit number, which determines about operation (for example ADD, SUB, MOV, etc. )
  • D : Determines source or destination operand. To make reverse engineering process simple, we consider that as constant 1. So, REG field in byte 0 is always destination.
  • W : Determines data size, and like D, to make reverse engineering process simple, we consider it as a constant 1. So, we only can do operations on 16 bit numbers.
  • MOD : Determines mode, as we decided before, we only model the register addressing mode, so we need to consider mode as constant 11.
  • REG and R/M : REG shows us source, R/M shows us destination. Please pay attention, we made this special case because we are going to model register addressing mode. For other modes, we can’t consider R/M as destination.

Now, we learned how 8086 can understand programs, for now, we have some instruction code like this :

Opcode D W MOD REG R/M
xxxxxx 1 1 11 xxx xxx

Let’s assign codes to our registers. As we decided to simplify our reverse engineering process, and also we decided to use only 16 bit registers, I prefer to model four main registers, AX, BX, CX and DX. This table shows us codes :

Code Register
000 AX
001 CX
010 DX
011 BX

As you can see, now we are able to convert instructions to machine code. To make reverse engineering process even simpler, we can ignore “MOV”, but I prefer to include MOV in my list. So, let’s find opcodes for MOV, ADD and SUB.

Opcode Operation
100010 MOV
000001 ADD
010101 SUB

Now, we can convert every 8086 assembly instruction using the format we have. For example this piece of code :

MOV AX, CX 
MOV BX, DX
ADD AX, BX

Now, if we want to convert this piece of code to machine code, we have to use the tables we made. Now, I can tell you these codes will be :

1000101111000001
=> 0x8bc1

1000101111011010
=> 0x8bda

0000011111000011
=> 0x07c3

Now, we can model our very simple x86-based computer. But a note to mention, this has a lot of bugs! For example, we can’t initialize registers, so we need to study and implement immediate addressing mode, also, we can’t read anything from memory (x86 is not a load/store architecture, and it lets people work with data stored in memory directly!). But I think, this can be helpful if you want to study this popular processor or do any projects with it.

How to make a computer program

This is a cliché in IT and computer related blogs. You can find at least one topic on How to make a computer program in every blog written by a computer expert (scientist, engineer or experimental expert). So, I also decided to write about it. In this topic, I’m going to explain how your idea can be a program.

I’m not a startup or business person, and I hate when someone wants to teach other people how to have an idea so I consider you already have an idea, and you want to implement your idea as a computer program. Let’s start!

Choose your target hardware

Unfortunately, a lot of programmers ignore this important step, but if you consider a special hardware to develop and implement your ideas, you will have two points :

  1. You learn a new hardware architecture (and maybe organization)
  2. You help someone who wants a specific application on that hardware.

Sometimes, you realize that writing a calculator is pretty stupid. Of course it is when you write a calculator for Windows or macOS. But, when you write a calculator for Arduino, which can interact with a keypad and displays, it’s not.

Write Algorithm

Actually, algorithm is explaining the way we solve the problems. So, we need to write the steps of our solution and test it. Sometimes, when we write a simple algorithm, it’s not efficient at all, and needs a lot of improvements. Imagine this (This algorithm makes all even numbers lesser than 100:

while( a < 100){
 if(a%2 == 0){
  puts(a);
 }
 a++;
}

This is a piece of larger code. But wait,  how can we improve that? That if there can make this piece of code slower. But, if we consider a = 0, we can write something like this :

for(int a = 0; a < 100; a + 2){
 puts(a);
}

You know, I wrote a shorter code here. Also, this short code has a better structure of making all even numbers lesser than 100.  But I think both of these codes have the same time complexity, so there is no difference. If we had two nested loops, and the inner loop’s condition had effects on the outer loop’s condition, we had to spend time on calculating time complexity and optimizing it.

Finally, you will realize there are some “classic” algorithms, which are already optimized, and you can just use them, and model your idea with them.

Choose the language

This step is also one of the most important ones. Imagine if you want to program an AVR chip, of course JavaScript is not the best choice. There are tools which allow you to write programs for those chips in JS, but the language is not made for communication with AVR! But, when you want to program a website, specially when you’re dealing with front-end stuff, C is not your best choice! But wait, if the program we want to make is a general purpose desktop program or a school/university project, we are actually free to choose the language!

Imagine we want to write a simple program, which does Addition with bitwise operations. We can write our program in C/C++ like this :

#include <stdio.h>

int bitwiseAdd(int x, int y){
 while(y != 0) {
  int carry = x & y;
  x = x ^ y;
  y = carry << 1; 
 }
 return x;
}

int main(){
 printf("%d\n", bitwiseAdd(10 , 5));
 return 0;
}

And you can write it in Ruby like this :

def bitwiseAdd(x, y)
 while y != 0
  carry = x & y
  x = x ^ y
  y = carry << 1
 end
 return x
end

puts bitwiseAdd(10, 15)

But, when you want to directly communicate with hardware, you’ll need a low-level language. C/C++ are actually mid-level languages. They can help you communicate with hardware (like this piece of AVR code) :

while(1){
 PORTC.1 = 0;
 delay_ms(1000);
 PORTC.1 = 1;
 delay_ms(1000);
}

or like that bitwiseAdd(x, y) function , they can help us write normal programs. But Assembly language is a really low-level language. We can use it when we need to talk to our hardware directly.

You see, all programming languages can help us, but depending on the conditions, we can use different languages.

And …?

And now, you probably know how a computer program is made. But, if you really want to become a developer, you have to study about paradigms, methodologies, etc. I tried to keep it simple in this article, but later, I’ll write about those topics more.

Microcontrollers, Design and Implementation released!

It was about two years I started serious study on computer architecture. In these years, I learned a lot and I could simulate and implement a microprocessor, similar to real ones. In Summer 2016, I decided to share my experience with others. Then, I started writing this book. This book has seventeen chapters, and after reading this book, you will have a concept of computer architecture.

Chapters

  • License – Licensing and Copyrights
  • Introduction – A quick review of the book, defining target audience of the book.
  • Chapter 1 : What’s a microcontroller? – This chapter, defines a microcontroller. After reading this chapter you’ll understand the internal parts of a microcontroller. It’s completely theory, but you need the concepts.
  • Chapter 2 : How to talk to computer? – In this chapter, we have a quick view on programming and then, machine language. We determine the word size of our processor in this chapter.
  • Chapter 3 : Arithmetic Operations – This chapter focuses on arithmetic operations in base 2.
  • Chapter 4 : Logical Operations – This is all about boolean algebra, the very basic introduction to logical circuits.
  • Chapter 5 : Logical Circuits – Our journey starts here, we learn how to make logics using NAND in this chapter, and then, we learn the logic gates.
  • Chapter 6 : Combinational Circuits – This chapter is where you learn how to combine simple logics together and make more complex logics. Actually, you learn how to implement Exclusive OR and Exclusive NOR using other gates.
  • Chapter 7 : The First Computer – In this chapter, we make a simple Addition Machine.
  • Chapter 8 : Memory – In this chapter, we just take a look on sequential circuits.
  • Chapter 9 : Register File – After we learned sequential circuits, we make registers and then, we make our register file.
  • Chapter 10 – Computer Architecture – In this chapter, we’ll learn theory and basics of computer architecture and organization .
  • Chapter 11 – Design, Advanced Addition Machine – In this chapter, we add memory blocks to our addition machine.
  • Chapter 12 – The Computer (Theory) – In this chapter, we decide about what our computer should do. Actually, we design a simple ISA.
  • Chapter 13 – Arithmetic and Logical Unit – Now, it’s time to design our ALU.
  • Chapter 14 – Program Structure – In this chapter we decide about programming and machine language, and we design a simple instruction code.
  • Chapter 15 – Microcontroller – And finally, we add the RAM to our ALU, and we’ll have our simple microcontroller.
  • Chapter 16 – Programming and Operating System – In this chapter, we actually talk about the software layer of computers.
  • Chapter 17 – The Dark Side of The Moon – The final chapter, is all about making real hardware, we take a look at transistors, integrated circuits and HDL’s here.

Link to PDF File : Download