CS 286 Computer Architecture & Organization

Slides:



Advertisements
Similar presentations
Goal: Write Programs in Assembly
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Branches Two branch instructions:
Deeper Assembly: Addressing, Conditions, Branching, and Loops
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker.
SPIM and MIPS programming
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
MIPS Function Continued
MIPS Assembly Language Programming
Assembly Language Working with the CPU.
ECE 0142 Recitation #5.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
MIPS Instruction Set Advantages
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
First Programming Assignment For MIPS R3000 Processor Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki.
MIPS R3000 Subroutine Calls and Stack Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Registers and MAL Lecture 12. The MAL Architecture MAL is a load/store architecture. MAL supports only those addressing modes supported by the MIPS RISC.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
Ch2b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Thanks for all the Memory! When 32 registers just won’t do. Many times (almost.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
The Assembly Process Computer Organization and Assembly Language: Module 10.
MIPS Architecture Topics –What resources MIPS assembly manipulates –CPU (Central Processing Unit) –ALU (Arithmetic & Logical Unit), Registers –Memory –I/O.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
CS 312 Computer Architecture & Organization
Deeper Assembly: Addressing, Conditions, Branching, and Loops
MIPS Instruction Set Advantages
Introduction to Lab #1 José Nelson Amaral.
CS2100 Computer Organisation
Control Unit Lecture 6.
Lecture 7: MARS, Computer Arithmetic
CS 286 Computer Organization and Architecture
MIPS Coding Continued.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Assembly Programming using MIPS R3000 CPU
CS170 Computer Organization and Architecture I
MIPS coding.
CS/COE0447 Computer Organization & Assembly Language
Instructions - Type and Format
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
MPIS Instructions Functionalities of instructions Instruction format
MIPS Functions.
MIPS coding.
Instruction encoding The ISA defines Format = Encoding
Review.
MIPS Assembly.
3.
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
CS 286 Computer Architecture & Organization
CS 286 Computer Organization and Architecture
MIPS Instruction Set Architecture
Assembly Programming using MIPS R3000 CPU
MIPS Assembly.
Instruction encoding The ISA defines Format = Encoding
MIPS Coding Continued.
MIPS coding.
MIPS assembly.
Generalities for Assembly Language
MIPS Assembly Language Programming Computer Architecture
9/27: Lecture Topics Memory Data transfer instructions
7/6/
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
MIPS R3000 Subroutine Calls and Stack
9/13/
MIPS instructions.
CS/COE0447 Computer Organization & Assembly Language
Presentation transcript:

CS 286 Computer Architecture & Organization MIPS 3000 Assembly Programming Part 2 (Load, Store, data types and sys-calls) Department of Computer Science Southern Illinois University Edwardsville Summer, 2019 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu Assembly_Prog_01/000

CS 286 Computer Architecture & Organization Execution of a simple C/C++ statement by assembly instructions C/C++ statement Assembly instructions LW $S1, (address of B) A = B + C; LW $S2, (address of C) ADD $S3, $S2, $S1 Processor Memory SW $S3, (address of A) ALU (Arithmetic Logic Unit) B C A LW (Load Word) + B+C LW (Load Word) S1 S2 S3 B C SW (Store Word) Processor Registers Assembly_Prog_01/001

In the first programming CS 286 Computer Architecture & Organization Different types of “LOAD” (and “STORE”) instructions  li (load immediate)  la (load address)  lb (load byte)  lw (load word) In the first programming assignment, we need to use these three “load” instructions  lhw (load half-word) Assembly_Prog_01/002

CS 286 Computer Architecture & Organization  li (load immediate) How does this processor handle this number? = Load a constant (immediate) to a MIPS-3000 32-bit register As a 2’s complement signed integer Example li $t0, 6 A constant you want to the register “Load Immediate” operator “Destination” register “Source” parameter Don’t forget ‘,’ Register name to which a constant will be placed What are the other 29 bits? Register name should have ‘$’ MSB LSB 1 Assembly_Prog_01/003

CS 286 Computer Architecture & Organization  la (load address) = Load a constant (immediate) as a 32-bit memory address Example Memory address as a constant (immediate) (Using an immediate) la $s0, FA00CD0012 “Load Address” operator “Destination” register “Source” parameter “la” just assigns a 32-bit address value to a register Memory FA00CD0012 FA00CD0012 S0 register “la” does NOT load the contents of memory Assembly_Prog_01/004

CS 286 Computer Architecture & Organization How “level” works? Your *.asm file Only data (structure) or instructions are counted “label” Memory 4C000000 # ################################ # Program Header 4C000000 H 4C000000 e 4C000001 .data l 4C000002 l 4C000003 o 4C000004 message1: .asciiz “Hello World!” 4C000005 <space> message2: .asciiz “My name is …..” W 4C000006 o 4C000007 .text .globl main Constant “4C0000000” will be loaded to t4 r 4C000008 l 4C000009 main: d 4C00000A ! 4C00000B la $t4, message1 Constant “4C000000D” will be loaded to t1 4C00000C \0 4C00000D M 4C00000E y la $t1, message2 Assembly_Prog_01/005

CS 286 Computer Architecture & Organization  la (load address) = Load a constant (immediate) as a 32-bit memory address Example Memory address as a label (Using a label) la $s0, My_Address “Load Address” operator “Destination” register “Source” parameter Memory ***.asm Assembled + Loaded 4C000000 My_Address: Label “My_Address” XXXXXX My_Address: Assembly_Prog_01/006

CS 286 Computer Architecture & Organization  la (load address) = Load a constant (immediate) as a 32-bit memory address Example Memory address as a label (Using a label) la $s0, My_Address “Load Address” operator “Destination” operand “Source” operand “la” just assigns a 32-bit address value to a register Memory “la” does NOT load the contents of memory 0000CD0000 0000CD0000 S0 register Assembly_Prog_01/007

CS 286 Computer Architecture & Organization  lb (load byte) = Load a 8-bit data from memory to a MIPS-3000 32-bit register (This instruction will NOT modify the top 24 bits ) Example Four possible ways to specify the target memory address Memory lb $t0, (FA00CD0012) 1-byte Target Address lb $t0, MY_LABEL lb $t0, ($t1) lb $t0, 100 ($t1) MSB LSB t0 register  Assembly_Prog_01/008

CS 286 Computer Architecture & Organization  lb (load byte) = Load a 8-bit data from memory to a MIPS-3000 32-bit register (This instruction will NOT modify the top 24 bits ) Example Memory lb $t0, (FA00CD0012) 1-byte lb $t0, MY_LABEL Target Address 00011001 lb $t0, ($t1) lb $t0, 100 ($t1) t0 register MSB LSB   1 Top 24 bits are preserved Assembly_Prog_01/009

CS 286 Computer Architecture & Organization The target address MUST be a multiple of 4!  lw (load word) = Load a 32-bit data from memory to a MIPS-3000 32-bit register lw $t0, FFFFFFE Example Memory Illegal address! lw $t0, (FA00CD0012) 1-byte lw $t0, MY_LABEL Target Address 4 bytes lw $t0, ($t1) lw $t0, 100 ($t1) MSB LSB  t0 register Assembly_Prog_01/010

CS 286 Computer Architecture & Organization = FFFFFFFF (for a 32-bit processor) What’s the difference? Can it be a negative number? NOT a memory access -(2(N-1)) (2(N-1)) -1 la $s0, FA00CD0012 li $t0, 6 lw $t0, (FA00CD0012) lw $t0, FA00CD0012 2N -1 Memory A memory access Is this an illegal parameter (operand)? Target Address Assembly_Prog_01/011

CS 286 Computer Architecture & Organization System Calls Systems calls in SPIM is something like sub-routine calls in a high-level programming language that perform useful tasks Such as: - Print a message (a character string) on the local monitor - Print an integer on the local monitor - Take a user input from the keyboard and store the key input in a register A list of SPIM system calls available Figure A.17 (p. A-49) Assembly_Prog_01/012

CS 286 Computer Architecture & Organization Major system calls available in MIPS R3000 simulator The system calls with the yellow background Those we use in the first programming assignment Assembly_Prog_01/013

ASCII character string CS 286 Computer Architecture & Organization System Call:  Print a message (a character string on the local monitor) Procedure for SPIM system-call #4: “print a message” Specify the type of your message data Declare the beginning of the data section System Call #4 = “print a message” .data Create a label for your character string my_string: .asciiz “Hello World!” Your message as an ASCII character string .text .globl main main: li $v0, 4 System call la $a0, my_string syscall Memory address where your message is stored jr $31 Assembly_Prog_01/014

CS 286 Computer Architecture & Organization System Call:  Print a number (integer) on the local monitor Nothing to be prepared in .data Procedure for SPIM system-call #1: “print a number” System Call #1 = “print a number” .data .text .globl main It’s “li” (NOT “la”) main: li $v0, 1 li $a0, 9 syscall jr $31 The number you want to display as an immediate Assembly_Prog_01/015

CS 286 Computer Architecture & Organization System Call:  Take a user input (as an integer) from the keyboard .data .text .globl main Nothing to be prepared in .data Procedure for SPIM system-call #5: “take a user input (integer)” System Call #5 = “Take user input” main: li $v0, 5 syscall jr $31 The input value goes to $v0 register Assembly_Prog_01/016

CS 286 Computer Architecture & Organization Conditional branches and jumps Immediate address Label  Conditional branches  Jump (= unconditional branch) beq $t0, $t1, <destination address> bne $t0, $t1, <destination address> Compare $t0 and $t1 registers. If they hold the same value jump to the instruction in the destination address. Compare $t0 and $t1 registers. If they hold the different value, jump to the instruction in the destination address. j <destination address> Always jump to the instruction in the destination address. Assembly_Prog_01/017

CS 286 Computer Architecture & Organization Examples for conditional branches .text .globl main These instructions will be executed only if t0  t1! jump is needed to skip “if_equal” main:     beq $t0, $t1, if_equal This implements if-then-else structure instruction A These instructions will be executed only if t0 = t1!     j end_if_else if_equal: instruction B     end_if_else: instruction C Assembly_Prog_01/018

CS 286 Computer Architecture & Organization Copying a register to another Load instructions can not be used for data transfer between two registers Move instructions must be used for register-to-register data transfer Example move $s0, $s1 “To” “From” Simple integer arithmetic add $t0, $t1, $t2 (t0 = t1 + t2) sub $t0, $t1, $t2 (t0 = t1 - t2) Assembly_Prog_01/019

CS 286 Computer Architecture & Organization Helpful Resources  The list of available registers (B-24)  Conditional branch instructions (B-59 through B-63) beq, bgez, blez, bne, ble, etc.  The list of available system-calls (B-44)  Sample programs for the major program-flow control (pp. 105-111) Assembly_Prog_01/020

CS 286 Computer Architecture & Organization The target address MUST be a multiple of 2!  lhw (load half-word) = Load a 16-bit data from memory to a MIPS-3000 32-bit register (This instruction will NOT modify the top 16 bits ) lw $t0, FFFFFFF Example Memory Illegal address! lhw $t0, (FA00CD0012) lhw $t0, ($t1) lhw $t0, 100 ($t1) lhw $t0, MY_LABEL 1-byte Target Address 2 bytes MSB LSB  t0 register Top 16 bits are preserved Assembly_Prog_01/000