0% found this document useful (0 votes)
48 views

Computer Organization and Design PPT02

This document discusses the different levels of computer language from machine language understood by hardware to assembly language and high-level languages. It covers computer operations using operands in registers and memory. Instruction representation in MIPS assembly language is explained, including register usage and instruction formats. Logical and arithmetic operations are demonstrated along with conditional and unconditional jumps to enable decision making and loops in programs.

Uploaded by

ELSA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Computer Organization and Design PPT02

This document discusses the different levels of computer language from machine language understood by hardware to assembly language and high-level languages. It covers computer operations using operands in registers and memory. Instruction representation in MIPS assembly language is explained, including register usage and instruction formats. Logical and arithmetic operations are demonstrated along with conditional and unconditional jumps to enable decision making and loops in programs.

Uploaded by

ELSA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Instructions: Language of the

Computer
Xin Zeng, Associate Professor Dept.
of Information and Communication
Tongji University

Email: [email protected]
2.1 Computer Hierarchy Levels

 Language understood by
the computer’s hardware:
machine language(0101..)
 Usually discussed in terms
of assembly language

2
Some concepts

 Instruction set: collection of instructions that a processor can


execute
 A compiler translates a high level language, which is architecture
independent, into assembly language, which is architecture
dependent.
 An assembler translates assembly language programs into
executable binary codes.
.

3
MIPS assembly language

 MIPS is a reduced instruction set computer (RISC)


instruction set architecture (ISA) developed by MIPS
Technologies
 The early MIPS architectures were 32-bit, and later
versions were 64-bit
 Used areas: embedded system, supercomputer

Portable Game Device


with Two MIPS Chips

4
2.2 Operations of the computer
hardware

5
6
7
8
9
2.3 Operands of the computer
hardware
 Operands must be from a limited number
of Registers;
 Register: a special location built directly
in hardware, actually inside of the CPU.
 With a size of 32 bits = length of a word
 Byte = 8 bits

 MIPS has 32 registers

10
11
2.3 Operands of the computer
hardware
 Memory operands
 Only a small amount of data is kept in
registers
 Large data structures (like array) are kept in
the memory
 Data transfer function: A command that
moves data between memory and
register

12
2.3 Operands of the computer
hardware
 To access a word in memory, the
instruction must supply the memory
address
 Address: a value used to denote the
location of a specific data elements in a
memory array.
Load a word

14
 8 is a offset
 $s3 is a base register

15
 Alignment restriction: in MIPS, words
must start at addresses that are
multiples of 4.

16
Big-Endian and Little-Endian Formats
 In a byte-addressable machine, two choices for the order in which
the bytes are stored in memory: most significant byte at lowest
address, referred to as big-endian, or least significant byte stored at
lowest address, referred to as little-endian

17
 The "most significant" byte is
the one for the largest powers
of two: 231, ..., 224. The "least
significant" byte is the one for
the smallest powers of two:
27, ..., 20.
 32-bit pattern 0x12345678 is
at address 0x00400000. The
most significant byte is 0x12;
the least significant is 0x78.

18
Store a word

19
20
Constant or Immediate operands

 Add instruction with only one source


operand is called add immediate or addi.

21
Constant or Immediate operands

22
2.4 Representing instruction in
the computer
 Decimal number: base 10 number
 Binary number: base 2 number
 Hexadecimal number: base 16 number

23
24
Signed and Unsigned
Numbers
Unsigned numbers

25
Signed and Unsigned
Numbers
Signed numbers?
where to put the sign?
example:
0001 = 1ten ?
1001 = -1ten ?

26
Signed and Unsigned
Numbers
Let's answer another question:

How to use an adder to subtract ?


Ignore overflow.

27
Signed and Unsigned
Numbers
Signed numbers:

28
Signed and Unsigned
Numbers

29
Signed and Unsigned
Numbers

30
Signed and Unsigned
Numbers

31
Signed and Unsigned
Numbers

32
2.4 Representing instruction in
the computer

In MIPS assembly language


 Register $s0 - $s7 = Register 16 – 23
 Register $t0 - $t7 = Register 8 – 15

33
 Field: each of these segment
 0 (first segment)and 32 (last segment) (two
fields in combination) tell the computer
perform addition
 17 = $s1, 18 = $s2, 8 = $t0
 The fifth field is unused
34
 MIPS instruction is 32 bit long
 Equal to the length of word

35
R-type or R-format

What is the range for memory address


offset when loading words ? assuming
only 5 bits available.
36
 R-type = register type
 I-type (immediate) or I-format: used for
data transfer

 what is the range now? note there is a


sign.

How to differentiate R or I format?

37
38
Ref: https://blog.csdn.net/ben_chong/article/details/51794093
39
 In binary:

40
2.5 Logic operations

 sll: shift left logical, srl: shift right logical;


 Shift: move all the bits in a word to left or right, filling
the emptied bits with 0s.
 left shift by 4: 1000 1001 => 1001 0000
 Shifting left by i bits gives the same result as
multiplying by 2^i
41
 the original value was in register $s0 and the result
should go in register $t2, instruction:

 Machine language version

 REMEMBER:
Shamt = 4: stand for the shift
amount
 0 in both op and funct fileds
 rd = $t2
 rt = $s0
 rs = 0 is unused
42
 AND: bit-by-bit operation that leaves 1 in the
result if both bits of the operands are 1.

43
or: bit-by-bit operation that leaves 1 in the
result if either operand is 1.
=

44
 NOT: a logic bit-by-bit operation with one
operand that inverts the bits, i.e., it replace
every 1 with 0, and every 0 with 1;
 NOR: A logic bit-by-bit operation with two
operands that calculates the NOT of the OR of
the two operands. ($t3 = 0)

45
Review

46
2.6 Instruction for making
decisions

 Go to statement label L1 if the value in register


1 equals the value in register 2;

 Go to statement label L1 if the value in register


1 does not equal the value in register 2;
 Two instructions are called conditional
branches

47
 flow chart:

48
49
Loops

50
51
52
More conditional operations

 Register $t0 is set to 1 if the value in $s3


is less than the value in $s4

 $t0 =1 if the value in $2 is less than 10

53
Unconditional jump instructions
 j
 Unconditionally jumps to the instruction at the
specified address
 j exit # jump to the statement labeled by exit
 jr
 Jumps to the address contained in the specified
register
 jr $ra # goto address $ra

54
55

You might also like