# Org2 - Machine Language Chapter 2 Basic Operations add a,...

This preview shows pages 1–19. Sign up to view the full content.

Machine Language Chapter 2

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

View Full Document
Basic Operations add a, b, c a = b + c a, b, and c are registers This family of instructions operates on registers only On RISC architectures we can have nothing but registers as operands
Prime Directive Simplicity Until late 80s computer architects tried to outdo each other in complexity This made computers slow The new and nimble technology was named RISC

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

View Full Document
More Complex Example f = ( g + h ) - ( i + j ) add t0, g, h add t1, i, j sub f, t0, t1
Operands In RISC, all instructions are either operating on registers only are load-store instructions The reason is that we like simplicity

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

View Full Document
What is a register On-chip place to save a single word A word for this MIPS is 32 bits One bit words fit a number either 0 or 1 Two bits: 0. ..3 Three bits: 0. ..7 32 bits: 0. .. four billion
Why 32 registers More registers means slower execution (in general) That was a fair amount when MIPS came out Among the advantages of MIPS back then was the large number of registers.

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

View Full Document
Example Using Registers f = ( g + h ) - ( i + j ) add \$t0, \$s1, \$s2 add \$t1, \$s3, \$s4 sub \$s0, \$t0, \$t1
Registers \$zero: zero constant \$at, \$k0, \$k1: reserved \$v0, \$v1: function and expression results \$a0-\$a3: Arguments \$s0-\$s7: Saved temps \$t0-\$t10: Temps \$sp, \$gp, \$fp, \$ra: {stack, global, frame} pointers, return address.

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

View Full Document
Memory Operands Memory is a (long) series of bytes We specify where on memory with an address An address is a positive integer We do only two things with memory: Load stuff from memory Save stuff to memory
Memory access example g = h + A[8]; lw \$t0, 8(\$s3) add \$s1, \$s2, \$t0 lw is load word (h for half word and b for byte) Array base address is in \$s3 Do you notice something peculiar?

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

View Full Document
Memory access example A[12] = h + A[8]; lw \$t0, 32(\$s3) add \$t0, \$s2, \$t0 sw \$t0, 48(\$s3)
Constant or Immediate Operands a = a +4; addi \$s3, \$s3, 4 Works perfectly for small operands Since the constant zero appears too often we have it built in. Subtraction is equally simple addi \$s3, \$s3, -4

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

View Full Document
Binary numbers All computers understand is 0, 1 0000: 0 0001: 1 0010: 2 0011: 3 0100: 4 1110: 14 1111: 15
Binary Numbers 1011 2 = 1*8 + 0 * 4 + 1 * 2 + 1 * 1 = 11 10 How about negatives? How much more hardware and gate delays do we need? Simple solution: sign and magnitude

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

View Full Document
Two's Complement Arrange numbers on a circle Call half of them positive (or zero) Other half negative. 000, 001, 010, 011, 100, 101, 110, 111, 000, . .. 0, 1, 2, 3, -4, -3, -2, -1, 0, . ..