Assembly Language Working with the CPU.

Slides:



Advertisements
Similar presentations
Catch up on previous topics Summary and putting together first four classes.
Advertisements

Branches Two branch instructions:
Arrays First step is to reserve sufficient space for the array.
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker.
5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
SPRING 2015 QtSpim Demo & Tutorial. 2 By DGP Outline How to write your own MIPS assembly language program How to use QtSpim simulator.
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.
Some Samples of MIPS Assembly Language Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Function Continued
MIPS Assembly Language Programming
Ch. 8 Functions.
1 Computer Architecture MIPS Simulator and Assembly language.
The University of Adelaide, School of Computer Science
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
ECE 0142 Recitation #5.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
1 Review Chpt 2 and 3 Five components of a computer Input Output Memory Arithmetic & Logic Unit (ALU) Control Two types of information Data and instruction.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
Feb 18, 2009 Lecture 4-2 instruction set architecture (Part II of [Parhami]) MIPS encoding of instructions Spim simulator more examples of MIPS programming.
Lecture 5: Procedures. Function call book-keeping in C main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } /* really dumb mult function */
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.
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang.
In Class Execise. .data A:.word 0,1,2,3,4,5,6,7,8,9.text.globl main main: la $a0,A li $a1,6 li $a2,5 jal onUpStream done: li $v0, 10# exit syscall onUpStream:
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
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.
Lecture 161 Lets examine a SPIM program in detail. io.asm This program is a simple routine which demonstrates input/output using assembly code. SPIM.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Pseudo instructions. MIPS supports pseudo instructions. We have seen some like – li $t0, 4 which set $t0 to 4. – la $t0, A which puts the address of label.
MIPS assembly syntax Home Assignment 3 Assigned. Deadline 2016 February 14, Sunday.
The Assembly Process Computer Organization and Assembly Language: Module 10.
CS 312 Computer Architecture & Organization
System Calls & Arithmetic
Computer Architecture & Operations I
MIPS Instruction Set Advantages
CS 286 Computer Organization and Architecture
MIPS Coding Continued.
MIPS assembly syntax Comments
Pseudo instructions.
MIPS coding.
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
SPIM Syscalls.
MPIS Instructions Functionalities of instructions Instruction format
MIPS Functions.
MIPS coding.
Pseudo instructions.
Компьютерийн зохион байгуулалт, ассемблер CS201
MIPS Coding.
MIPS function continued
Компьютерийн зохион байгуулалт, ассемблер CS201
COMS 361 Computer Organization
QtSpim Demo & Tutorial SPRING 2011.
CS 286 Computer Organization and Architecture
Review.
MIPS coding.
Generalities for Assembly Language
MIPS Assembly Language Programming Computer Architecture
9/27: Lecture Topics Memory Data transfer instructions
CS 286 Computer Architecture & Organization
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Introduction to SPIM Simulator
PROF. JOHN ABRAHAM UTRGV
Presentation transcript:

Assembly Language Working with the CPU

Overview What is SPIM? Fetch-Execute Cycle Declaring “variables” I/O Commands Loops

What is SPIM? SPIM is a simulator that runs programs for the MIPS R2000/R3000 RISC computers SPIM is MIPS backwards PC-SPIM is the windows version of SPIM MIPS Assembly files usually end in .a

Why is Assembly Important?

Fetch-Execute Cycle

Text vs Data Assembly programs have two sections: Instructions go here Larger of the two sections Contains the beginning of the program Data Where the variables are declared A limited number of data types in ASM Everything is separated by tabs!

Declaring Data Done in the .data section <name>: .<type> <value> str: .asciiz “Hello World\0” str2: .ascii “Hello” number: .byte 10 bigNum: .word 10000

The Registers Note: there are also 16 floating-point registers $f0-$f15

I/O Load one of these values into $v0 and arguments into registers $a0…$a3. $v0 is for system calls

Hello World It is very important that you understand when the syscall .text # instruction segment starts here .globl __start # tell where to start __start: # execution starts here la $a0, str # load the address of str into $a0 li $v0, 4 # syscall 4 prints the string whose address is in $a0 # look at chart! syscall # call syscall li $v0, 10 # syscall 10 exit program .data # data segment starts here str: .asciiz "hello world\n" #define a null terminated string called str It is very important that you understand when the syscall is executed, it will look in $a0 for what is to be printed

Commands add $r0, $r2, $r3 # r0 = r2 + r3 addi $t0, $t1, 15 # t0 = t1 + 15 (from instruction) sub $r0, $r0, $r3 # r0 = r0 – r3 mul $t0, $t1, $t2 # t0 = t1 * t2 div $t0, $t1, $t2 # t0 = t1 / t2 la $a0, str # load address of str into $a0 li $t1, 3 # t1 = 3 (from instruction)

Multiplication/Division Because multiplication/division can result in a larger number, there are two special registers named lo and hi # move 5 into $t0 li $t0, 5 # move 2 into $t1 li $t1, 2 # mult, putting into lo & hi mult $t0, $t1 # move from lo into $t3 mflo $t3

.text # Fahrenheit to Celsius calculator .globl __start __start: la $a0, prompt # print prompt on terminal li $v0, 4 syscall li $v0, 5 # read from user mul $t0, $v0, 9 # to convert, multiply by 9, div $t0, $t0, 5 # divide by 5, then add $t0, $t0, 32 # add 32 la $a0, ans1 # print string before result move $a0, $t0 # print result li $v0, 1 la $a0, endl # system call to print li $v0, 4 # out a newline li $v0, 10 # exit program .data # data segment prompt: .asciiz "Enter temperature (Celsius): " ans1: .asciiz "The temperature in Fahrenheit is: " endl: .asciiz "\n"

Control Structures j <addr> #update PC to be addr beq $t0, $t1, <addr> #if t0==t1, go to addr beqz $t0, <addr> #if t0 == 0, go to addr bne $t0, $t1, <addr> #if t0 != t1, go to addr blt $t0, $t1, <addr> #if t0 < t1, go to addr “Mmmm.. blt…” – Homer Simpson

Labels Anywhere in our code, we can put a label Labels are names in the code Keep us from having to know the exact memory address! Labels are followed by a colon myLabel:

Count to 10 .text .globl __start __start: li $t0, 0 # $t0 will be our counter, starting at 0 loop: # here is our label to jump to later add $t0, 1 # $t0 = $t0 + 1 move $a0, $t0 # $a0 = $t0, necessary because $v0 works with $a0 li $v0, 1 # what kind of syscall? Print int! Go back & look at chart syscall la $a0, endl # print a return (\n) li $v0, 4 bne $t0, 10, loop # if $t0 != 10, then branch to the loop label li $v0, 4 # print “Thank you” la $a0, str .data # data section endl: .asciiz "\n"; str: .asciiz "Thank you!\n"

Reading in Strings First, need to open up space for the string # open up 64 bytes mySpace: .space 64 String goes into $a0, and length into $a1 la $a0, mySpace li $a1, 64 Do system call li $v0, 8 Now, mySpace is an array of characters!

mySpace 1 2 3 4 5 6 63 H E L L O \n \0 ………

.text .globl __start __start: la $a0, gimme # print gimme a cookie li $v0, 4 syscall li $v0, 8 # read string $a0 = buffer, $a1 = l la $a0, mySpace # read into mySpace li $a1, 64 # read max of 64 li $t0, 0 # this is our counter li $t5, 6 # number of letter in cookie loop: lb $t2, mySpace($t0) # copy char of mySpace into $t2 lb $t3, cookie($t0) # copy char of cookie into $t3 bne $t2, $t3, __start # if not equal, jump to start addi $t0, 1 # $t0 = $t0 + 1 bne $t0, $t5, loop # if $t0 isn't 6, jump back to loop end: la $a0, rock # print you rock! .data gimme: .asciiz "Gimme a cookie: " rock: .asciiz "You rock!\n" mySpace: .space 64 cookie: .asciiz "cookie"

For More Information http://www.compapp.dcu.ie/~jkellehe/architecture/