Assembly language: arithmetic and load/store instructions Ellen Spertus MCS 111 September 17, 2002.

Slides:



Advertisements
Similar presentations
Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Advertisements

Goal: Write Programs in Assembly
Instruction Set-Intro
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
SPIM and MIPS programming
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
Chapter 2.
© 2010 Kettering University, All rights reserved..
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
ECE 4436ECE 5367 ISA I. ECE 4436ECE 5367 CPU = Seconds= Instructions x Cycles x Seconds Time Program Program Instruction Cycle CPU = Seconds= Instructions.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
MIPS assembly. Computer What’s in a computer? Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Instruction Set Architecture Basics. Our Progress Done with levels 0 and 1 Seen multiple examples of level 2 Ready for ISA general principles.
Lecture 4: MIPS Instruction Set Reminders: –Homework #1 posted: due next Wed. –Midterm #1 scheduled Friday September 26 th, 2014 Location: TODD 430 –Midterm.
Lecture 8. MIPS Instructions #2 – Memory Access (Load/Store) Instructions Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Lecture 4. MIPS Instructions #2 Memory Access (Load/Store) Instructions Prof. Taeweon Suh Computer Science Education Korea University ECM534 Advanced Computer.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
Computer Architecture CSE 3322 Lecture 2 NO CLASS MON Sept 1 Course WEB SITE crystal.uta.edu/~jpatters.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Ellen Spertus MCS 111 October 16, 2001 Review. 2 What you will learn this semester Given devices that implement simple boolean functions… Understand how.
1 The Instruction Set Architecture September 27 th, 2007 By: Corbin Johnson CS 146.
More Intro MIPS Computer Organization I 1 September 2009 © McQuain, Feng & Ribbens Machine Language But, how is all of this driven? Machine.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
Computer Organization Instructions Language of The Computer (MIPS) 2.
MIPS assembly. Computer  What’s in a computer?  Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
Address alignment When a word (4-bytes) is loaded or stored the memory address must be a multiple of four. This is called an alignment restriction. Addresses.
Computer Operation. Binary Codes CPU operates in binary codes Representation of values in binary codes Instructions to CPU in binary codes Addresses in.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Full Adders Vector Notation Multiplexers and Decoders Ellen Spertus MCS 111 September 6, 2001.
Computer Architecture & Operations I
Computer Architecture & Operations I
MIPS Assembly.
CS/COE 0447 (term 2181) Jarrett Billingsley
Lecture 6: Assembly Programs
Instruction Set Architecture
Prof. Sirer CS 316 Cornell University
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
MIPS Assembly.
CSCI206 - Computer Organization & Programming
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Computer Programming Machine and Assembly.
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
The University of Adelaide, School of Computer Science
Systems Architecture Lecture 5: MIPS Instruction Set
MIPS assembly.
The University of Adelaide, School of Computer Science
Computer Instructions
Computer Architecture
September 17 Test 1 pre(re)view Fang-Yi will demonstrate Spim
3.
Instruction encoding The ISA defines Format = Encoding
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
CPU Structure CPU must:
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
9/27: Lecture Topics Memory Data transfer instructions
Presentation transcript:

Assembly language: arithmetic and load/store instructions Ellen Spertus MCS 111 September 17, 2002

2 Big picture

3 The role of assembly language Every instruction in a high-level programming language (such as Java) is converted into several assembly instructions. A program called an assembler converts each assembly instruction to a machine instruction. The hardware “knows how to” run machine instructions.

4 Review: hardware Flip-flops (aka registers) –Can remember its old input –Can remember a new input Multiplexers –Choose one of many inputs Selector –Select one of many outputs

5 Instruction execution

6 Addition add $s1, $s2, $s3 –Meaning: $s1 = $s2 + $s3 –Operation: add –Operands: $s1, $s2, $s3 –Exactly three operands –Each operand must be a register

7 Translating Java code int a; int b; int c; a = b + c; a: $s1 b: $s2 c: $s3

8 A closer look at registers The MIPS architecture has 32 registers Each register is bits wide Registers corresponding to Java variables are called $s0, $s1,... Registers corresponding to temporary (unnamed) values are called $t0, $t1,...

9 Converting complex instructions a = b + c + d; add $t0, $s2, $s3 add $s1, $t0, $s4 a: $s1 b: $s2 c: $s3 d: $s4

10 Practice b = b + c + a; a: $s1 b: $s2 c: $s3

11 Subtraction sub $s1, $s2, $s3 –Meaning: $s1 = $s2 - $s3 –Operation: sub –Operands: $s1, $s2, $s3 –Exactly three operands –Each operand must be a register

12 Practice a = a - (b + d); a: $s1 b: $s2 c: $s3 d: $s4

13 Practice a = b - c - (a + d); a: $s1 b: $s2 c: $s3 d: $s4

14 Translation steps Java code: a = b + c Assembly code: add $s1, $s2, $s3 Machine code:

15 The need for more memory Why aren’t 32 registers enough memory for a modern computer?

16

17 Main memory How big?

18 Load/store instructions Purpose: Transfer data between registers and memory Load instructions –lb: load byte –lw: load word Store instructions –sb: store byte –sw: store word

19 Load-byte instruction Transfer data from memory to a register Load-byte: lb –Format:lb $ra, i($rb) –Example: lb $t2, 2($t0) –Meaning: Take the value in memory location (2+$t0) and put it in $t2 Note: i stands for immediate

20 Example: lb and sb count sum sum = sum + count; Assume $t0 = 0 lb $t2, 2($t0) lb $t1, 1($t0) add $t1, $t1, $t2 sb $t1, 1($t0) 8 bits

21 Bytes and words } one byte one word (4 bytes) 8 bits

22 How to combine bytes into word Little-endian –The “little end” (least significant byte) is stored first in memory. –Used by Intel Big-endian –The “big end” (most significant byte) is stored first in memory. –Used by MIPS, Motorola

23 Bytes and words } one byte one word (4 bytes) 8 bits

24 Word example count sum sum = sum + count; Assume $t0 = 0 lw $t2, _($t0) lw $t1, _($t0) add $t1, $t1, $t2 sw $t1, _($t0)

25 Summary: levels of languages People like to program in high-level languages, such as Java. The hardware knows how to run low- level machine code. High-level code is converted into machine language by compilers, assemblers, and students.

26 Summary: assembly language The add and sub operations act on registers. The load and store operations transfer data between memory and registers. How to order bytes within a word? –Little-endian –Big-endian –Bi-endian or “byte-sexual”

27

28 “His Majesty desired I would take some other opportunity of bringing all the rest of his enemy's ships into his ports. And so unmeasurable is the ambition of princes, that he seemed to think of nothing less than reducing the whole empire of Blefuscu into a province, and governing it by a Viceroy; of destroying the Big-Endian exiles, and compelling that people to break the smaller end of their eggs, by which he would remain the sole monarch of the whole world.” — Gulliver’s Travels by Jonathan Swift