1 / 22

# MIPS 3000 Assembly Programming Part 2 (Load, Store, data types and sys-calls)

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

Télécharger la présentation

## MIPS 3000 Assembly Programming Part 2 (Load, Store, data types and sys-calls)

E N D

### Presentation Transcript

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

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

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

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

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

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

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

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

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

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

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

13. System Calls Figure A.17 (p. A-49) CS 286 Computer Architecture & Organization • 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 Assembly_Prog_01/012

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

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

16. 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 It’s “li” (NOT “la”) .text .globl main main: li \$v0, 1 li \$a0, 9 syscall The number you want to display as an immediate jr \$31 CS 286 Computer Architecture & Organization Assembly_Prog_01/015

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