Documente Academic
Documente Profesional
Documente Cultură
2 2 2
3 2 4 2
5 2 6 2
1
24/07/17
7 2 8 2
9 2 10 2
11 2 12 2
2
24/07/17
13 2 14 2
15 2 16 2
• How to compute the 1’s complement of a number? +3 0011 -4 1011 -4 = 1’s complement of
+4 0100 -3 1100 0100 = 1011
– Complement every bit of the number (1à0 and 0à1).
– MSB will indicate the sign of the number (0: posiFve, 1: negaFve). +5 0101 -2 1101
+6 0110 -1 1110
+7 0111 -0 1111
17 2 18 2
3
24/07/17
19 2 20 2
21 2 22 2
c) Shik right by k posiFons with sign bit padding divides the number by 2k.
• Some other features of 2’s complement representaFon
00010110 = +22 :: Shik right by 2 :: 00000101 = +5
a) Weighted number representaFon, with the MSB having weight -2n-1.
-2n-1 2n-2 21 20 11100100 = -28 :: Shik right by 2 :: 11111001 = -7
bn-1 bn-2 b1 b0
d) The sign bit can be copied as many Fmes as required in the beginning to
D = -bn-12n-1 + bn-22n-2 + … + b222 + b121 + b020 extend the size of the number (called sign extension).
b) Shik lek by k posiFons with zero padding mulFplies the number by 2k. X = 00101111 (8-bit number, value = +47) X = 10100011 (8-bit number, value = -93)
00010011 = +19 :: Shik lek by 2 :: 01001100 = +76 Sign extend to 32 bits: Sign extend to 32 bits:
00000000 00000000 00000000 00101111 11111111 11111111 11111111 10100011
11100011 = -29 :: Shik lek by 2 :: 10001100 = -116
23 2 24 2
4
24/07/17
END OF LECTURE 6
Lecture 1: EVOLUTION OF COMPUTER SYSTEM
Lecture Lecture 1: EVOLUTION
7: INSTRUCTION OF AND
FORMAT COMPUTER SYSTEMMODES
ADDRESSING
DR.DR.
KAMALIKA
KAMALIKA DATTA
DATTA
DR. KAMALIKA DATTA
DEPARTMENT OF COMPUTER
DEPARTMENT SCIENCE
OF COMPUTER SCIENCEAND
AND ENGINEERING, NIT
ENGINEERING, NIT MEGHALAYA
MEGHALAYA
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, NIT MEGHALAYA
25 2 2
InstrucWon Format
• An instrucFon consists of two parts:-
• Number of operands varies from instrucFon to instrucFon.
a) OperaFon Code or Opcode
• Specifies the operaFon to be performed by the instrucFon.
• Also for specifying an operand, various addressing modes are
• Various categories of instrucFons: data transfer, arithmeFc and logical, possible:
control, I/O and special machine control. – Immediate addressing
b) Operand(s) – Direct addressing
• Specifies the source(s) and desFnaFon of the operaFon. – Indirect addressing
• Source operand can be specified by an immediate data, by naming a – RelaFve addressing
register, or specifying the address of memory.
– Indexed addressing, and many more.
• DesFnaFon can be specified by a register or memory address.
27 2 28 2
29 2 30 2
5
24/07/17
31 26 25 21 20 16 15 0
LOAD R11,100(R2)
opcode dest source 16-bit immediate data :: R11 = Mem(R2+100)
LOAD 01011 00010 0000000001100100
31 26 25 21 20 16 15 11 10 0
opcode dest source source ALU funcFon ADD R2,R5,R8
:: R2 = R5 + R8
ALU op 00010 00101 01000 ADD
ADDRESSING MODES
31 2 32 2
33 2 34 2
Direct Addressing
• The instrucFon contains a field that holds the memory address of the opcode operand address
operand. Memory
opcode operand address
• Examples:
– ADD R1,20A6H // R1 = R1 + Mem[20A6] operand
• Single memory access is required to access the operand.
– No addiFonal calculaFons required to determine the operand address.
– Limited address space (as number of bits is limited, say, 16 bits).
35 2 36 2
6
24/07/17
Indirect Addressing
• The instrucFon contains a field that holds the memory address, which in opcode operand address
turn holds the memory address of the operand. Memory
• Two memory accesses are required to get the operand value.
• Slower but can access large address space. operand
– Not limited by the number of bits in operand address like direct addressing.
pointer
• Examples:
– ADD R1,(20A6H) // R1 = R1 + (Mem[20A6])
37 2 38 2
Register Addressing
• The operand is held in a register, and the instrucFon specifies the register opcode register no
number. Register Bank
– Very few number of bits needed, as the number of registers is limited.
– Faster execuFon, since no memory access is required for getng the operand.
• Modern load-store architectures support large number of registers.
• Examples: operand
– ADD R1,R2,R3 // R1 = R2 + R3
– MOV R2,R5 // R2 = R5
39 2 40 2
41 2 42 2
7
24/07/17
43 2 44 2
Stack Addressing
opcode index reg offset • Operand is implicitly on top of the stack.
• Used in zero-address machines earlier.
• Examples:
Register Bank Memory – ADD
– PUSH X
– POP X
ADDER operand
• Many processors have a special register called the stack pointer (SP) that
keeps track of the stack-top in memory.
– PUSH, POP, CALL, RET instrucFons automaFcally modify SP.
45 2 46 2
47 2 48 2
8
24/07/17
Broad ClassificaWon
• Computer architectures have evolved over the years.
– Features that were developed for mainframes and supercomputers in
the 1960s and 1970s have started to appear on a regular basis on later
generaFon microprocessors.
Lecture 1: EVOLUTION OF COMPUTER SYSTEM
Lecture
Lecture8:
1:CISC AND RISC
EVOLUTION ARCHITECTURE
OF COMPUTER SYSTEM • Two broad classificaFons of ISA:
a) Complex InstrucFon Set Computer (CISC)
DR.
DR.
DR.
KAMALIKA
KAMALIKA
KAMALIKA
DATTA
DATTA
DATTA
b) Reduced InstrucFon Set Computer (RISC)
DEPARTMENT
DEPARTMENT OF
OF COMPUTER
DEPARTMENTCOMPUTER SCIENCE
SCIENCE
OF COMPUTER AND
AND
SCIENCE ENGINEERING,
ENGINEERING,
AND NIT
ENGINEERING, NIT MEGHALAYA
MEGHALAYA
NIT MEGHALAYA
2 50 2
51 2 52 2
53 2 54 2
9
24/07/17
55 2 56 2
57 2 58 2
59 2 60 2
10
24/07/17
61 2 62 2
63 2 64 2
Some MIPS32 Assembly Language ConvenWons Register name Register number Usage
$zero R0 Constant zero
• The integer registers of MIPS32 can be accessed as R0..R31 or r0..r31 in an
assembly language program.
• Several assemblers and simulators are available in the public domain (like Used to represent the constant zero
QtSPIM) that follow some specific convenFons. value, wherever required in a program.
– These convenFons have become like a de facto standard when we write
assembly language programs for MIPS32.
– Basically some alternate names are used for the registers to indicate their
intended usage.
65 2 66 2
11
24/07/17
Register name Register number Usage Register name Register number Usage
$at R1 Reserved for assembler $v0 R2 Result of funcFon, or for expression evaluaFon
$v1 R3 Result of funcFon, or for expression evaluaFon
May be used as temporary register Example: Load Address instrucFon used to
during macro expansion by assembler. iniFalize pointers May be used for up to two funcFon
return values, and also as temporary
• Assembler provides an extension to
registers during expression evaluaFon.
the MIPS32 instrucFon set that are la !R5,addr!
converted to standard MIPS32 !
instrucFons.
lui !$at,Upper-16-bits-of-addr!
ori !R5,$at,Lower-16-bits-of-addr!
67 2 68 2
69 2 70 2
71 2 72 2
12
24/07/17
END OF LECTURE 8
These registers are supposed to be used by the OS kernel in a real
computer system.
It is highly recommended not to use these registers.
73 2 74 2
2 76 2
77 2 78 2
13
24/07/17
c) Accessing fields that are not word aligned. Data sizes that can be accessed through LOAD and STORE
• Examples: LWL, LWR, SWL, SWR
d) Atomic memory update for read-modify-write instrucFons Data Size Load Signed Load Unsigned Store
• Examples: LL, SC Byte YES YES YES
Half-word YES YES YES
Word YES Only for MIPS64 YES
Unaligned word YES YES
Linked word (atomic modify) YES YES
79 2 80 2
Type Mnemonic FuncWon Type Mnemonic FuncWon (b) ArithmeWc and Logic InstrucWons
LB Load Byte LWL Load Word Lek
• All arithmeFc and logic instrucFons operate on registers.
LBU Load Byte Unsigned LWR Load Word Right
Unaligned
LH Load Half-word SWL Store Word Lek
• Can be broadly classified into the following categories:
– ALU immediate
LHU Load Half-word Unsigned SWR Store Word Right
Aligned – ALU 3-operand
LW Load Word Atomic LL Load Linked Word
Update – ALU 2-operand
SB Store Byte SB Store CondiFonal – Shik
Word
SH Store Half-word – MulFply and Divide
SW Store Word
81 2 82 2
83 2 84 2
14
24/07/17
85 2 86 2
87 2 88 2
89 2 90 2
15
24/07/17
91 2 92 2
93 2 94 2
95 2 96 2
16
24/07/17
END OF LECTURE 9
Lecture 1: EVOLUTION OF COMPUTER SYSTEM
Lecture
Lecture 10:1:MIPS
EVOLUTION OF COMPUTER
PROGRAMMING SYSTEM
EXAMPLES
DR. KAMALIKA DATTA
DR. KAMALIKA DATTA
DR. KAMALIKA DATTA
DEPARTMENT
DEPARTMENTOF
OFCOMPUTER SCIENCEAND
COMPUTER SCIENCE ANDENGINEERING,
ENGINEERING,NITNIT MEGHALAYA
MEGHALAYA
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, NIT MEGHALAYA
97 2 2
99 2 100 2
101 2 102 2
17
24/07/17
103 2 104 2
Working with Immediate Values in Registers • Case 2: Large constants, that require 32 bits to represent.
– How to load a large constant in a register?
• Case 1: Small constants, which can be specified in 16 bits. – Requires two instrucFons.
– Occurs most frequently (about 90% of the Fme). • A “Load Upper Immediate” instrucFon, that loads a 16-bit number into
– Examples: the upper half of a register (lower bits filled with zeros).
A = A + 16; à addi $s1, $s1, 16 (A in $s1) • An “OR Immediate” instrucFon, to insert the lower 16-bits.
X = Y – 1025; à subi $s1, $s2, 1025 (X in $s1, Y in $s2) – Suppose we want to load 0xAAAA3333 into a register $s1.
A = 100; à addi $s1, $zero, 100 (A in $s1)
lui $s1, 0xAAAA 1010101010101010 0000000000000000
105 2 106 2
107 2 108 2
18
24/07/17
109 2 110 2
111 2 112 2
113 2 114 2
19
24/07/17
115 2 116 2
117 2 118 2
2 120 2
20
24/07/17
121 2 122 2
123 2 124 2
125 2 126 2
21
24/07/17
127 2 128 2
.data
value: .word 50, 30, 0
129 2 130 2
131 2 132 2
22
24/07/17
Example .data
li $v0, 4
la $a0, str2 li $v0, 1
Program 5 num: .word 1, 2, 3, 4, 5, 6 ,7, 8, 9, 10
.text
syscall move $a0, $t1 .globl main
syscall main:
li $v0, 5
Calculate sum of 10 la $t0, num
syscall li $v0,10 li $t2, 0 # holds the sum
move $t1, $v0 syscall 32-bit numbers stored
li $t3, 0 # counter for loop
in consecuFve loop: lw $t1, 0($t0)
add $t1, $t0, $t1 memory locaFons. add $t2, $t2, $t1
# $t1= $t0 + $t1
addi $t3, $t3, 1
addi $t0, $t0, 4 # point to next
li $v0, 4
bne $t3, 10, loop
la $a0, str3
syscall
li $v0,10
syscall
133 2 134 2
135 2 136 2
li $v0,10
syscall
137 2 138 2
23
24/07/17
END OF LECTURE 11
139 2
24