0

Let's say I did an instruction such as MOV R1, #9. Would this store the binary number 9 in binary in memory in ARM Assembly? Would the ARM Assembly code see the number 00001001 stored in the location of R1 in memory? If not what how would it store the decimal number 9 in binary?

2
  • R1 is a 32-bit register. Yes, when it comes to the actual hardware - everything is stored and handled in binary. Would the ARM Assembly code see the number 00001001 stored in the location of R1 in memory? - this is rather awkwardly put. The code does not see anything as it has no eyes... Commented Nov 14, 2019 at 15:50
  • Related: stackoverflow.com/questions/58849919/… is basically an earlier version of the same question. Commented Nov 14, 2019 at 18:05

3 Answers 3

0

The processor's storage and logic are composed of gates, which manipulate values as voltages.  For simplicity, only two voltages are recognized: high and low, making a binary system.

The processor can manipulate (compute with) these values using simple boolean logic (AND, OR, etc..) — this is called combinational logic.

The processor can also store binary values for a time using cycles in logic (here think circular, as in cycles in a graph) called sequential logic.  A cycle creates a feedback loop that will preserve values until told to preserve a new one (or power is lost).

Most anything meaningful requires multiple binary values, which we can call bit strings.  We can think of these bit strings as numbers, characters, etc.., usually depending on context.

The processor's registers are an example of sequential logic used to store bit strings, here strings of 32 bits per register.

Machine code is the language of the processor.  The processor interprets bit strings as instruction sequences to carry out.  Some bit strings command the processor to store values in registers, which are composed of gates using strings of sequential logic, here 32 bits per register: each bit stores a value as a voltage in a binary system.

The registers are storage, but the only way we can actually visualize them is to retrieve their values using machine code instructions to send these values to an output device for viewing as numbers, characters, colors, etc..

In short, if you send a number #9 to a register, it will store a certain bit string, and some subsequent machine code instruction will be able to retrieve that same bit pattern.  Whether that 9 represents a numeric 9 or tab character or something else is a matter of interpretation, which is done by programming, which is source code ultimately turned into sequences of machine code instructions.

Sign up to request clarification or add additional context in comments.

Comments

0

Everything is always binary in a computer; decimal and hex are just human-friendly notations for writing the values that a binary bit-pattern represents.

Even after you convert a binary integer to a string of decimal digits (e.g. by repeated division by 10 to get digit=remainder), those digits are stored one per byte in ASCII.

For example the digit '0' is represented by the ASCII / UTF-8 bit-pattern 00110000 aka hex 0x30 aka decimal 48.

We call this "converting to decimal" because the value is now represented in a way that's ready to copy into a text file or into video memory where it will be shown to humans as a series of decimal digits.

But really all the information is still represented in terms of binary bits which are either on or off. There are no single wires or transistors inside a computer that can represent a single 10-state value using e.g. one of ten different voltage levels. It's always either all the way on or all the way off.


https://en.wikipedia.org/wiki/Three-valued_logic aka Ternary logic is the usual example of non-binary logic. True decimal logic would be one instance of n-valued logic, where a "bit" can have one of 10 values instead of one of 3.

In practice CPUs are based on strictly binary (Boolean) logic. I mention ternary logic only to illustrate what it would really mean for computers to truly use decimal logic/numbers instead of just using binary to represent decimal characters.

1 Comment

Setun seems to remain the only example of a ternary-logic computer actually implemented in hardware. Remember it being mentioned during my university course...
0

A processor has a number of places to store content; you can call it a memory hierarchy: „Memories“ that are very close to the processor are very fast and small, e.g. registers, and „memories“ that are far from the processor are slow and large, like a disk. In between are cache memories at various levels and the main memory.
Since these memories are technologically very different, the are accessed in different ways: Registers are accessed by specifying them in assembly code directly (as R1 in MOV R1, #9), whereas the main memory storage locations are consecutively numbered with „addresses“.
So if you execute MOV R1, #9, the binary number 9 is stored in register 1 of the CPU, not in main memory, and an assembly code reading out R1 would read back number 9.
All numbers are stored in a binary format. The most well known are integers (as your example binary 00001001 for decimal 9), and floating point.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.