{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

08-MIPS-arithmetic

08-MIPS-arithmetic - MIPS arithmetic Today well review all...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
February 17, 2003 ©2001-2003 Howard Huang 1 MIPS arithmetic Today we’ll review all the important ideas of arithmetic from CS231. — Unsigned and signed number representations. — Addition and subtraction with two’s complement numbers. — Overflow detection. These issues are important in understanding MIPS arithmetic instructions. Finally, we review the construction of an ALU that will appear in our CPU designs in the next few weeks.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
February 17, 2003 MIPS arithmetic 2 Unsigned numbers We can store unsigned numbers as their binary equivalents. Bit position i has a decimal weight 2 i , so the decimal value v of an n -bit unsigned binary number a n –1 a n –2 ...a 1 a 0 can be calculated as below. This is just the sum of each digit times the weight of its position. 1 0 1 1 0 1 2 = (2 5 •1) + (2 4 •0) + (2 3 •1) + (2 2 •1) + (2 1 •0) + (2 0 •1) = 45 10 The smallest and largest possible numbers are 0 and 2 n –1. In MIPS, the largest unsigned number is 2 32 –1, or about 4.3 billion. = = 1 0 2 n i i i a v
Background image of page 2
February 17, 2003 MIPS arithmetic 3 Hexadecimal notation Hexadecimal is frequently used as a shorthand for binary numbers, because one hex digit corresponds to four bits. Converting between binary and hex is easy with a table. B E E F 16 = 1011 1110 1110 1111 2 In SPIM and many high-level programming languages, the prefix 0x denotes a hexadecimal constant, as in 0xBEEF . F 1111 E 1110 D 1101 C 1100 B 1011 A 1010 9 1001 8 1000 7 0111 6 0110 5 0101 4 0100 3 0011 2 0010 1 0001 0 0000 Hex Binary M o o .
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
February 17, 2003 MIPS arithmetic 4 Working with unsigned numbers Addition can be done just like in decimal. Multiplication and integer division by powers of 2 can be done using left and right “logical” shifts. 1 0 1 1 0 1 × 10 = 1 0 1 1 0 1 0 45 × 2 = 90 1 0 1 1 0 1 / 10 = 0 1 0 1 1 0 45 / 2 = 22 68 0 0 1 0 0 0 1 23 + 1 1 1 0 1 0 + 45 1 0 1 1 0 1 1 1 1 1 1
Background image of page 4
February 17, 2003 MIPS arithmetic 5 Logical shifts in MIPS MIPS has sll (shift left logical) and srl (shift right logical) instructions. — A constant specifies the number of bits to shift, from 0 to 31. — 0s are shifted into the right or left sides, respectively. For example, assume that $t0 contains 0xFEEDBEEF. sll $t1, $t0, 4 # $t1 contains 0xEEDBEEF 0 srl $t2, $t0, 12 # $t2 contains 0x 000 FEEDB Shifts are actually R-type instructions, not I-type! The constant is stored in the 5-bit “shamt” field that we hadn’t seen up until now. 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits func shamt rd rt rs op
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
February 17, 2003 MIPS arithmetic 6 Unsigned overflow One recurring issue in computer arithmetic is dealing with finite amounts of storage, such as 32-bit MIPS registers. Overflow occurs when the result of an operation is too large to be stored. There are many examples of unsigned n -bit overflows. — When there is a carry out of position n –1 in an addition. — When a n –1 is 1 in a multiplication by two. The 6-bit addition and multiplication operations on page 4 both result in overflow, since the correct answers require 7 bits.
Background image of page 6
February 17, 2003 MIPS arithmetic 7 Signed two’s-complement numbers Signed numbers are represented in two’s complement format.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}