MIPS assembler language de branching

Benzer belgeler
Ozet. Review pointers (in C) Memory Addressing

BM-311 Bilgisayar Mimarisi

Lecture 7. Assembler language nedir? Language in 3 seviyesi. Language 3 seviyesi. Nicin onu ogreniriz?

Spatial locality nin getirdigi avantaji kullanmak

Hem lw hem de sw komutlarının ofseti 16-bitlik işaretli tamsayıdır.

Assembly Language Programming

Memory. Amac. Baslangictan beri programcilar unlimited hizli memory ler hayal etmisler 1972, PDP-11/20. Oku H&P sections 7.1, 7.2

Multiplication/division

BM-311 Bilgisayar Mimarisi

BM-311 Bilgisayar Mimarisi

Stack Islemleri. Postfix ve Infix notasyonlari. Stack ozellikleri

Komut Seti Mimarisi (ISA)

PC is updated PS güncellenir

BİLGİSAYAR MİMARİSİ. Bilgisayar Bileşenleri Ve Programların Yürütülmesi. Özer Çelik Matematik-Bilgisayar Bölümü

En kucuk calisabilir birime satetement denir Statements semicolon (;) ile sonlanir Yalniz basina ; null statement i ifade eder

Hiyerarşik Yazılım Tasarımı Kavramı

DOĞU AKDENİZ ÜNİVERSİTESİ BAHAR BİLGİSAYAR MÜHENDİSLİĞİ BÖLÜMÜ BLGM-324 BİLGİSAYAR MİMARİSİ DENEY #6

W SAYAC SAYAC SAYAC. SAYAC= ise, d=0 W

80x86 MICROPROCESSOR Instructions

Şekil. 64 Kelimelik Yığıtın Blok Şeması

K uark projesi. Temel Özellikler :

Bölüm 6. Diziler (arrays) Temel kavramlar Tek boyutlu diziler Çok boyutlu diziler

İŞLETİM SİSTEMİ İşletim sistemi kullanıcıyla bilgisayar donanımı arasında iletişim sağlayan programdır.

Linux Assembly Programlamaya Giriş

Bölüm 3: Adresleme Modları. Chapter 3: Addressing Modes

BM 375 Bilgisayar Organizasyonu Dersi Vize Sınavı Cevapları 10 Nisan 2009

BM-311 Bilgisayar Mimarisi

CISC Complex Instruction Set Computers

Clear omegle ban on puffin

Pros and Cons of Pointers. Pointers. Avantajlar. Dezavantajlar


Giris {\} /\ Suhap SAHIN

EEM 306 Mikroişlemciler ve Lab. Doç.Dr. Mehmet SAĞBAŞ

İSTANBUL TİCARET ÜNİVERSİTESİ BİLGİSAYAR MÜHENDİSLİĞİ BÖLÜMÜ MİKROİŞLEMCİLİ SİSTEM LABORATUVARI OLAYLARI ZAMANLAMA

DOĞU AKDENİZ ÜNİVERSİTESİ BAHAR BİLGİSAYAR MÜHENDİSLİĞİ BÖLÜMÜ BLGM-324 BİLGİSAYAR MİMARİSİ. PC-SPIMGirişi(MIPS R2000 Simulatörü)

Bahar Dönemi. Öğr.Gör. Vedat MARTTİN

TEMPLATES. Binnur Kurt Bilgisayar Mühendisliği Bölümü İstanbul Teknik Üniversitesi. C++ ile Nesneye Dayalı Programlama 1

Veri Yapıları ve Algoritmalar dönem

ATILIM UNIVERSITY Department of Computer Engineering

Final Sınavı Soruları Bahar 2018

Komutların Yürütülmesi

Adresleme Modları. Mikroişlemciler ve Mikrobilgisayarlar

Mikroişlemci ve Yapısı. Mikroişlemciler ve Mikrobilgisayarlar

12. HAFTA BLM323 SAYISAL ANALİZ. Okt. Yasin ORTAKCI.

1 I S L U Y G U L A M A L I İ K T İ S A T _ U Y G U L A M A ( 5 ) _ 3 0 K a s ı m

Logical signals. Active high or asserted logic. Logic threshold, yaklasik 1.4 volts. Read H&P sections B.3, B.4, B.5 Read H&P sections 5.1 and 5.

BM-311 Bilgisayar Mimarisi. Hazırlayan: M.Ali Akcayol Gazi Üniversitesi Bilgisayar Mühendisliği Bölümü

İSTANBUL TİCARET ÜNİVERSİTESİ BİLGİSAYAR MÜHENDİSLİĞİ BÖLÜMÜ MİKROİŞLEMCİLİ SİSTEM LABORATUVARI KESMELİ GİRİŞ/ÇIKIŞ

Maltepe Üniversitesi Bilgisayar Mühendisliği Bölümü BİL 203 Veri Yapıları ve Algoritmalar I

CSD İŞLETİM SİSTEMİNDE SİSTEM FONKSİYONLARININ ÇAĞIRILMASI

DOKUZ EYLUL UNIVERSITY FACULTY OF ENGINEERING OFFICE OF THE DEAN COURSE / MODULE / BLOCK DETAILS ACADEMIC YEAR / SEMESTER

Bölüm 4: İş Parçacıkları. Operating System Concepts with Java 8 th Edition

BM-311 Bilgisayar Mimarisi

MTM 305 MĠKROĠġLEMCĠLER

Virtualmin'e Yeni Web Sitesi Host Etmek - Domain Eklemek

1 RUBY HAKINDA 1 Ruby nin Gelişim Hikayesi 1 Neden Ruby? 1 Neden Bu Kadar Popüler? 2

Ilgili prefixes ler. 2 nin kuvvetleri. 2 nin kuvvetleri

Yrd. Doç. Dr. Caner ÖZCAN

Selection Sort Insertion Sort

x86 Ailesi Mikroişlemciler ve Mikrobilgisayarlar

Bölüm 9. Altprogramlar ISBN

İSTANBUL TİCARET ÜNİVERSİTESİ BİLGİSAYAR MÜHENDİSLİĞİ BÖLÜMÜ MİKROİŞLEMCİLİ SİSTEM LABORATUVARI OLAYLARI ZAMANLAMA

MIKRODENETLEYICILER. Ege Üniversitesi Ege MYO Mekatronik Programı

D-Link DSL 500G için ayarları

BAŞVURU ŞİFRE EDİNME EKRANI/APPLICATION PASSWORD ACQUISITION SCREEN

Onluk duzende toplama. Lecture 4. Addition and Subtraction. Onluk tabanda toplama

Yrd. Doç. Dr. Caner ÖZCAN

MİKROİŞLEMCİLER 1 Ders 1

Big Endian & Little Endian K.Atilla Toker İzmir Üniversitesi Meslek Yüksek Okulu Bilgisayar Programcılığı Ver:01

Mikrobilgisayar Mimarisi ve Programlama

PROGRAMLAMAYA GİRİŞ DERS 2

İçindekiler. Glossary

DÖNEM İÇİ NOT GİRİŞİ KULLANMA KILAVUZU

BLM 112- Programlama Dilleri II. Hafta 5 İşaretçiler (Pointers)

MİKROBİLGİSAYAR SİSTEMLERİ. Teknik Bilimler Meslek Yüksekokulu

İSTANBUL TİCARET ÜNİVERSİTESİ BİLGİSAYAR MÜHENDİSLİĞİ BÖLÜMÜ MİKROİŞLEMCİLİ SİSTEM LABORATUARI MİKROİŞLEMCİLİ A/D DÖNÜŞTÜRÜCÜ

VERİ YAPILARI DERS NOTLARI BÖLÜM 4 STACK (YIĞIN, YIĞIT) Yard. Doç. Dr. Deniz KILINÇ

Yüz Tanımaya Dayalı Uygulamalar. (Özet)

Eco 338 Economic Policy Week 4 Fiscal Policy- I. Prof. Dr. Murat Yulek Istanbul Ticaret University

YZM 2116 Veri Yapıları

KASIRGA -4 Buyruk Tasarımı Belgesi Ankara

DERS 3 MİKROİŞLEMCİ SİSTEM MİMARİSİ. İçerik

BM-311 Bilgisayar Mimarisi

C++ Statements. { ve } arasında ifade edilen bir dizi statement bir compound statement (birleşik ifade) oluşturur.

3/7/2011. ENF-102 Jeoloji 1. Tekrar -- Değişken Tanımlamaları (Definition) ve Veri Türleri (Data Type) Veri Tanımları ve Mantıksal Đşlemler

10/17/2007 Nesneye Yonelik Programlama 3.1

Teknoloji Servisleri; (Technology Services)

MODBUS MODBUS MODBUS PROTOKOLÜ

CNC MACH breakout board user manual V8 type

MTM 305 MİKROİŞLEMCİLER

Bölüm 4 Veri Aktarma Komutları

BM-311 Bilgisayar Mimarisi

BİL 361 BİLGİSAYAR MİMARİSİ VE ORGANİZASYONU Güz Dönemi ÖDEV 1

2 İş Hattı (Pipeline)

PostgreSQL ve PL/pgSQL

Final Sınavı Örnek Soruları Bahar 2018

Grade 8 / SBS PRACTICE TEST Test Number 9 SBS PRACTICE TEST 9

YIĞINLAR YIĞINLAR. Yığın İşlemleri Postfix, Prefix, Infix. G. Ü. Bilgisayar Mühendisliği Bölümü

C++ Programming: Program Design Including Data Structures, Third Edition. Bölüm 1: Bilgisayarlar ve Programlama Dillerine Kısa Bakış

Keyestudio SHT31 Temperature and Humidity Module / SHT31 Sıcaklık ve Nem Modülü

Transkript:

Read H&P section 3.5 and 3.6 MIPS assembler language de branching Kosula bagli olarak farkli instruction lar run et High-level language lerde IF statement ine benzer Similar to IF statement in a high-level language Assembly language branch veya jump instruction lari kullanarak programin farkli bolumlerine program executione yonlendirir 12/3/2004 Bilgisayar Mimarisi 9.1 12/3/2004 Bilgisayar Mimarisi 9.2 Branching in MIPS Branch la erisilebilen herhangi bir staement e label atanir workhere: add $t0, $t1, $t2 Branch Conditional (data-dependent) Unconditional (daima dallan) Branching in MIPS Conditional branche lar cok siklikla kullanililir High-level languages If statetements, loops (for, while, do-while) MIPS I formatta beq ve bneq instructionlarina sahip beq $t0, $t1, label # go to label if t0 = t1 bneq $t0, $t1, label # go to label if t0!= t1 12/3/2004 Bilgisayar Mimarisi 9.3 12/3/2004 Bilgisayar Mimarisi 9.4

Example of MIPS equality test if (a == b) c = c + 9; c = c + 5; // Java code here, MIPS // assy code below lw $t0, a # a, b, and c into registers lw $t1, b lw $t2, c bne $t0, $t1, add5 # bypass next line if a=b addi $t2, 9 # c = c + 9 add5: addi $t2, 5 # c = c + 5 sw $t2, c # result back to memory BNE not enough for if-else Asagidaki Java yapisi A nin hesaplanmasindan sonra unconditional jump instruction ina ihtiyac duyar if (a == b) do calculation A else do calculation B Eger a = b, B yi hesaplayan code uzerinden dallanilmali 12/3/2004 Bilgisayar Mimarisi 9.5 12/3/2004 Bilgisayar Mimarisi 9.6 Fabricate an unconditional branch? Unconditional Jump beq $t0, $t0, label # Daima dallan j label # always jump Unconditional branch dan yavas olacaktir MIPS gercek unconditional branch a sahip hizli J format: op address 6 26 Note: The address specifies words, not bytes, thus extending its range by 4 times 12/3/2004 Bilgisayar Mimarisi 9.7 12/3/2004 Bilgisayar Mimarisi 9.8

Example of MIPS if-else construct if (a == b) c = c + 9; else c = c + 5; // Java code here, MIPS // assy code below lw $t0, a # a, b, and c into registers lw $t1, b lw $t2, c bne $t0, $t1, add5 # bypass next line if a=b addi $t2, 9 # c = c + 9 j more # continue ahead add5: addi $t2, 5 # c = c + 5 more: sw $t2, c # result back to memory 12/3/2004 Bilgisayar Mimarisi 9.9 Address widths in 3 instruction formats R Format I Format J Format 6 5 5 5 5 6 OP RS RT RD shamt funct OP RS RT address OP address 16 bits 26 bits BEQ uses I format, branch address has 16 bits, so branch can only cover 64K bytes, which is 16K words. Thus a program can only fit in 64K bytes -- too small. J uses J format, branch address has 26 bits, so branch can cover 64M words. 12/3/2004 Bilgisayar Mimarisi 9.10 Extending the BEQ branch range 64 Kbyte program cok kucuk. Daha sonra BEQ instruction in range ini artirma yontemlerini gorecegiz. Branch gercekte ne demek PC ye fetch edilecek yeni instruction in address ini yukle Normal non-branching instruction larda sonraki instruction i execute et prensibi PC nindegeri 4 artirilarak sonraki instruction in address i bulunur 12/3/2004 Bilgisayar Mimarisi 9.11 12/3/2004 Bilgisayar Mimarisi 9.12

Branch on signed data Genel instructions blt,ble,bgt, bqe. Ornek: blt A,B,label # eger A <= B ise dallan MIPS hardware bu tip instructionlara sahip degil Assembler blt instruction i slt ve bne instruction larina cevirir (bne slt yi izler) blt instruction pseudo instruction olarak adlandirilir Set on Less Than (slt) slt $t0, $t1, $t2 t0 is set to 1 if t1 < t2, unchanged otherwise R-format (doesn t need a memory address) 12/3/2004 Bilgisayar Mimarisi 9.13 12/3/2004 Bilgisayar Mimarisi 9.14 How to do a blt blt $t1, $t2, overthere # does the same thing pseudoinstruction -- assembles into slt + bne slt $t0, $t1, $t2 # t0 = 1 if t1 < t2 bne $t0, $zero, overthere # branch if t1 < t2 for loop nasil gerceklenir Sonraki slide larda uc ornek Diger sekiller de mevcut (Note: $zero is a register that always = 0) 12/3/2004 Bilgisayar Mimarisi 9.15 12/3/2004 Bilgisayar Mimarisi 9.16

for (i=5; i>0; i++) { } for(i=0; i<5; i++) { } ntm:.word 5 # number of times to loop ntm:.word 5 # number of times to loop lw $t1, ntm # Start index at 5 loop: do stuff do stuff addi $t1,-1 # decrement index bne $t1,$zero,loop # loop til index is 0 lw $t0, ntm # Max loop value to t0 add $t1,$zero,$zero # clear index loop: do stuff do stuff addi $t1,1 # increment index slt $t2, $t1, $t0 # t2=1 if index < max bne $t2,$zero,loop # loop while index < max 12/3/2004 Bilgisayar Mimarisi 9.17 12/3/2004 Bilgisayar Mimarisi 9.18 for (i=0; i<5; i++) { } use BLT pseudoinstruction ntm:.word 5 # number of times to loop lw $t0, ntm # Max loop value to t0 add $t1,$zero,$zero # clear index loop: do stuff do stuff addi $t1,1 # increment index blt $t1, $t0, loop # loop while index < max 12/3/2004 Bilgisayar Mimarisi 9.19 Non-MIPS loop-control instructions Cok yaygin olduklarindan bazi hardware ler tarafindan gerceklenir Iki ornek sob R0, loop Substract one and branch PDP-11 family bc loop Branch conditional loop Power Pc ozel bir loop register a sahip 12/3/2004 Bilgisayar Mimarisi 9.20

MIPS branching instructions H&P pages A-61 A-65 Pseudoinstructions Assembler language instructions, fakat hardware tarafindan taninmazlar (hardware direkt execute edemez) Assembler hardware in direkt execute edebilecegi bir veya bir kac instruction a cevirir Code yazimini kolaylastirir Kodlamayi daha genel hale getirir Hardware i expand etmeksizin instruction set expand edilir 12/3/2004 Bilgisayar Mimarisi 9.21 12/3/2004 Bilgisayar Mimarisi 9.22 Pseudoinstruction Translates into move $t0, $t1 add $t0, $t1,$zero blt $t0, $t1, label slt $t2, $t0, $t1 bne $t2, $zero, label li $t0, 23 addi $t0, $zero, 23 Pseudoinstruction lar gercek machinelevel instruction lar degil Kismi high-level language Hardware i degerlendirmede kullanilamazlar SPIM simulator hangi instruction lara donusturulduklerini gosterir 12/3/2004 Bilgisayar Mimarisi 9.23 12/3/2004 Bilgisayar Mimarisi 9.24

Registers - reality and conventions Butun register lar fiziksel olarak ayni Sadece $zero daima 0 icerir ve degistirilemez Kullanim sekli: Belli registerlar belli seyler icin kullanilir ve isimleri yaptiklari islere gore verilir 12/3/2004 Bilgisayar Mimarisi 9.25 MIPS register kullanim kurallari $zero 0 constant 0 $at 1 reserved for assembler $v0-$v1 2-3 results from functions $a0-$a3 4-7 saved registers, arguments $t0-$t7 8-15 temporary registers $s0-$s7 16-23 saved registers $t8-$t9 24-25 more temporary registers $k0-$k1 26-27 reserved for op sys $gp 28 global pointer $sp 29 stack pointer $fp 30 frame pointer $ra 31 return address 12/3/2004 Bilgisayar Mimarisi 9.26 Neyi bilmemiz gerekir Subroutine call nasil olur Subroutine nasil jump edilir How to jump to the subroutine Subroutine argument ler nasil gecirilir Subroutine den sonuclar nasil geri dondurulur Subroutine den geri nasil donulur Register lar nasil save edilir stack nasil calisir Last-In-First-Out storage (LIFO) Empty: Stack Pointer (SP) belli bir mem location a point eder Push: SP yi bir azalt, data yi SP nin point ettigi memory location ina yaz Pop: Data yi SP nin point ettigi bellek gozunden oku ve SP yi bir artir Bu is icin MIPS $sp adinda ozel bir register a sahip 12/3/2004 Bilgisayar Mimarisi 9.27 12/3/2004 Bilgisayar Mimarisi 9.28

100 104 Empty 108 SP -- > 112 116 Push 19 100 SP -- > 104 108 112 116 Operation of a stack 19 17 Push 17 100 104 SP -- > 108 112 116 Pop 100 104 SP -- > 108 112 116 17 17 12/3/2004 Bilgisayar Mimarisi 9.29 subroutine calls Arguments in $a0-3 Results in $v0-1 leaf fonksiyonlarda (diger fonksiyonlara cagri yapmayan) $t0-$t7 yi save-restore etmeye gerek yok Diger register lar fonksiyon cagriminda save edilir, fonksiyondan donusten hemen once ise restore edilir 12/3/2004 Bilgisayar Mimarisi 9.30 subroutine calls non-leaf function (diger fonksiyonlara cagri yapan) $t0-$t7 yi cagrilan fonksiyon icin save edilmeye gerek olmayan temporary variable lar icin kullan $s0-$s7 yi cagrilan fonksiyonda kullanilan degerler icin kullan $s0-$s7 cagrilan fonksiyonda degistirilecekse bunlari save et $sp tarafindan point edilen memory alanina register lari save et, local variable lari allocate et MIPS subroutine calls Jump and Link instruction (jal) Ornek: jal MySub Bir sonraki instruction in address i (PC+4) return address, return address ($ra) registerine save sedilir J formatinda, 26 bit lik address alanina sahip 12/3/2004 Bilgisayar Mimarisi 9.31 12/3/2004 Bilgisayar Mimarisi 9.32

MIPS subroutine return Jump register instruction (jr) Ornek jr $ra Address i $ra registerinde olan instruction a jump et. R formata sahip (memory address kismi yok) Eger MIPS code subroutine cagrimi yapmiyorsa Code u main label i ile baslat Code u ozel bir instruction ile sonlamaya gerek yok (veya jr $ra ile SPIM e geri don) $t0-$t9 haricinde bir register kullanmazsaniz, save islemi yapmaniza gerek yok 12/3/2004 Bilgisayar Mimarisi 9.33 12/3/2004 Bilgisayar Mimarisi 9.34 Eger kendi subroutinimizi cagriyorsak $ra register i SPIM e geri donus address ini tutar. Bizim fonksiyon cagriliz $ra nin icerigini degistirecek (SPIM e geri donus address ini yok edecek). Bu yuzden bizim subroutinimizi cagirmadan once satack e $ra push edilmeli ve SPIM e geri donulmeden once de push edilen geri donus addresi pop edilip $ra ya yazilmali 12/3/2004 Bilgisayar Mimarisi 9.35 Form to preserve proper return to SPIM.text # Program block starts here main: subu $sp,$sp,4 # Push return address on stack sw $ra, 0($sp) # since we will modify ra ###### Your code here, including jal MySub ###### lw $ra,0($sp) # Restore main's return address addi $sp,4 # Restore the stack pointer jr $ra # Return to Spim simulator ########## MySub here, in same source file 12/3/2004 Bilgisayar Mimarisi 9.36