An assembly language is a low-level programming language designed for a specific type of processor. It may be produced by compiling source code from a high-level programming language (such as C/C++) but can also be written from scratch. Assembly code can be converted to machine code using an assembler
Since most compilers convert source code directly to machine code, software developers often create programs without using assembly language. However, in some cases, assembly code can be used to fine-tune a program. For example, a programmer may write a specific process in assembly language to make sure it functions as efficiently as possible.
While assembly languages differ between processor architectures, they often include similar instructions and operators. Below are some examples of instructions supported by x86 processors.
MOV - move data from one location to another
ADD - add two values
SUB - subtract a value from another value
PUSH - push data onto a stack
POP - pop data from a stack
JMP - jump to another location
INT - interrupt a process
The following assembly language can be used to add the numbers 3 and 4:
mov eax, 3 - loads 3 into the register "eax"
mov ebx, 4 - loads 4 into the register "ebx"
add eax, ebx, ecx - adds "eax" and "ebx" and stores the result (7) in "ecx"
MISPS (Microprocessor without Interlocked Pipelined Stages) is a reduced instruction set computer (RISC) instruction set architecture (ISA) developed by MIPS Computer Systems, now MIPS Technologies, based in the United States. There are multiple versions of MIPS we are just doing a basic intro into the architecture.
Instructions are divided into three types: R, I and J. Every instruction starts with a 6-bit opcode. In addition to the opcode, R-type instructions specify three registers, a shift amount field, and a function field; I-type instructions specify two registers and a 16-bit immediate value; J-type instructions follow the opcode with a 26-bit jump target.
The following are the three formats used for the core instruction set:
sll $t5, $t4, 2
opcode rs rt rd shamt funct
000000 01001 01010 01000 00000 100000
There are a lot of other examples you can do
A detailed reading of many MIPS instructions is given in the document below. It's basically, all the instructions that the processor can do.
C code
i=0;
while ( i<10 ) {
// loop body
i++;
}
MIPS Assembly Code would look like
li $t0, 10 # t0 is a constant value of 10
li $t1, 0 # t1 is our counter i
loop:
beq $t1, $t0, end # if t1 == 10 the loop ends
//loop body (just a marker so you can compare to the code above)
addi $t1, 1 # add 1 to t1
j loop # jump back to loop instruction above (it's above beq)
end:
If you are interested in more C to MIPS conversions, you can check out the document below