Why are addresses assigned to computer memory?

Why are addresses assigned to computer memory?


Why was something like ASCII code created?


Why was a system like variable declaration created?





Alesa:


Now, please take a look at the following program:

#include <stdio.h>

#include <stdlib.h>


int main(void){


puts("Hello, World");


return EXIT_SUCCESS;


}


Program output:


Hello, World


This is a program written using an integrated development environment called "Eclipse". In the Eclipse IDE, it is common to see "return EXIT_SUCCESS;" instead of "return 0;", which is seen in other integrated development environments. It's a unique feature. If we try to run the above program on the integrated development environment(=Microsoft Visual Studio) we are using, "Hello, World" will be displayed correctly.


As you can see, the program includes the line "#include <stdlib.h>".


Actually, in order to use "return EXIT_SUCCESS;", it is necessary to include the line "#include <stdlib.h>".


So, what does "#include <stdlib.h>" actually mean?


Alesa:


Yes, I've received another piece of information. As we mentioned earlier, the difference in integrated development environments means there are also differences in the compilers that translate the source code into machine code.


For example, when performing calculations with real numbers in the computer and attempting to round the result to 6 decimal places while discarding the 7th decimal place, there may be differences in how the rounding is performed, such as whether to round up or down.


Specifically, let's say we perform the numerical calculation "5.45678×3.45678=18.8628879684" within the computer.


If we want to display the result using the "%f" output conversion specifier allows you to display up to 6 decimal places. and print it to the command prompt screen, whether we round up the 7th decimal place to display "18.862888" or discard it to display "18.862887" depends on the processing system (compiler).



010101110101010100001010100・・・・





Yes,


Regarding character codes


why


are there things like character codes?


(ASCII code is one of several character codes,

other code are

Unicode,

Shift JIS code,

and so on...


Character code is a system that assigns numeric data to character data's image data.

If the character codes are different,

even the same character data can be assigned different numeric data.)


Is that what you're asking about?


Let's look into this a little bit in this world.


Let's try to analyze it.


010111010100100101010101111...


Because computers can only handle data made of 0s and 1s,

the image data of a character, for example, the image data of the character A or the symbol "+",

is made up of a collection of 0s and 1s.


In other words, characters and symbols are made up of a collection of 0s and 1s in image data format

and are handled by computers.


In other words, when a computer displays characters on a display,

the characters are image data...


So, when displaying characters on a computer,

if you correspond the image data of the character and the numeric value (such as ASCII code),

you can easily call and use the image data of the character using the numeric value.


I think the real story begins now, though...


0000000111//"


__________'''']]'''''''----''''''''''''''''


Aretha:

"It seems that the correspondence between numeric values and image data for characters is absolutely necessary."


When displaying the character "a" as an image (image data), it would be very time-consuming to create the image data from scratch. Therefore, it is more efficient to pre-store the image data of "a" on a computer and call it up for use from within the computer. In doing so, the image data of "a" is assigned a numerical value and this numerical value is used to call up and use the image data of "a" from within the computer. This is the process that is followed.



"I'll skip the discussion about the correspondence between numeric (ASCII code) and character image data.


By the way, the data stored in a computer's memory is managed in units of 8 bits (1 byte).

Each of these 8-bit units is assigned a number called an address, and when the CPU retrieves data, it uses that address number to retrieve the data."


"Let's say Solar stored data such as the number 1 in a certain area of the computer's memory."


"Yes," Solar replied.


"Then let's say Solar wants to retrieve and use that number 1 from the computer's memory," said Aretha.



Solar: "Yes 🌞"


Aretha: "How do you retrieve and use value 1 from a memory location in a computer?"


Solar: "Yes? 🌞 I don't know."


Aretha: "So, let's say that among many memory locations, the data value 1 is stored in an 8-bit section of one of them. How do you find the memory location that stores the data value 1 among many memory locations?"


Solar: "It is an intuition."


Aretha: "It may be an intuition. People in the past have thought of ways to store and retrieve data in memory. However, the computer can only retrieve the data value 1 from memory by assigning a number to each memory location and then specifying that number to retrieve the data value 1. There seems to be no other way."


For some reason, the computer cannot find a way to retrieve the data value 1 from memory without assigning a number to each memory location.


000000000000000000000000000...


Currently, even I, Aretha, am thinking of a way to retrieve the data value 1 stored in memory without assigning a number to each memory location, but I have not yet come up with an idea. Do any of you have a good idea?


How to retrieve the data value 1 stored in memory...


0001010101010010101010011111111...


0111010100101???


01010101010...?


0111001...


To retrieve the data value 1...


0101010100111110101010010101010101000...???


For example, let's say that the data value 1 is stored in memory location D. To retrieve the data value 1, you can only specify memory location D. There is no other way to retrieve the data value 1.


To specify memory location D, you need a name for memory location D. Since the computer only understands 0 and 1, the name for memory location D must correspond to a combination of 0 and 1 (i.e., a number).


In other words, when retrieving the data value 1, you call the name (for example, 00101010, which corresponds to a number) assigned to memory location D.


That is, when retrieving the data value 1, a certain number corresponds to the name assigned to memory location D.


01010111110101000101001010111...


Using the name (for example, 00101010) assigned to memory location D...


(Actually, the data stored in the computer's memory is managed in units of 8 bits (1 byte) per memory location. Each memory location is assigned an address number, and when the CPU retrieves data, it uses that address number to retrieve the data.)


00001010010101001111001010011...


To retrieve the data value 1, you need to use the number...



I need the name of the memory D where numerical data 1 is stored. The name of memory D can only be represented by a number that can be understood by a computer (for example, 00101010). It is troublesome to call numerical data 1 by typing 00101010 into the program, and it is difficult to remember the memory number (00101010) where numerical data 1 is stored. Therefore, the solution is variable declaration.


When you declare


int b;

,


it is equivalent to giving the name "b" to memory. This allows you to call or store data with the familiar name "b" without having to call or store data using the numerical value (address) assigned to memory. At this time, the number originally assigned to memory, such as 00101010, does not disappear or get overwritten by the name "b" assigned through variable declaration. If you want to store numerical value 1 in memory, with variable declaration, you can store numerical value 1 in memory with the name "b" by declaring


int b;

b=1;


.


You can display numerical value 1 using printf("%d",b);.


If there were no variable declaration system,


you would have to call or store numerical data 1 in memory using numbers such as 11001001,.


When you declare


int b;


and give the name "b" to memory, by displaying int type (4 bytes) next to the name "b",


you can manage memory of 1 byte × 4 together under the name "b".


Therefore, when int b; and b=1; are executed, numerical data 1 is stored in memory of 1 byte × 4, like 00000000 00000000 00000000 00000001.


When printf("%d",b); is executed, the data stored in memory named "b" and managed together in 1 byte × 4 memory, which is 00000000 00000000 00000000 00000001, is displayed on the command prompt screen as 1 using the %d output conversion specifier.



If


char b;

b=1;


are executed, numerical data 1 will be stored in 1 byte of memory as follows:


00000001.


When


printf("%d",b);


is executed,


the data stored in memory named "b" and managed together in 1 byte memory, which is


00000001,


is displayed on the command prompt screen as


1


using the %d output conversion specifier.

(Actually, when printf("%d",b); is executed, the data stored in memory named "b" and managed together in 1 byte memory, which is 00000001, is processed in an int type format, that is, over 4 bytes.


00000001


is stored in the int format,


which means it is stored as four bytes


00000000 00000000 00000000 00000001


and by using the %d conversion specifier,


it will be displayed as "1"


on the command prompt screen


when using printf to output it.)


Doing variable declarations

and assigning names to memory

is necessary and natural

for easy retrieval of data.









Solar: "Oh... you seem to be having fun doing something. 😊 Aretha-san."


Aretha: "Welcome, Solar-san."


Solar: "I was called, I flew over, and I have arrived, ooooohh... But, I have been here since earlier."


Aretha: "00000000000000000000111111111111..."


Solar: "In other words, whether a computer was made during the Indus Civilization or the Yellow River Civilization, you can only call up data stored in memory by assigning numbers to memory. And, it is complicated to call up data stored in memory by using the numbers (addresses) attached to memory, so we assign names to memory through variable declarations to call them up more easily. The reason why character image data corresponds to numbers (ASCII codes) is also for the same reason."


Solar: "For example, in the following program:"


#include <stdio.h>


int main()

{

printf("%c\n", 97);


return 0;

}


Program output:


a


Solar: "When displaying the character image data 'a' on the command prompt screen, ASCII code 97 is used. At this time, the computer uses the number (01100001 in decimal 97, ASCII code 97) assigned to the character image data 'a'. In other words, when displaying the character image data 'a' on the command prompt screen, we can call it up by the assigned ASCII code without calling up the character image data 'a' from the place where it is stored .


Aretha: "It seems to be like that."


Solar: "So... the appearance of ASCII magazine... is inevitable..."


Aretha: "11111100000... D-Did you hear that... 000000"


Solar: "Yes, the super important point here is the appearance of ASCII magazine. (laughs) The appearance of ASCII magazine is a natural flow. (laughs) Did you hear something like that?"


Aretha: "Ah..."


Solar: "By the way, how is data called up in the human brain?"


Aretha: "11111100000... How is data called up in the human brain...?"


Solar: "To call up data, a computer needs the name of the memory that stores the data... However, there should be something like memory in the human brain that stores data, but it doesn't have a name... It's amazing that we can call up the scenery we want to remember even though there is no mechanism like 'I'm going to call up the image data stored in memory No. 1111000 in the brain'. How do people call up data when they try to remember something?"


Aretha: "Yes, well... looking at everyone, I feel like in the memory storage of your brain, various data are piled up and written in multiple layers, so to speak..."


Aretha: "Therefore, it seems like things such as memory merging and changes are happening..."


Solar: "You think so?"


Aretha: "Giving an address (numeric value) to a memory is natural and necessary, and declaring variables is very convenient. That was the story of giving names to memory through variable declaration."


Solar: "Are we suddenly ending things here???"

  • Xで共有
  • Facebookで共有
  • はてなブックマークでブックマーク

作者を応援しよう!

ハートをクリックで、簡単に応援の気持ちを伝えられます。(ログインが必要です)

応援したユーザー

応援すると応援コメントも書けます

新規登録で充実の読書を

マイページ
読書の状況から作品を自動で分類して簡単に管理できる
小説の未読話数がひと目でわかり前回の続きから読める
フォローしたユーザーの活動を追える
通知
小説の更新や作者の新作の情報を受け取れる
閲覧履歴
以前読んだ小説が一覧で見つけやすい
新規ユーザー登録無料

アカウントをお持ちの方はログイン

カクヨムで可能な読書体験をくわしく知る