1

Let's assume that I want to add 2 decimal numbers and print the result on screen. For example 12345678 + 343567. I know that it is done on values in registers, on logic "AND" gates etc. but my question is how does computer know how this number (12345678) representation looks in binary? For example for my microcontroller it takes 1 clock cycle (135ns) to input value (8 bits) to a register and the same amount of time to add R1 to R2. So how is it possible that it is done so quickly? Converting inputted decimal number to its binary form and storing in register in 1 clock cycle.

Also if CPU uses IEEE 754 notation it has to do much more operations. This may be easy and silly question but i cannot understand it. Can someone please explain me how it is done that computer knows so fast to which logic gate pass the current and to which not to do it, to make binary representation of a decimal number?

ralf
  • 11
  • 2
  • 1
    The first idea to get out of your head is that anything is stored in your computer as anything other than binary digits. The number 123456 is literally a bunch of 1s and 0s in the computer memory and CPU. You *see* it as 123456 because it gets converted to something easy for you to comprehend. – Mokubai Jul 25 '19 at 14:25
  • @Mokubai Yeah, I know it and thats my point. How is that it is converted in 1 clock cycle? – ralf Jul 25 '19 at 15:08
  • 1
    It isn't converted at all to do the actual addition, it is already in the right format of binary. To show you the result is where a lot of work is done. – Mokubai Jul 25 '19 at 15:17
  • 1
    *"Converting inputted decimal number to its binary form and storing in register in 1 clock cycle."* -- Your assumption is wrong. If you start with a string of decimal digits (i.e. text in ASCII code), then an input conversion *routine* will require a few dozen instruction cycles to generate the binary value. – sawdust Jul 25 '19 at 19:43
  • But still, for example this instruction "LDI R26,138" takes 1 clock cycle to be done and after that 10001010 is in 26th register. Am i missing something important here? – ralf Jul 25 '19 at 23:37
  • You neglect to specify an instruction set. That looks like it could be a `load literal value` instruction. The actual machine instruction (as stored in the computer memory) contains the value in binary form. Only when you write out the instruction in mnemonic form is the value in decimal form, but could also be expressed in any radix you choose (e.g. hexadecimal). Any conversion of the source code is done by the assembler. Loading a literal value is not "input". It is a known value already in memory as a constant. So yes, you are missing something important. – sawdust Jul 26 '19 at 01:32
  • Thank you, now I'm satisfied with this answer :) The instruction is "load immediate" btw :) – ralf Jul 26 '19 at 16:33

0 Answers0