SineLaboreNihil SineLaboreNihil - 12 days ago 6
C++ Question

Machine Language Instruction on C++ Tutorial

I started learning C++ on the website cplusplus.com and there is a tutorial about the language. In that tutorial the first lesson is on compilers and in that lesson, that can be found at http://www.cplusplus.com/doc/tutorial/introduction/, they give the following example:


A single instruction to a computer could look like this:

00000 10011110


A particular computer's machine language program that allows a user to input two numbers, adds the two numbers together, and displays the total could include these machine code instructions:

00000 10011110
00001 11110100
00010 10011110
00011 11010100
00100 10111111
00101 00000000



My question is why do they put 5 bits in front (on the left side) separate from the other 8 bits on the right side? What does the group of 5 bits on the left mean? Does that group tell the computer how to interpret the 8 bits on the right? For example does it tell the computer that what's following on the right side is a number or a character or an operator? I have tried to find an answer to this question on the Internet, but I couldn't find anything that would clear things up for me. If anyone could provide me with a clear answer in simple terms that would be much appreciated.

Answer

As noted it seems to be arbitrary, one possible explanation is that it's separating operators and operands, but as it's sequential the best guess is that it's just the instruction address:

00000 => address 0
00001 => address 1
00010 => address 2
00011 => address 3
00100 => address 4
00101 => address 5

Machine code instructions are hardware dependent, here are some examples separating operator and operands

[  op  |        target address        ]
    2                 1024               decimal
 000010 00000 00000 00000 10000 000000   binary
Comments