Computer Organization and Assembly Language (COAL)
Edited by TheGuyLoveNY, Jen Moreau
- 1 Assembly Language Structure:
- 2 Register:
- 3 General Registers:
- 4 Instructions:
- 5 Stored program concept:
- 6 Assembly Language vs C Language:
- 7 Data Transfer Instructions:
- 8 Arrays:
- 9 MIPS Instruction Format:
- 10 MIPS Performance:
- 11 Average Cycles Per Instruction
- 12 This article is part of a series on Computer Organization and Assembly Language (COAL). Read the full series here:
- 13 Questions and Answers
- 14 Referencing this Article
- 15 Comments
Assembly Language Structure:
Assembly language has a structure that we follow whenever we write a code in Assembly language. An assembly language has following components in total:
- Machine code.
- Opcode or operational code.
- Memory address.
Mainly, all these comes in a section and The program must follow the structure. Assembly language structure is:
- Model small
Registers are small computer memory that is used to store information. Registers are very close to a processor and the amount or the size of the register is very limited. Hence, This register is used for higher priority operations. There are many types of registers, Following are the categorization of registers.
- Control Registers.
- General Registers.
- Segment Registers.
Here is a detailed classification diagram of registers:
- Ax: Ax is an accumulator register that is used by the processor to store result obtained by performing Arithmetic and logical operation. CPU use this memory to store the result and later retrieve this information for the further process. The accumulator is very important, Otherwise, the processor would have to store the result in the primary memory (RAM), which would take a lot of time which will eventually lead to inefficiency.
- Bx: Bx register is a base register. This register is used when addressing memory addresses. It is mainly used for the indexing of the addresses. Base register along with the offset can point to a memory address.
- Cx: Cx register is a counter register. The counter register stores the loop count in the process of iteration. This counter register also acts as a counter in string manipulation and other shift/rotate instructions.
- Dx: Dx register is a Data register. This register act as a temporary memory holder. Whenever there is a need to transfer data from one location to another, the information is stored in the data register. Data registers contain the whole information.
Instructions are a set of commands that tells the computer what is to be done. There are many types of instructions such as Assignment instruction which tells the computer to assign a particular value to a variable. We have conditional instructions which help computer make better decisions, For example: if ( user_Age > 18) then LetIn();
In the above pseudo code, the computer checks if the user's age is greater than 18, If so, then the computer let the user in. These types of conditional instructions help make program smarter. A collection of instructions makes a program do more than one thing.
Stored program concept:
The Idea of Stored program concept was proposed by Computer scientist, John Von Neumann. Back in the old days, Program's instruction used to be stored in one memory, while the program's Data used to be stored in other memory. The program would then execute with Instructions at one location and data in other location. This was a very bad Idea, but later Computer scientist, John Conn Neumann suggested that both, the program instruction and the programs data should be at one memory location. Later it was found that this was a much efficient method to store the information in the memory. Even today, Programs with instructions and data are stored in a single memory thus Stored program concept.
Assembly Language vs C Language:
The syntax of assembly language is different than C language. It is important to note here, That C is a middle-level language, whereas, Assembly language is a low-level language. Assembly language closely communicates with the processor on what to do. C, being middle-level language tells what to do but it is actually converted to assembly language before the execution takes place.
- Comments: Comments are ignored by the compiler. It is mainly used for better understanding of the code. A programmer comments each line of code explaining what this line of code does and why we are doing this way. So that when this programmer comes after a vacation to the same project, understands why did he create that code and what does that code do.
We use "//" for single line comment in C. For example : Int a = b + c; // This line adds variable b and variable c, storing the result in variable a.
In Assembly language, We use "#" as a comment: For example:
ADD a,b,c # Add variable b and c. Store the result in variable a.
Instructions in C:
- 1a = b + c;Advertisement
- 2f = a * c;
- 3g = (a%b) * 2;
Instructions in Assembly Language:
- 1ADD T0, a, b
- 2MUL f,a,c
- 3DIV c,e,j
As we have discussed earlier, Memory operand is a small register that the processor uses for small operations. The memory operand is mostly used in arrays and structures. The operand may be processor register and even constant. For example MOV DS, AX. Here the operands are DS and AX, Both of them are processor register in this case.
Data Transfer Instructions:
These instructions are used to manipulate data my moving information from memory location to other. Data transfer instructions are instruction sets that allow programmers to transfer data from one memory address to another. Following are some of the data transfer instructions:
- 1This instruction copies the data from memory to Register. This mainly is used when the information needed is critical and must be present in the register throughout the lifetime of the program.Load:
- 2This instruction performs the opposite action to the instruction Load. Store instruction mainly transfers the data stored in the register to the memory. This instruction is used when the user wants to enter some information but it is not very important at the moment, so for the time being the information is stored in the memory.Store:
- 3This instruction is followed by a register to be loaded or stored according to the situation, along with the constant and the register to hold the information into the register. So that the information can be accessed later from the register, whenever required.Format:
Often there are situations where a programmer wants to store multiple values for a program. In would be very tedious to have multiple variables with those same type of multiple information. That is where arrays come in, Arrays are used to store similar type of information for a given computer memory. In programming, it really becomes easy when we use an array to store multiple information.
C statements: g = h + a;
Here, we are adding the variable "h" with the 9th element of "a", and finally storing the result in the variable "g".
Assembly Language statements:
LWO $to, $S3 ADD $s1, $S2, $to
Here, Firstly we are loading the element of the array into a register to, "$' Represent register. In the second instruction, We are adding that element of the array stored in the temporary register to, with other variable S2 and finally storing the result in the third variable S3. Interestingly, C statements are simple, but behind the scene, the compiler actually converts it to this assembly language statement for the sake of optimization, which is, of course, difficult for the human to understand.
Constants are the values or variables that do not change. They are quite useful at times when we need to store an information that will never change. Sometimes they are used along with the instructions as an argument for certain operations.
ADDI $S3, $S3, 4
Here, the instruction ADDI means to add the numbers with a constant. In the example above, We are adding the constant 4 with the register S3 and storing the result in the register S3.
MIPS Instruction Format:
As we can see from the diagram, MIPS Instruction format is 32 bit long. This instruction format of 32 bit is segmented into 6 segments. Each segment is assigned 6/5 bits.
- 1This segment is assigned with 6-bits. Opcode segment is used to store operational code.Opcode:
- 2Register s and Register t are used as source register and are assigned 5-bits. If one register is full, the other one is used.Register s and Register t:
- 3This register is called as the Destination register. This register is assigned with 5-bit.Register d:
- 4This block is assigned 5-bit as well. This block is used in shift instruction and It signifies what amount of bits are to be transferred.Shift amount:
- 5This block indicates the operation in addition to the opcode block. This block is assigned with 6 bit.Function:
MIPS: MIPS is a computer measure for comparing the performance of the computer processor with almost same architecture. MIPS is abbreviated for Millions of Instruction per second, Which means if a processor, say X, has a performance of 1 MIPS then it means the processor X can execute 1 Million instructions per second. This is a better measure and It is quite different than frequency measured in Hz. MIPS are also dependent on the programming language. So, the efficient the programming language is, the greater the MIPS of a processor will be.
MIPS performance depends on the basis of the systems. There are also some other factors that MIPS dependence on. Following are the other factors MIPS performance depends on: Processing Time. Execution Time.
MIPS formula = Instruction Count X 10-6Execution Time per second
Execution Time = CPU CycleClock frequency
CPU CycleClock frequency= CPI X CI
Where, CPI is Cycles per Instruction. CI is Compiler Instruction.
Average Cycles Per Instruction
There are different kinds of Instruction in a program and Chances are that the cycles for each different instructions are variable. Instruction like ls, so which involve accessing memory requires more clock cycles, and hence are slower than other instruction. Other Instructions like Add, Subtract, Multiply are faster. In a nutshell, Each instruction takes different cycles for execution.
We look at the Instruction Frequency Fi= Number of instruction of type iProgram Instruction Count
Then CPI = Σ CPI I x F I Note �" Fi is program dependent! (will influence MIPS).
Example: Two 5 GHz computers with the same architecture use different compilers. They have: Instruction Class CPIi A 2 B 1 C 4
Solution: The compilers affect the Instruction count for each class code from,
Instruction Count Ci for each Clas (109)
A B C Compiler 1 5 1 2 Compiler 2 10 1 2
The CPU cycles= Σ CPI I x C I (how many instruction of class I are in the program) So CPU cycles for Machine 1 = (5x2+1x1+2x4) 109 = 19 x109 CPU cycles for Machine 2 = (10x2+1x1+2x4) 109 = 29 x 109
The Execution time for Machine 1 = #CPU cycles/clock frequency = (19 x 109 )/5 x109 = 3.8 sec The Execution time for Machine 2 = (29 x 109 )/5x109 = 5.8 sec So Machine 1 has better performance (it takes less time to execute the program).
MIPS as measure of performance= Instruction Count x10-6 Execution time
MIPS for Machine "1" =(5+1+2) 1093.8 x106 = 2,100 MIPS
MIPS for Machine "2 "= (10+1+2) 1095.8 x106 = 2,241 MIPS
Finally, We can conclude that: Machine 2 has higher MIPS! �" MIPS depends on the Instruction Count (which depends on the compiler) �" there will be different MIPS on a single machine.
This article is part of a series on Computer Organization and Assembly Language (COAL). Read the full series here:
1) Assembly Language Structure
Questions and Answers
I need to solve the following questions of computer architecture and organization?
Write a program to load the value 223 in $t0 register. Shift it left by 5, then shift it right by 7 and then shift it left by 2.. Show your program to Teacher: _____________ Run the program.. What is the Hex value of 223 load in $t0:___________. What is value of $t0 after it is shifted left by 5? ___________. Why? ___________________. What is value of $t0 after it is shifted right by 7? ___________. Why?__________________. What is value of $t0 after it is shifted left by 2? ___________. Why? ____________________. Is the final result different from 223: Why? __________________________________________. . . Write a program to load 220 in $s0. Mask $s0 using and operation to obtain least significant five bits of $s0 and store them in $s1. Find the sum of 8*$s1 and $s1/8 using shift operations. . What is the sum? _________. . 220.127.116.11 Exercise # 3. Recall that immediate field in addi can hold 16 bits. We learned how to load a 32-bit value in a register. Let us try that. . Remember the method is: 1. Load upper (most significant) 16 bits in a register. 2. Shift it left by 16 places. 3. Add lower (least significant) 16 bits.. . Using the above mentioned method, load the value 0x12345678 in $t0. You can load hex values using 0x notation, . e.g. addi $t0, $zero, 0x1234. I have some exercise questions. The article explains all the concepts of COAL, I'll be delighted if you can help me with this.
ScienceAid QnA. This section is not written yet. Want to join in? Click EDIT to write this answer.
Referencing this Article
If you need to reference this article in your work, you can copy-paste the following depending on your required format:
APA (American Psychological Association)
Computer Organization and Assembly Language (COAL). (2018). In ScienceAid. Retrieved Apr 25, 2019, from https://scienceaid.net/Assembly_Language_Structure
MLA (Modern Language Association) "Computer Organization and Assembly Language (COAL)." ScienceAid, scienceaid.net/Assembly_Language_Structure Accessed 25 Apr 2019.
Chicago / Turabian ScienceAid.net. "Computer Organization and Assembly Language (COAL)." Accessed Apr 25, 2019. https://scienceaid.net/Assembly_Language_Structure.
Categories : Computer Organization and Assembly Language
Recent edits by: TheGuyLoveNY