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:

Slides:



Advertisements
Similar presentations
Branches Two branch instructions:
Advertisements

Deeper Assembly: Addressing, Conditions, Branching, and Loops
5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
Comp Sci Floating Point Arithmetic 1 Ch. 10 Floating Point Unit.
Computer Organization CS224 Fall 2012 Lesson 19. Floating-Point Example  What number is represented by the single-precision float …00 
05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.
Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
SPIM and MIPS programming
MIPS Function Continued
The University of Adelaide, School of Computer Science
Assembly Language Working with the CPU.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
MIPS Coding. Exercise – the bubble sort 5/8/2015week04-3.ppt2.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Fall 2003SYCS-401 Operating Systems Instruction Set Architecture An overview of MIPS R3000 assembly language.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
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.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 5 Unsigned integer and floating point.
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
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.
MIPS I/O and Interrupt. .data val1:.float 0.6 val2:.float 0.8 msg_done:.asciiz "done\n".text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
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.
MIPS I/O and Interrupt.
MIPS mul div, and MIPS floating point instructions.
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.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Floating Point Processor Condition Bit The MIPS Floating Point Accelerator (FPA) chip (now, usually part of the processor chip) has a condition bit that.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Review. Interger Number Representations To convert an unsigned decimal number to binary: you divide the number N by 2, let the remainder be the first.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
MIPS Coding. Exercise – the bubble sort 7/9/2016week04-3.ppt2.
MIPS Programming.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
System Calls & Arithmetic
CSCI206 - Computer Organization & Programming
MIPS Instruction Set Advantages
Lecture 7: MARS, Computer Arithmetic
MIPS floating point instructions
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Pseudo instructions.
CSCI206 - Computer Organization & Programming
MIPS coding.
MIPS I/O and Interrupt.
Final Review.
SPIM Syscalls.
Review.
MPIS Instructions Functionalities of instructions Instruction format
Solutions Chapter 2.
MIPS Functions.
ECE232: Hardware Organization and Design
Pseudo instructions.
Review.
Instruction encoding The ISA defines Format = Encoding
Review.
MIPS Coding.
MIPS function continued
Flow of Control -- Conditional branch instructions
MIPS Coding.
Flow of Control -- Conditional branch instructions
MIPS coding.
9/27: Lecture Topics Memory Data transfer instructions
MIPS function continued
Presentation transcript:

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: onUpStream_LOOP: lw $t0, 0($a0) beq $t0, $a1, onUpStream_NO beq $t0, $a2, onUpStream_YES addi $a0, $a0, 4 j onUpStream_LOOP onUpStream_YES: ori $v0, $0, 1 j onUpStream_DONE onUpStream_NO: ori $v0, $0, 0 onUpStream_DONE: jr $ra

SPIM Syscalls

SPIM syscalls li $v0,1# print an integer in $a0 li $a0,100 syscall li $v0,5# read an integer into $v0 syscall li $v0,4# print an ASCIIZ string at $a0 la $a0,msg_hello syscall li $v0,10 #exit syscall

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 A (a 32-bit value) into $t0. – bgt $t0, $t1, L1 which goes to L1 if $t0 > $t1

Pseudo instructions Pseudo instructions are not real instructions implemented in hardware. They are created to make the program more readable. A pseudo instruction usually (not always) maps to several real instructions. The mapping is one-to-one.

Pseudo instructions For example, li $t0, 4 translate to ori $t0, $0, 4 but what should li $t0, translate to?

Pseudo instructions So li $t0, translates to lui $1, 1#load upper 16 bits ori $t0, $1, The special register $1 is $at and should only be used for pseudo instructions.

Pseudo instructions How to translate `` lw $t0, val’’ ?

MIPS mul div, and MIPS floating point instructions

Multiply and Division Instructions mul rd, rs, rt – put the result of rs times rt in rd div rd, rs, rt – A pseudo instruction – put the quotient of rs/rt into rd

hi and lo mult rs,rt – put the high word in hi and low word in lo. div rs, rt – put the remainder in hi and quotient in lo.

Load and Store Load or store from a memory location (pseudoinstruction ). Just load the 32 bits into the register. – l.s $f0, val – s.s $f0, val Load immediate number (pseudoinstruction ) – li.s $f0, 0.5

Print and Read Print: – li $v0, 2 – li $f12, 0.5 – syscall Read – li $v0, 6 – syscall – (the read will be in $f0 )

Arithmetic Instructions abs.s $f0, $f1 add.s $f0, $f1, $f2 sub.s $f0, $f1, $f2 mul.s $f0, $f1, $f2 div.s $f0, $f1, $f2 neg.s $f0, $f1

Data move mov.s $f0, $f1 copy $f1 to $f0. mfc1 $t0, $f0 copy $f1 to $t0. mtc1 $t0, $f0 copy $t0 to $f0.

Convert to integer and from integer cvt.s.w $f0, $f1 – convert the 32 bit in $f1 currently representing an integer to float of the same value and store in $f0 cvt.w.s $f0, $f1 – the reverse

Comparison instructions c.lt.s $f0,$f1 – set a flag in coprocessor 1if $f0 < $f1, else clear it. The flag will stay until set or cleared next time c.le.s $f0,$f1 – set flag if $f0 <= $f1, else clear it bc1t L1 – branch to L1 if the flag is set bc1f L1 – branch to L1 if the flag is 0 Where does the bc1t instruction take place? The main processor or the coprocessor?

Computing the square root of a number n The Newton’s method x’=(x+n/x)/2 – For any n, guess an initial value of x as the sqrt of n and keep on updating x until is the difference between the two updates are very close. – The idea is that x’=x-f(x)/f’(x), where f(x) is x 2 - n=0.

. data val1:.float 0.6 val2:.float 0.8 msg_done:.asciiz "done\n".text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt done: mtc1 $v0, $f12 li $v0,2 syscall eixt: li $v0,10 syscall # calsqrt: # calculating the square root of n # using the formular x'=(x+n/x)/2 # loop until |x'-x| < calsqrt: addi $sp, $sp, -24 swc1 $f0, 20($sp) swc1 $f1, 16($sp) swc1 $f2, 12($sp) swc1 $f3, 8($sp) swc1 $f20, 4($sp) swc1 $f21, 0($sp) mtc1 $a0, $f0 # $f0 gets n li.s $f20, 2.0 # $f20 storing constant 2 for dividing li.s $f21, # $f21 storing constant for exit comparision div.s $f1, $f0, $f20 # $f1 gets n/2 calsqrtloop: div.s $f2, $f0, $f1 # $f2 gets n/x add.s $f2, $f2, $f1 # $f2 gets n/x + x div.s $f2, $f2, $f20 # $f2 gets x'=(n/x + x)/2 sub.s $f3, $f2, $f1 # $f3 gets x'-x abs.s $f3, $f3 # $f3 gets |x'-x| c.lt.s $f3, $f21 # set the flag if |x'-x| < bc1t calsqrtdone mov.s $f1, $f2 j calsqrtloop calsqrtdone: mfc1 $v0, $f2 lwc1 $f0, 20($sp) lwc1 $f1, 16($sp) lwc1 $f2, 12($sp) lwc1 $f3, 8($sp) lwc1 $f20, 4($sp) lwc1 $f21, 0($sp) addi $sp, $sp, 24 jr $ra