Showing posts with label Machine Language. Show all posts
Showing posts with label Machine Language. Show all posts

Saturday, October 29

CHAPTER 4: MIPS (Million Instructions Per Second)

Well hello! *do i need to introduce myself??

       For this chapter, I will be the one who will explain to you what is MIPS. So, what you will learn here is:

      1. MIPS Architecture
      2. Register       3. Comment (#)      4. Assembly Instruction     5. Memory Operand


4.1 MIPS Architecture
          
    - a unit of computing speed equivalent to a million instructions per second.
    - an early RISC processor. RISC processors typically support fewer and much simpler instructions.

4.2 Register

    - limited number of special location built directly into the hardware
    - needd to perform the operation (cannot perform without it)
    - very fast since registers are directly in hardware
    - only 32 registers in MIPS
  • why? smaller the register, faster the performance
    - 1 register is 32 bits wide (32 bits = a word)
    - register preceded by $ in assembly language instruction
    - two formats for addressing:
  • using register number e.g. $0 through $31
  • using equivalent names e.g. $t1, $sp

    - special registers Lo and Hi used to store result of multiplication and division
  • not directly addressable: contents accessed with special instruction mfhi ("move from Hi") and mflo ("move from Lo")   
    - stack grows from high memory to low memory

4.3 Comment

      In programming language, we create comment by putting '//' at the front. Hence,in assembly language (coding in MIPS), we use put '#' (hashtag) before the words.

#comment

    - hash (#) is used for MIPS comments
  • anything from hash mark to the end of line is a comment
  • will be ignored in the coding

4.4 Assembly Instructions

    - in assembly language, instruction is a statement
    - each instruction is executed exactly one with a simple command
    

     Syntax of instructions:

     The arrangement of coding ::       1(ON)  2(Ds),3(S1),4(S2)

     1(ON) ---> operation name (ADD, SUB, etc)
     2(S0)  ---> operand for getting result or we called it ('destination')
     3(S1)  ---> 1st operand for operation called ('source1')
     4(S2)  ---> 1st operand for operation called ('source2')

     example :   add  $s0,$s1,$s2 
    
     - Syntax is rigid
  • 1 operator (add,sub, etc), 3 operands >> to keep hardware simple and fast

     :: Addition in assembly
         Example:               add  $s0,$s1,$s2  (in MIPS)
         is equal to:            a = b + c (in C)
   
     :: Subtraction in assembly
         Example:               sub  $s3,$s4,$s5  (in MIPS)
         is equal to:            d = e - f (in C)

4.5 Memory Operand
    
     - Main memory used for omposite data
     - To apply arithmetic operations
  • load values from memory into registers
  • store result from register to emory
     - memory is byte addressed
  • each address identifies an 8-bit byte
     - words are aligned in memory
  • address must be a multiple of 4

That's all from me. Hope you enjoys reading mine! Ppyong~


                

[EXTRA] CHAPTER 6: LANGUAGE OF THE COMPUTERS - Instruction Set Architecture (ISA)

Based on what I have introduced in the previous post, this time it will be about instruction set. If all I talked about was briefly the languages that computers use, now I will share about how it is being laid out in programs.


The high-level language is used to write out the Instruction Set Architecture (ISA). But first,

WHAT IS AN INSTRUCTION SET?

Instruction set is basically a set of commands that is to be carried out by the Central Processing Unit (CPU) of the computer in terms of machine language.

Simple instructions are made up of bit strings. Inside every instructions there are several important specifications that needs to be encoded.

1. Opcode

The first 6-bit of an instruction set is the opcode (“operation code”). It tells us what operation the CPU must carry out. Mnemonic language is used rather than hexadecimal code for simplicity and readability. 

2. Parameters

The rest of the instruction set contains parameters for the operation to work on. It can have registers, values and etc.


Now, ISA is the main interface between programming language and software with the main hardware component inside a computer. ISAs have unique assembly language that specifies how the program will run in a computer. 


WHERE INSTRUCTIONS ARE STORED?


Since instructions are sets of bit strings, there are mostly many instructions for every program and this requires some space in the memory. Inside the memory, the instructions are lined up in a consecutive manner with an address for each line of instruction. 

The relationship between CPU and Memory

Besides memory, a register also holds data temporarily. Registers can retrieve data whenever it is needed like how a memory works, though only a small volume can be stored. 

Example of instruction set:

MIPS Instruction Set

It uses 32-bit instructions which has R-Type Instructions, I-Type Instructions and J-Type Instructions. The opcode identifies the instruction which allow us to identify the instruction type.

x86 Instruction Set

It is one of the series of computer microprocessor developed by Intel for Intel 8086 CPU. It provides backward compatibility for older piece of hardware or software without the need to modify. Therefore x86 is the most prevalent ISA for desktop use. 



Glossary:

Mnemonic language: In assembly language, mnemonic is used to abbreviate various operations.
Parameters: Characteristics to customize a program.
Address: A unique number given to specify a particular set of instruction in memory.
Registers: Very small volume of memory located in the CPU itself.
Bit string: A sequence of bits that is represented by binary data. 


References:

Source 1
Source 2
Source 3

Picture credits:

https://www.eeweb.com/electronics-quiz/instruction-set-architecture
http://blog.biicode.com/bitscan-cpp-library-bit-strings/
http://math.hws.edu/javanotes/c1/s1.html


Ok so hope that summarizes what ISA is all about. Feel free to check out other topics for this syllabus! Your comments are highly welcome.

Til' next time, thanks for reading!

Friday, October 28

CHAPTER 6: LANGUAGE OF THE COMPUTERS - INTRO

In this blog post, we will look into the language that is use in computers. Roughly, computers have 2 major types of programming languages - low-level and high-level.

The Central Processing Unit (CPU) of a computer reads a computer programming language known as the machine code or machine language. Machine language are known as low-level language. The term "low" is represented because they are very close to how different hardware of the computer communicates with each other. It does not need any conversion or translation to execute instructions set.

Picture source: https://www.learnnpractice.com/generation-programming-languages.html
Machine language is a type of computer programming language that consists of binary and hexadecimal instructions which can be executed directly by the CPU. It is also the only language computer hardware understands. However, the binary notation are hard for humans to understand.

Even though low-level languages do not require any compiler to translate the instructions, some do need a simple processor called "assembler" to convert it to machine code and that is known as Assembly Language. Assembly language makes machine language more readable to humans. Instead of using long binary notation, assembly language uses a set of symbols and letters. Low-level language are categorized into first-generation and second-generation programming language. Assembly language is the second-generation as it no longer use 1s and 0s to write instructions.

Picture source: http://www.slideserve.com/karlyn/machine-assembly-language

Now for high-level language. High-level language are much more understandable to humans as it uses English and mathematical symbols in its instructions. Programming language is often referred to high-level language as it is mostly used by programmers nowadays such as C++, Java, Fortran and Python.

Being a low-level language, both machine code and assembly language are hardware specific and not portable. Meaning, the program can only be run on one specific computer and needs to be modified to run in other computers. 

Where as high-level language, they are portable and hence, are able to run on multiple computer system without modification. However, modification may be necessary due to different operating systems such as  for Windows which are typically different for Mac.

Unfortunately, high-level language is not directly understood by computers and needs to be translated into machine code. There are 2 ways to how it can be translated which are either compiled or interpreted. 

Compiling is a translation of the whole set of instruction into machine code as a compiled code (such as an .exe extension), prior to the insertion of input data during execution. Simply said, the result from compiling can be run as many times afterwards without having to compile them again. Example of compiled languages are C language and its derivatives - C++ and C#, COBOL and Fortran.

Interpretation on the other hand means the high-level program is interpreted line by line to produce an output data. Therefore for every execution, it is required to interpret the code again and again as there is no compiled code to use. Example of interpreted languages are Java, Perl, Python and Ruby. 

Alright, that's all for the introduction! Hope all the terms are well-written out.

Do comment if you have any doubts as we are all still learning as well! Til' the next post, keep computing! ;)

References:

Source 1
Source 2
Source 3