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?
1The 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 – 2019-07-25T14:25:09.537
@Mokubai Yeah, I know it and thats my point. How is that it is converted in 1 clock cycle? – ralf – 2019-07-25T15:08:32.323
1It 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 – 2019-07-25T15:17:43.387
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 – 2019-07-25T19:43:55.947
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 – 2019-07-25T23:37:10.613
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 – 2019-07-26T01:32:04.197Thank you, now I'm satisfied with this answer :) The instruction is "load immediate" btw :) – ralf – 2019-07-26T16:33:48.640