Читать книгу Beginning Programming All-in-One For Dummies - Wallace Wang - Страница 17

Talking to a processor in machine language

Оглавление

To understand how machine language works, you have to understand how processors work. Basically, a processor consists of nothing more than millions of tiny switches that can turn on or off. By turning certain switches on or off, you can make the processor do something useful.

Instead of physically turning switches on or off, machine language lets you turn a processor’s switches on or off by using two numbers: 1 (one) and 0 (zero), where the number 1 means “turn a switch on” and the number 0 means “turn a switch off.” So a typical machine language instruction might look like this:

1011 0000 0110 0001

If the preceding instruction doesn’t make any sense, don’t worry. The point is that machine language is just a way to tell a processor what to do.

Using 1s and 0s is binary arithmetic. Because binary arithmetic can be so hard to read, programmers also represent binary numbers in hexadecimal. Where binary arithmetic uses only 2 numbers, hexadecimal uses 16 numbers and letters (0–9 and A–F). So, the binary number 1011 0000 0110 0001 could be represented as the hexadecimal number B061.

Machine language is considered the native language of CPUs, but almost no one writes a program in machine language because it’s so tedious and confusing. Mistype a single 1 or 0, and you can accidentally give the wrong instruction to the CPU. Because writing instructions in machine language can be so difficult and error-prone, computer scientists have created a somewhat simpler language: assembly language.

Beginning Programming All-in-One For Dummies

Подняться наверх