Tuesday, 16 October 2012

Language of Computer - by Yau Kai Shi



Representing Instructions In The Computer
Introduction

v  Instructions are encoded in binary-Called machine code.

v  Instructions are kept in the computer as a series of high and low electronic signals and may be represented as numbers.

v  MIPS instructions
·       Encoded as 32-bit instruction words.
·       Small number of formats encoding operation code (opcode)and register numbers.
·       Regularity.

Ø  Register numbers
·       $t0 – $t7 are register numbers  8 – 15
·       $t8 – $t9 are register numbers  24 – 25
·       $s0 – $s7 are register numbers  16 – 23

MIPS Registers and Usage Convention
Name
Register number
Usage
$ zero
0
The constant value 0
$at
1
Reserved for assembler
$v0 - $v1
2 - 3
Value for results and expression evaluation
$a0 - $a3
4 - 7
Arguments
$t0 - $t7
8 - 15
Temporaries
$s0 - $s7
16 - 23
Saved
$t8 - $t9
24 - 25
More temporaries
$k0 - $k1
26 - 27
Reserved for OS kernel
$gp
28
Global pointer
$sp
29
Stack pointer
$fp
30
Frame pointer
$ra
31
Return address


MIPS Instruction Format
·       A form of representation of an instruction composed of fields of binary numbers.

·       One instruction is 32 bits

Ø Each of segments of an instruction is called a “fields”.
Ø Each field tells computer something about instruction.

·       MIPS is based on simplicity define 3 basic types of instruction formats:

Ø R-format : for register.
Ø I-format : for immediate, and lw and sw.
Ø J-format :for jump.

Instruction Format (machine code)
·       Simple instruction all 32 bits wide.
·       Very structured, no unnecessary baggage.
·       3 basic types of instruction formats:



MIPS R-format Instructions







·      Instruction fields
Ø op: operation code (opcode)
Ø rs (source register ) - first number
ü   Generally used to specify register containing first operand.

Ø rt (Target Register) - second number
ü   Generally used to specify register containing second operand.

Ø rd(Destination Register)
ü   Generally used to specift register which will receive result of computation.

Ø shamt (Shift amount)

Ø funct (function)
ü Selects the variant of the operation in the op field called function code.

MIPS I – format Instruction




·       Immediate arithmetic and load/store instructions

Ø opcode : Uniquely specifies an I-format instruction.
Ø rs : Specifies the only register operand and is the base register.
Ø rt : Specifies register which will receive result of computation .
Ø immediate : sign-extended to 32bits,and treated as a signed integer.

·       16 bits can be used to represent immediate up to 216 different values.

MIPS J-format Instructions

o   For general jumps (j and jal),we may jump to anywhere in memory.
Ø Encode full address in instruction.

·       Key concepts:
Ø Keep opcode field identical to R-format and I-format for consistency.
Ø Combine other fields to make room for target address.

·       Optimization :
Ø Jumps only jump to word aligned addresses.
·       Last two bits are always 00 (in binary)
·       Specify 28 bits of the 32-bit address.

·       (Pseudo) Direct jump addressing
Ø PC = PC [31…28] || target address (26 bits) || 00
Ø Note: means concatenation
Ø 4 bits|| 26 bits || 2 bits = 32-bit address

MIPS Instruction Encoding

Ø In the table above, “reg” means a register number between 0 and 31, “address” means a 16-bit address, and “n.a.”(not applicable) means this field does not appear in this format.


Ø Note that add and sub instructions have the same value in the op field; the hardware uses the funct field to decide the variant of the operation: add (32) or subtract (34).

Hexadecimal
Ø Reading binary number are tedious.
Ø Hexadecimal representation is popular.
Ø Base 16 is power of two and hence it is easy to replace each group of 4 binary digits.


0
0000
4
0100
8
1000
C
1100
1
0001
5
0101
9
1001
D
1101
2
0010
6
0110
A
1010
E
1110
3
0011
7
0111
B
1011
F
1111

·       Base 16
ü Compact representation of bit strings .
ü 4 bits per hex digit.

·       Example :FBDB A385
                                                                 
1111 1011 1101 1011 1010 0011 1000 0101

MIPS Machine Language



Stored Program Computers
·       Instructions represented in binary, just like data.
·       Instruction and data stored in memory.
·       Binary compatibility allows compiled programs to work on different computers.
Ø Standardized ISAs

Intstruction for Making Decisions
Introduction

·        Decision making instructions
·       Alter the control flow.
·       i.e. :change the “next” instruction to be executed.
(otherwise, it is address of current inst. 4)





·       Destination address can be specified in the same way as other operands (combination of registers, immediate constants, and memory locations), depending on what is supported in the ISA.

Loop
·       Decisions are important both for choosing between two alternatives – found in if statements – and for iterating a computation – found in loops. 

Basic Blocks


·       A sequence of instructions
·       Without branches,(except at end) .
·       Without branch targets or branch labels (except at beginning).

·       One of the first early phase of compilation is breaking the program into basic block.(for optimization)

·       An advanced processor can accelerate execution of basic blocks.


References









Written by.
Yau Kai Shi
B031210077



No comments:

Post a Comment