computer systems
play

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


  1. CS 230 – Introduction to Computers and Computer Systems Lecture 7 – Assembly Language Intro CS 230 - Spring 2020 2-1

  2. System Layers Python/C/Racket Code Multiprocessing and Operating Systems Build and Runtime Environments Memory and Caching CS 230 CPU Instructions Here now! and Pipelining Binary Signals & Number Representation Finished! Logic Gates Transistors and Electrical Properties CS 230 - Spring 2020 2-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 CS 230 - Spring 2020 2-3

  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” CS 230 - Spring 2020 2-4

  5. Instruction Set  Repertoire of instructions of a processor  Different processors have different sets  many commonalities  mathematical  memory access  control flow CS 230 - Spring 2020 2-5

  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 CS 230 - Spring 2020 2-6

  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  1 st is destination, 2 nd and 3 rd are sources  same register can be source and destination CS 230 - Spring 2020 2-7

  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 14 10  often used to initialize registers: addi $t, $0, i CS 230 - Spring 2020 2-8

  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 CS 230 - Spring 2020 2-9

  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

  11. Example addi $2, $0, -3 add $3, $2, $0 $0 $1 $2 $3 $4 $5 … ? … sub $3, $3, $2 0 ? ? ? ? jr $31 What is the value in register $3 at the end of this program? CS 230 - Spring 2020 2-11

  12. Example addi $2, $0, -3 add $3, $2, $0 $0 $1 $2 $3 $4 $5 … ? … sub $3, $3, $2 0 ? -3 ? ? jr $31 What is the value in register $3 at the end of this program? CS 230 - Spring 2020 2-12

  13. Example addi $2, $0, -3 add $3, $2, $0 $0 $1 $2 $3 $4 $5 … ? … sub $3, $3, $2 0 ? -3 -3 ? jr $31 What is the value in register $3 at the end of this program? CS 230 - Spring 2020 2-13

  14. Example addi $2, $0, -3 add $3, $2, $0 $0 $1 $2 $3 $4 $5 … ? … sub $3, $3, $2 0 ? -3 0 ? jr $31 What is the value in register $3 at the end of this program? CS 230 - Spring 2020 2-14

  15. Example addi $2, $0, -3 add $3, $2, $0 $0 $1 $2 $3 $4 $5 … ? … sub $3, $3, $2 0 ? -3 0 ? jr $31 What is the value in register $3 at the end of this program? • $3 = 0 10 CS 230 - Spring 2020 2-15

  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

  17. Try it yourself addi $1, $0, 13 addi $2, $1, 0xA $0 $1 $2 $3 $4 $5 … ? … sub $4, $2, $1 0 ? ? ? ? jr $31 What is the value in register $4 at the end of this program? CS 230 - Spring 2020 2-17

  18. Try it yourself addi $1, $0, 13 addi $2, $1, 0xA $0 $1 $2 $3 $4 $5 … ? … sub $4, $2, $1 0 13 ? ? ? jr $31 What is the value in register $4 at the end of this program? CS 230 - Spring 2020 2-18

  19. Try it yourself addi $1, $0, 13 addi $2, $1, 0xA $0 $1 $2 $3 $4 $5 … ? … sub $4, $2, $1 0 13 23 ? ? jr $31 What is the value in register $4 at the end of this program? CS 230 - Spring 2020 2-19

  20. Try it yourself addi $1, $0, 13 addi $2, $1, 0xA $0 $1 $2 $3 $4 $5 … 0 13 23 ? 10 ? … 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

  21. Try it yourself addi $1, $0, 13 addi $2, $1, 0xA $0 $1 $2 $3 $4 $5 … 0 13 23 ? 10 ? … sub $4, $2, $1 jr $31 What is the value in register $4 at the end of this program? • $4 = 10 10 CS 230 - Spring 2020 2-21

  22. Example Consider the equation z = x + y + 83 10 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

  23. Example Consider the equation z = x + y + 83 10 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

  24. Example Consider the equation z = x + y + 83 10 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

  25. Example Consider the equation z = x + y + 83 10 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

  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

  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

  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

  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

  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

Recommend


More recommend