{"id":402,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:25:59","modified_gmt":"2020-08-22T20:25:59","slug":"this-is-the-page-title-toplevel-235","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=402","title":{"rendered":"Computer Languages"},"content":{"rendered":"\n<title>Computer Languages<\/title>\n<subtitle>Assembly Languages<\/subtitle>\n<p>\nThe instructions that a <glossary>CPU<\/glossary> fetches from memory and executes are not at all understandable\nto human beings.\nThey are machine codes which tell the computer precisely what to do.\nThe hexadecimal number <em>0x89E5<\/em> is an Intel 80486 instruction which copies the\ncontents of the ESP <glossary>register<\/glossary> to the EBP register.\nOne of the first software tools invented for the earliest computers was an assembler,\na program which takes a human readable source file and assembles it into\nmachine code.\nAssembly languages explicitly handle registers and operations on\ndata and they are specific to a particular microprocessor.\nThe assembly language for an Intel X86 microprocessor is very different\nfrom the assembly language for an Alpha AXP microprocessor.\nThe following Alpha AXP assembly code shows the sort of operations that a\nprogram can perform:\n<pre>\n    ldr r16, (r15)    ; Line 1\n    ldr r17, 4(r15)   ; Line 2\n    beq r16,r17,100   ; Line 3\n    str r17, (r15)    ; Line 4\n100:                  ; Line 5\n<\/pre>\n<p>\nThe first statement (on line 1) loads register 16 from the\naddress held in register 15.\nThe next instruction loads register 17 from the next location in\nmemory.\nLine 3 compares the contents of register 16 with that of register 17\nand, if they are equal, branches to label <em>100<\/em>.\nIf the registers do not contain the same value then the program\ncontinues to line 4 where the contents of r17 are saved into memory.\nIf the registers do contain the same value then no data needs to\nbe saved.\nAssembly level programs are tedious and tricky to write and prone to\nerrors.\nVery little of the Linux kernel is written in assembly language and\nthose parts that are are written only for efficiency and they are\nspecific to particular microprocessors.\n<h3>The C Programming Language and Compiler<\/h3>\n<p>\nWriting large programs in assembly language is a difficult and time\nconsuming task.\nIt is prone to error and the resulting program is not portable, being\ntied to one particular processor family.\nIt is far better to use a machine independent language\nlike C.\nC allows you to describe programs in terms of their logical algorithms and the data\nthat they operate on.\nSpecial programs called compilers read the C program and translate\nit into assembly language, generating machine specific code from it.\nA good compiler can generate assembly instructions that are very\nnearly as efficient as those written by a good assembly programmer.\nMost of the Linux kernel is written in the C language.\nThe following C fragment:\n<pre>\n        if (x != y)\n                x = y ;\n<\/pre>\n<p>\nperforms exactly the same operations as the previous example assembly code.\nIf the contents of the variable <tt>x<\/tt> are not the same as the contents\nof variable <tt>y<\/tt> then the contents of <tt>y<\/tt> will be copied to <tt>x<\/tt>.\nC code is organized into routines, each of which perform a task.\nRoutines may return any value or data type supported by C.\nLarge programs like the Linux kernel comprise many separate C source\nmodules each with its own routines and data structures.\nThese C source code modules group logical functions such as\nfilesystem handling code.\n<p>\nC supports many types of variables, or locations in memory which\ncan be referenced by a symbolic name.\nIn the above C fragment <tt>x<\/tt> and <tt>y<\/tt> refer to locations in memory.\nThe programmer does not care where in memory the variables are put, it\nis the linker (see below) that has to worry about that.\nSome variables contain different sorts of data,\ninteger and floating point and others are pointers.\n<p>\nPointers are variables that contain the address, the location in memory\nof other data.\nConsider a variable called <em>x<\/em>, it might live in memory at address\n<em>0x80010000<\/em>.\nYou could have a pointer, called <em>px<\/em>, which points at <em>x<\/em>.\n<em>px<\/em> might live at address <em>0x80010030<\/em>.\nThe value of <em>px<\/em> would be <em>0x80010000<\/em>: the address of the variable <em>x<\/em>.\n<p>\nC allows you to bundle together related variables into data structures.\nFor example,\n<pre>\n        struct {\n                int i ;\n                char b ;\n        } my_struct ;\n<\/pre>\n<p>\nis a data structure called <tt>my_struct<\/tt> which contains two elements,\nan integer (32 bits of data storage) called <tt>i<\/tt> and a character (8 bits\nof data) called <tt>b<\/tt>.\n<p>\n<subtitle>Linkers<\/subtitle>\n<p>\nLinkers are programs that link together several object modules and libraries\nto form a single, coherent, program.\nObject modules are the machine code output from an assembler or compiler and contain\nexecutable machine code and data together with information that allows the linker\nto combine the modules together to form a program.\nFor example one module might contain all of a program&#8217;s database functions and\nanother module its command line argument handling functions.\nLinkers fix up references between these object modules, where a routine or data\nstructure referenced in one module actually exists in another module.\nThe Linux kernel is a single, large program linked together from its\nmany constituent object modules.\n","protected":false},"excerpt":{"rendered":"<p>Computer Languages Assembly Languages The instructions that a CPU fetches from memory and executes are not at all understandable to human beings. They are machine codes which tell the computer precisely what to do. The hexadecimal number 0x89E5 is an &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=402\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-402","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=402"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/402\/revisions"}],"predecessor-version":[{"id":525,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/402\/revisions\/525"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}