Lecture 5 Digital Computing Systems

Preview:

DESCRIPTION

Lecture 5 Digital Computing Systems

Citation preview

1

Digital Computer SystemsEE 344

Lecture 5: Assembly Language, an Overview

Where are we?• Very close to the hardware…• Link between HLL, ISA, and

microarchitecture• One HLL instruction may be implemented with

several assembly language instructions• Symbolic presentation of the instruction set

architecture (ISA) level• Programs written with different HLL can be

transformed to the same assembly language

2

Not Easy!• Limited storage resources (memory and

registers)• No notion of types, it is the programmer

responsibility to use the correct instructions• Only “go to” control instructions• Amount of work done by an instruction is

smaller than a HLL instructions• Much longer to debug and much harder to

maintain• Difficult to think at that low level• Not portable

Why bother, then?• Performance (speed and cost)

– Much smaller than HLL– Much faster than HLL

• Complete access to the hardware features – Device drivers– Interrupts– Some real-time embedded systems– etc...

3

Assembly-Language

The view/model(registers and memory)

Data Types

Instruction types

The assembly programmersees memory and registers

the key difference between mediocre and excellent programmers is whether or not they know assembly language.

The Memory

• Large number of locations• Each location has a fixed size width

(usually the width is 1 byte)• Collection of all locations is called

memory address space• In assembly we use labels • Memory address space is used to store

instructions and data

4

Typical Memory OrganizationMemory Address Space

Text

Addresses0x000000000x00000001

.

.

.

Direction of growthAt run-time

Data

Stack

•Hold the instructions•Usually read-only fromProgrammer point of view

•OS can still write to it

To store the data (localand global) during run-time

To store data required during Subroutine activation, includingLocal variables

Register Model FAQ• Where are the registers?

– Inside the processor chip• What is their function

– Holding data needed frequently• How many registers do we have?

– Usually few • Why?

– Decoder used in selection is much smaller than the one used for memory

– Limited space on-chip– Few bits to specify a register– Technology

5

Commonly Used Registers• PC: program counter• ACC: Accumulator• SP: Stack Pointer• Link register• General purpose registers (GPRs)• Flag register

– N---negative result– Z--- zero result– V--- overflow– C--- carry– other

What about Data Types?

• There is no notion of variables• Type is specified based on the

instruction used• Instructions deal with few data types:

– Signed/unsigned integers– Floating point– Decimal (BCD)– characters

6

Instructions• Each assembly-level architecture has its

own group of instructions -> instruction set

• Instructions can be grouped into four categories:– Data Transfer– Data Manipulation– Program Sequencing and Control– Trap/system call

Instructions: Data Transfer

7

Instructions: Data Manipulation

Instructions: Program Sequencing and Control

8

Welcome to MIPS Assembly Language

Why MIPS?• Patterson and Hennessy use MIPS assembly language. Given the

overwhelming acceptance of their textbook as the standard, this is already a strong argument.

• RISC architectures actually are dominant. • It's best to teach a subject by going from the simple to the

complex. The MIPS R2000 instruction set architecture is probably the simplest in existence for a real processor with a significant market. In contrast, the Intel architecture, is extremely complex.

• Electrical and software engineers do, in fact, need to write assembly-language programs for embedded processors. (e.g. HP 4000 laser printer, Nintendo, Sony playstation, etc.)

• Other system integrators, such as router and telephone-switch manufacturers, make use of embedded processors.

• In all cases, these RISC architectures are extremely similar to the MIPS R2000 architecture that Hennessy and Patterson use throughout their text. A student who has learned the MIPS R2000 instruction set is in a good position to write programs for any embedded RISC processor.

9

You really should do…• http://www.cs.unibo.it/~solmi/teaching/arch_2002-

2003/AssemblyLanguageProgDoc.pdf(MIPS assembly Language Programmer’s Guide -> download it!)

http://logos.cs.uic.edu/366/notes/MIPS%20Quick%20Tutorial.htm

(A quick start on MIPS assembly -> look at it!)

Get Some books:

MIPS Assembly Language Programmingby Robert Britton. Published by Prentice Hall.

See MIPS Runby Dominic Sweetman. Publisher: Morgan Kaufmann

Processor

Computer

Control(“brain”)

Datapath

Memory

(where programs, data live whenrunning)

Devices

Input

Output

Keyboard, Mouse

Display, Printer

Disk(where programs, data live whennot running)

Computer Structure

10

MIPS arithmetic

•All instructions have 3 operands and order is fixed (destination first)

Example:

C code: a = b + c

MIPS ‘code’: add a, b, c

“The natural number of operands for an operation like addition is three…requiring every instruction to have exactly three operands, no more and no less, conforms to the philosophy of keeping the hardware simple”

MIPS arithmetic

•Design Principle: simplicity favors regularity. •Of course this complicates some things...

(what are these things?)

C code: a = b + c + d;

MIPS code: add a, b, cadd a, a, d

•Operands must be registers, •Only 32 registers provided•Each register contains 32 bits•Design Principle: smaller is faster.

What about programs with lots of variables?

11

12

13

14

15

Let $s3 = …1001 0100

Meaning:$t0 = Memory[$s3+24]

16

17

Memory Organization

•Viewed as a large, single-dimension array, with an address.•A memory address is an index into the array•"Byte addressing" means that the index points to a byte of

memory.

0

1

2

3

4

5

6

...

8 bits of data

8 bits of data

8 bits of data

8 bits of data

8 bits of data

8 bits of data

8 bits of data

18

Memory Organization

•Bytes are nice, but most data items use larger "words"•For MIPS, a word is 32 bits or 4 bytes.•Registers hold 32 bits of data•232 bytes with byte addresses from 0 to 232-1•230 words with byte addresses 0, 4, 8, ... 232-4

Instructions•Load and store instructions•Example:

C code: A[12] = h + A[8];

MIPS code: lw $t0, 32($s3)add $t0, $s2, $t0sw $t0, 48($s3)

•Can refer to registers by name (e.g., $s2, $t2) instead of number•Store word has destination last•Remember arithmetic operands are registers, not memory!

Can’t write: add 48($s3), $s2, 32($s3)•Byte Addressing: 4x8=32•$s3 is called Base Register•Data Transfer Instruction: A[8] is offset

19

Summary

•MIPS— loading words but addressing bytes— arithmetic on registers only

•Instruction Meaning

add $s1, $s2, $s3 $s1 = $s2 + $s3sub $s1, $s2, $s3 $s1 = $s2 – $s3lw $s1, 100($s2) $s1 = Memory[$s2+100] sw $s1, 100($s2) Memory[$s2+100] = $s1

20

ori = OR immediate

21

22

23

Examples of sll &srlSll $t2, $s0, 2 Multiply by 4

….0010…00100 Shift left once (* by 2)

…001000 Shift left twice(* by 4)srl $t2, $s0, 2 Divide by 4001…0001… Shift right once (div by 2)00001…Shift right twice(div by 4)

24

25

MIPS Instruction Classes

26

27

28

29

(Section 2.8)

30

See you next time….