Computer Systems Lecture 7 Assembly Language Intro CS 230 - Spring - - PowerPoint PPT Presentation

computer systems
SMART_READER_LITE
LIVE PREVIEW

Computer Systems Lecture 7 Assembly Language Intro CS 230 - Spring - - PowerPoint PPT Presentation

CS 230 Introduction to Computers and Computer Systems Lecture 7 Assembly Language Intro CS 230 - Spring 2020 2-1 System Layers Python/C/Racket Code Multiprocessing and Operating Systems Build and Runtime Environments Memory and


slide-1
SLIDE 1

CS 230 - Spring 2020 2-1

CS 230 – Introduction to Computers and Computer Systems Lecture 7 – Assembly Language Intro

slide-2
SLIDE 2

System Layers

CS 230 - Spring 2020 2-2

Transistors and Electrical Properties Logic Gates Binary Signals & Number Representation CPU Instructions and Pipelining Memory and Caching Build and Runtime Environments Multiprocessing and Operating Systems Python/C/Racket Code CS 230 Here now! Finished!

slide-3
SLIDE 3

CS 230 - Spring 2020 2-3

Machine Code

 Binary code – comprised of 0s and 1s  “Direct” execution by processor  Program composed of instructions

 operation code (opcode) + operands  instructions control processor

 opcode says what thing to do  operands say what to apply that thing to

slide-4
SLIDE 4

CS 230 - Spring 2020 2-4

Assembly Language

 Human-readable “programming language”

 very simple compared to Racket, Python, etc.

 Almost direct mapping to machine code

 except a few concepts we’ll cover later

 Assembler turns it into machine code

 process is called “assembling” rather than “compiling”

slide-5
SLIDE 5

CS 230 - Spring 2020 2-5

Instruction Set

 Repertoire of instructions of a processor  Different processors have different sets

 many commonalities

 mathematical  memory access  control flow

slide-6
SLIDE 6

CS 230 - Spring 2020 2-6

MIPS Architecture

 MIPS: Microprocessor without Interlocked

Pipeline Stages

 details later

 Multiple revisions, systems, and compilers

 not just a single standard MIPS  we use simplified version in CS 230

slide-7
SLIDE 7

CS 230 - Spring 2020 2-7

MIPS Assembly Language

 Each instruction takes 32 bits

 4 bytes = 1 word

 Arithmetic instructions operate on registers

 32 registers available numbered $0 to $31

 refer to them in assembly language with $[register number]

 register $0 always equals 0

 Instructions have up to 3 operands

 1st is destination, 2nd and 3rd are sources  same register can be source and destination

slide-8
SLIDE 8

CS 230 - Spring 2020 2-8

Immediate Addition

addi $t, $s, i

 add register s and value i  value i can be negative  value i can be hexadecimal  place result in register t  example: addi $1, $2, 14

 sets content of $1 to the content of $2 plus 1410

 often used to initialize registers: addi $t, $0, i

slide-9
SLIDE 9

CS 230 - Spring 2020 2-9

Addition and Subtraction

add $d, $s, $t

 add content of register s and t  place result in register d  example: add $3, $2, $1

 sets content of $3 to content of $2 plus content of $1

sub $d, $s, $t

 subtract register t from s  place result in register d  example: sub $6, $5, $4

 sets content of $6 to content of $5 minus content of $4

slide-10
SLIDE 10

Example

addi $2, $0, -3 add $3, $2, $0 sub $3, $3, $2 jr $31 What is the value in register $3 at the end of this program?

CS 230 - Spring 2020 2-10

slide-11
SLIDE 11

Example

addi $2, $0, -3 add $3, $2, $0 sub $3, $3, $2 jr $31 What is the value in register $3 at the end of this program?

CS 230 - Spring 2020 2-11

$0 $1 $2 $3 $4 $5 … ? ? ? ? ? …

slide-12
SLIDE 12

Example

addi $2, $0, -3 add $3, $2, $0 sub $3, $3, $2 jr $31 What is the value in register $3 at the end of this program?

CS 230 - Spring 2020 2-12

$0 $1 $2 $3 $4 $5 … ?

  • 3

? ? ? …

slide-13
SLIDE 13

Example

addi $2, $0, -3 add $3, $2, $0 sub $3, $3, $2 jr $31 What is the value in register $3 at the end of this program?

CS 230 - Spring 2020 2-13

$0 $1 $2 $3 $4 $5 … ?

  • 3 -3

? ? …

slide-14
SLIDE 14

Example

addi $2, $0, -3 add $3, $2, $0 sub $3, $3, $2 jr $31 What is the value in register $3 at the end of this program?

CS 230 - Spring 2020 2-14

$0 $1 $2 $3 $4 $5 … ?

  • 3

? ? …

slide-15
SLIDE 15

Example

addi $2, $0, -3 add $3, $2, $0 sub $3, $3, $2 jr $31 What is the value in register $3 at the end of this program?

  • $3 = 010

CS 230 - Spring 2020 2-15

$0 $1 $2 $3 $4 $5 … ?

  • 3

? ? …

slide-16
SLIDE 16

Try it yourself

addi $1, $0, 13 addi $2, $1, 0xA sub $4, $2, $1 jr $31 What is the value in register $4 at the end of this program?

CS 230 - Spring 2020 2-16

slide-17
SLIDE 17

Try it yourself

addi $1, $0, 13 addi $2, $1, 0xA sub $4, $2, $1 jr $31 What is the value in register $4 at the end of this program?

CS 230 - Spring 2020 2-17

$0 $1 $2 $3 $4 $5 … ? ? ? ? ? …

slide-18
SLIDE 18

Try it yourself

addi $1, $0, 13 addi $2, $1, 0xA sub $4, $2, $1 jr $31 What is the value in register $4 at the end of this program?

CS 230 - Spring 2020 2-18

$0 $1 $2 $3 $4 $5 … 0 13 ? ? ? ? …

slide-19
SLIDE 19

Try it yourself

addi $1, $0, 13 addi $2, $1, 0xA sub $4, $2, $1 jr $31 What is the value in register $4 at the end of this program?

CS 230 - Spring 2020 2-19

$0 $1 $2 $3 $4 $5 … 0 13 23 ? ? ? …

slide-20
SLIDE 20

Try it yourself

addi $1, $0, 13 addi $2, $1, 0xA sub $4, $2, $1 jr $31 What is the value in register $4 at the end of this program?

CS 230 - Spring 2020 2-20

$0 $1 $2 $3 $4 $5 … 0 13 23 ? 10 ? …

slide-21
SLIDE 21

Try it yourself

addi $1, $0, 13 addi $2, $1, 0xA sub $4, $2, $1 jr $31 What is the value in register $4 at the end of this program?

  • $4 = 1010

CS 230 - Spring 2020 2-21

$0 $1 $2 $3 $4 $5 … 0 13 23 ? 10 ? …

slide-22
SLIDE 22

Example

Consider the equation z = x + y + 8310 Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y.

CS 230 - Spring 2020 2-22

slide-23
SLIDE 23

Example

Consider the equation z = x + y + 8310 Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y. add $3, $1, $2

CS 230 - Spring 2020 2-23

slide-24
SLIDE 24

Example

Consider the equation z = x + y + 8310 Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y. add $3, $1, $2 addi $3, $3, 83

CS 230 - Spring 2020 2-24

slide-25
SLIDE 25

Example

Consider the equation z = x + y + 8310 Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y. add $3, $1, $2 addi $3, $3, 83 jr $31

CS 230 - Spring 2020 2-25

slide-26
SLIDE 26

Try it Yourself

Consider the equation z = (x – y) – (0xB3C + y) Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y.

CS 230 - Spring 2020 2-26

slide-27
SLIDE 27

Try it Yourself

Consider the equation z = (x – y) – (0xB3C + y) Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y. sub $4, $1, $2

CS 230 - Spring 2020 2-27

slide-28
SLIDE 28

Try it Yourself

Consider the equation z = (x – y) – (0xB3C + y) Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y. sub $4, $1, $2 addi $3, $2, 0xB3C

CS 230 - Spring 2020 2-28

slide-29
SLIDE 29

Try it Yourself

Consider the equation z = (x – y) – (0xB3C + y) Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y. sub $4, $1, $2 addi $3, $2, 0xB3C sub $3, $4, $3

CS 230 - Spring 2020 2-29

slide-30
SLIDE 30

Try it Yourself

Consider the equation z = (x – y) – (0xB3C + y) Assume x represents $1, y represents $2, and z represents $3. Write a MIPS assembly language program that evaluates the value of z given x and y. sub $4, $1, $2 addi $3, $2, 0xB3C sub $3, $4, $3 jr $31

CS 230 - Spring 2020 2-30