1

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.

mindriot
  • 5,413
  • 1
  • 25
  • 34
SineLaboreNihil
  • 953
  • 4
  • 11
  • 18
  • 1
    Translate the 5 bit numbers into decimals; you should be able to recognise whats happening after that. – Disillusioned Nov 23 '16 at 13:08
  • I think it's probably so that you only have 4 "wasted" zeros on the left. It's just a shorter version of `00000000`, `00000001`, `00000101`, etc. – J. Allan Nov 23 '16 at 13:08
  • Did you read the part just after this table ? These numbers are some arbitrary codes just to show why machine language is hard to read and why high level languages were created... – Malkocoglu Nov 23 '16 at 13:09
  • These 5 digits on the left represent the memory address of the instruction (or data) on the right. – Meena Alfons Nov 23 '16 at 13:12
  • Malkocoglu, I did read the part after the example and I understand the point they're trying to make, but I would also like to know why the machine code example was created in the way it was presented there. Is that really how a computer interprets instructions after they are compiled and why do we have two groups of bits? – SineLaboreNihil Nov 23 '16 at 13:12
  • See [ARM's instruction encoding](http://stackoverflow.com/questions/11785973/converting-very-simple-arm-instructions-to-binary-hex) as a modern example, and give a look at those of the x86, etc. architectures. – asu Nov 23 '16 at 13:15
  • 1
    "Sine Labore Nihil". Nec omnia laborum utilia – sehe Nov 23 '16 at 13:20

1 Answers1

2

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
dfranca
  • 5,156
  • 2
  • 32
  • 60