Low level computing construct Programming CS208
Slide 2Assembly Language Assembly dialect permits us to utilize advantageous shortenings (called mental aides ) for machine dialect operations and memory areas. Every low level computing construct is particular to a specific equipment design, and must be utilized on a machine of that engineering. A low level computing construct program must be converted into machine code before it can be executed. The program that advises the PC how to play out the interpretation is called a constructing agent .
Slide 3Assembly Language When a processor chip is planned, it is intended to comprehend and execute an arrangement of machine code guidelines ( OpCodes ) remarkable to that chip. One stage up from machine code is gathering code. Each machine code direction is given a memory helper (name), with the goal that it is less demanding for individuals to compose code. There is for the most part a coordinated correspondence between the low level computing constructs memory aide directions and the machine dialect numeric guidelines.
Slide 4Model Assembly Instructions Our low level computing construct guidelines have two sections: The operation code indicates the operation the PC is to complete (include, look at, and so forth) An address that permits the direction to allude to an area in principle memory The CPU runs every guideline in the program, beginning with guideline 0, utilizing the get decipher execute cycle.
Slide 5Review of the Fetch-Decode-Execute Cycle The CPU brings the following direction from the address contained in the Program Counter and places the guideline in the Instruction Register . At the point when a program begins, the program counter contains 0, so the direction at address 0 is gotten. Instantly after the direction get, the CPU adds 1 word to the substance of the Program Counter , with the goal that it will contain the address of the following successive guideline.
Slide 6Review of the Fetch-Decode-Execute Cycle The CPU unravels the direction in the Instruction Register and figures out what operations should be done and what the address is of any operand that will be utilized. The predefined operation is executed (include, think about, and so on). After execution of the guideline has been finished the cycle starts from the very beginning once more (unless the direction ends the program).
Slide 7CPU
Slide 8CPU Registers The Instruction Register (IR) contains the real guideline which is at present being executed by the CPU. The Status Register records the aftereffect of contrasting the substance of enlist An and the substance of enlist B. The Program Counter (PC) contains the address of the following direction to be executed by the program.
Slide 9CPU Registers A & B hold the operands for every number juggling operation (ie. the qualities on which the operation will be performed). After the operation has been completed, the outcome is constantly put away in Register B. In this way, after a math operation has been played out, the second operand is no longer put away in Register B, since it has been overwritten by the consequence of the operation.
Slide 10CPU Registers After a correlation has been done, the Status Register will hold a code that stores the consequences of the examination. The outcomes are coded as takes after: - 1 if (A < B) 0 if (A = B) 1 if (A > B)
Slide 11Model Assembly Language Instructions Operation What it intends to the CPU STP Stop the program LDA Load enlist A with incentive from a specified memory area LDB Load enlist B with incentive from a specified memory area STR Store enroll B incentive to a predefined memory area INP Store information contribution by client to a predetermined memory area PNT Print the esteem put away in a predetermined memory area to the screen
Slide 12Model Assembly Language Instructions Operation What it intends to the CPU JLT Jump if not as much as (Status enlist = - 1) to a predefined memory area JGT Jump if more prominent than (Status enlist = 1) to a predefined memory area JEQ Jump if parallel (Status enlist = 0) to a predetermined memory area JMP Unconditional hop to a predetermined memory area CMP Compare enlist A to enlist B and set Status Register esteem
Slide 13Model Assembly Language Instructions Operation What it intends to the CPU ADD Add (enlist A + enlist B) and store entirety in enlist B SUB Subtract (enlist A - enlist B) and store contrast in enlist B MUL Multiply (enlist A * enlist B) and store item in enlist B DIV Divide for remainder (enlist An/enlist B) and store remainder in enlist B MOD Divide for leftover portion (enlist An/enlist B) and store leftover portion in enlist B
Slide 14Steps to compose Assembly Programs Create C++ Program (just the announcements between the { and } sections are required) Translate each C++ articulation to the comparable gathering statement(s) Number the low level computing construct program beginning from 0 Replace memory names by memory address quantities of purge memory cell Resolve bounced (supplant with number of memory cell hopping to)
Slide 15C++ to Assembly Language Statement Assembly proportional #include none void main() none const value in memory cell int, twofold, char address of memory cell cin INP cout PNT assignment (=) LDA Val1 val3 = val1 + val2 LDB Val2 ADD STR Val3 } STP
Slide 16Sample Program #1 Program #1. Compose a low level computing construct program that will get a number as contribution from the client, and yield its square to the client.
Slide 17Sample Program #1 Step 1: Write a calculation to depict the means expected to take care of our issue. Calculation: 1. Input a number and store it in memory. 2. Register the square by duplicating the number circumstances itself. 3. Yield the outcomes.
Slide 18Sample Program #1 Step 2: Write the C++ code { int Number , Square; cout << "Enter a number: "; cin >> Number; Square = Number * Number ; cout << Square; }
Slide 19{ cout << "Enter a number: "; cin >> Number; square = number * number; cout << Square; } INP number LDA number LDB number MUL STR square PNT square STP Sample Program #1 Step 3: Translate C++ code to get together
Slide 20Sample Program #1 Step 4: Number get together code lines beginning from 0 INP number 1 LDA number 2 LDB number 3 MUL 4 STR square 5 PNT square 6 STP
Slide 21Sample Program #1 Step 5: Replace memory names with purge memory areas after STP 0 INP number 7 1 LDA number 7 2 LDB number 7 3 MUL 4 STR square 8 5 PNT square 8 6 STP
Slide 22Sample Program #1 Step 6: Final Assembly code INP 7 LDA 7 LDB 7 MUL STR 8 PNT 8 STP
Slide 23Running the Code on the Model Assembler Type the code on the past slide into a record (utilize Notepad). Spare the document as sample1.txt in an indistinguishable catalog from the assembler.exe record Double snap assembler.exe Press ENTER Type the filename sample1.txt Press "r" to run
Slide 24Before running the code, the screen will resemble this: Your Assembly Code
Slide 25After running the code, the screen will resemble this: Results of Program Run
Slide 26C++ Decisions to Assembly Language C++ Statement if ( Num < 10 ) cout << Num; Assembly proportional LDA Num LDB Ten CMP [test condition] JLT Then piece address JMP address of articulation after Then square PNT Num [ Then block]
Slide 27C++ Decisions to Assembly Language Pascal Statement if ( Num < 10 ) cout << Num; else cout << "0"; Assembly comparable LDA Num LDB Ten CMP [Test condition] JLT Then piece address PNT Zero [Else block] JMP Address of explanation after Then square PNT Num [Then block]
Slide 28Sample Program #2 Program #2. Compose a get together program that will get a number from the client, and figure out whether the number is equally detachable by 5. Yield zero (false) if the number is NOT equitably separable by 5 or one (genuine) if the number IS equally distinguishable .
Slide 29Sample Program #2 Step 1: Write the calculation to depict the means expected to tackle our issue. 1. Perused in a number and store it in memory. 2. Figure out whether input number is uniformly separable by 5. 2.1 Divide input number by 5 to get the rest of. 2.2 Compare leftover portion to 0. In the event that leftover portion meets 0, the number is uniformly separable. In the event that the rest of not equivalent 0, the number NOT uniformly detachable. 3. Yield the outcomes 3.1 If equally distinguishable, yield 1. 3.2 If NOT equitably distinguishable, yield 0.
Slide 30Sample Program #2 Step 2: Write the C++ code { const int Zero = 0; const int One = 1; const int Five = 5; int number, rem; cout << "Enter number: "; cin >> number; rem = number % Five; if (rem = Zero) cout << One; else cout << Zero; }
Slide 31Sample Program #2 Step 3: Translate C++ code to Assembly cout << "Enter number: "; cin >> number; INP number LDA number rem = number % Five ; LDB Five MOD STR rem
Slide 32Sample Program #2 Step 3: proceeded if (rem = Zero) LDA Zero cout << One; LDB rem else CMP cout << Zero; JEQ then piece address PNT Zero else square JMP address after then square PNT One then piece } STP
Slide 33Sample Program #2 Step 4: Number gathering code lines starting from 0 INP number 1 LDA number 2 LDB Five 3 MOD 4 STR rem 5 LDA Zero condition 6 LDB rem 7 CMP 8 JEQ then piece address 9 PNT Zero else piece 10 JMP address after then square 11 PNT One then piece 12 STP
Slide 34Sample Program #2 Step 5: Replace names by cell numbers after STP 0 INP number 16 1 LDA number 16 2 LDB Five 13 3 MOD 4 STR rem 17 5 LDA Zero 14 6 LDB rem 17 7 CMP 8
SPONSORS
SPONSORS
SPONSORS