Download presentation
Presentation is loading. Please wait.
1
CS 312 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, 2016 Dr. Hiroshi Fujinoki Assembly_Prog_01/001
2
CS 312 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/002
3
In the first programming
CS 312 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/003
4
CS 312 Computer Architecture & Organization
li (load immediate) How does this processor handle this number? = Load a constant (immediate) to a MIPS 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/004
5
CS 312 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/005
6
CS 312 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 “4C ” 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/006
7
CS 312 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/007
8
CS 312 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/008
9
CS 312 Computer Architecture & Organization
lb (load byte) = Load a 8-bit data from memory to a MIPS 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/009
10
CS 312 Computer Architecture & Organization
lb (load byte) = Load a 8-bit data from memory to a MIPS bit register (This instruction will NOT modify the top 24 bits ) Example Memory lb $t0, (FA00CD0012) 1-byte lb $t0, MY_LABEL Target Address lb $t0, ($t1) lb $t0, 100 ($t1) t0 register MSB LSB 1 Top 24 bits are preserved Assembly_Prog_01/010
11
CS 312 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 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/011
12
CS 312 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/012
13
CS 312 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/013
14
CS 312 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/014
15
ASCII character string
CS 312 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/015
16
CS 312 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/016
17
CS 312 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/017
18
CS 312 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/018
19
CS 312 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/019
20
CS 312 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/020
21
CS 312 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 ) Assembly_Prog_01/021
22
CS 312 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 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.