Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University. March 12, Xuan Guo

Similar documents
Xuan Guo. Lecture XIX: Subroutines (2) CSC 3210 Computer Organization and Programming Georgia State University. March 31, 2015.

Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University. March 31, Lecture XX: Subroutines (3) Xuan Guo

Lecture V: Register and SPARC Assembly Language Programming. Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University

Lecture VII: The debugger gdb and Branching. Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University.

CSE 30 Spring 2006 Final Exam

231 Spring Final Exam Name:

CSE 30 Spring 2007 Final Exam

CSE 30 Fall 2013 Final Exam

CSE 30 Fall 2012 Final Exam

CSE 30 Fall 2007 Final Exam

Lecture VIII: Branching and Control Statements. Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University.

CSE 30 Winter 2014 Final Exam

Lecture XXIV: Review Xuan Guo CSC 3210 Computer Organization and Programming Georgia State University April 23, 2015 Xuan Guo Lecture XXIV: Review

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Chapter 5 Data Organization: The Load and Store Instructions

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Lecture XXI: I/O (1) Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University. April 7, Xuan Guo. Lecture XXI: I/O (1)

231 Spring Final Exam Name:

17. Instruction Sets: Characteristics and Functions

CSE 30 Fall 2006 Final Exam

Compiler Design. Homework 1. Due Date: Thursday, January 19, 2006, 2:00

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

CSE 30 Winter 2009 Final Exam

Practical Malware Analysis

Procedure Call. Procedure Call CS 217. Involves following actions

Final CSE 131 Fall 2014

EECE416 :Microcomputer Fundamentals and Design. X86 Assembly Programming Part 1. Dr. Charles Kim

Expectations. Why learn Assembly Language? Administrative Issues. Assignments. CSC 3210 Computer Organization and Programming

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

Instruction Sets: Characteristics and Functions

ECE331: Hardware Organization and Design

Mark II Aiken Relay Calculator

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

MIPS Functions and the Runtime Stack

Course Administration

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

Chapter 2 SPARC Architecture Chinua Umoja

Communicating with People (2.8)

Xuan Guo. Lecture XIV: Review of Chapter 3 & 4. CSC 3210 Computer Organization and Programming Georgia State University. March 5, 2015.

1. Introduction to Assembly Language

Reverse Engineering II: The Basics

CS 270 Systems Programming. Debugging Tools. CS 270: Systems Programming. Instructor: Raphael Finkel

Chapter Two MIPS Arithmetic

Declaring Floating Point Data

Computer Organization MIPS ISA

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

CS241 Computer Organization Spring 2015 IA

CPSC 213. Introduction to Computer Systems. Static Scalars and Arrays. Unit 1b

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

Under the Hood: Data Representation. Computer Science 104 Lecture 2

Systems Architecture I

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

ECE232: Hardware Organization and Design

Chapter 2 Bits, Data Types, and Operations

CSE 220: System Fundamentals I Unit 14: MIPS Assembly: Multi-dimensional Arrays. Kevin McDonnell Stony Brook University CSE 220

Instruction encoding. MIPS Instruction encoding

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

Chapter 2: Instructions:

MIPS Assembly Language Programming

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

F28HS2 Hardware-Software Interfaces. Lecture 6: ARM Assembly Language 1

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

Assembler. Lecture 8 CS301

MIPS Assembly Language Programming

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux

Description of the Simulator

Cache Organizations for Multi-cores

3. Instruction Set Architecture The MIPS architecture

The PAW Architecture Reference Manual

Representation of Information

Chapter 2 Bits, Data Types, and Operations

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

CENG3420 Lecture 03 Review

A Processor! Hakim Weatherspoon CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 10 Instruction Sets: Characteristics and Functions

Basic Assembly SYSC-3006

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Computer Architecture 1 ح 303

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

Homework 2. Lecture 6: Machine Code. Instruction Formats for HW2. Two parts: How to do Homework 2!!!!

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Course Administration

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

Machine and Assembly Language Principles

CPS311 - COMPUTER ORGANIZATION. A bit of history

Tutorial 1: C-Language

Lecture 4: MIPS Instruction Set

Programming the ARM. Computer Design 2002, Lecture 4. Robert Mullins

CPSC 213, Winter 2009, Term 2 Midterm Exam Date: March 12, 2010; Instructor: Mike Feeley

Part 7. Stacks. Stack. Stack. Examples of Stacks. Stack Operation: Push. Piles of Data. The Stack

CS401 - Computer Architecture and Assembly Language Programming Glossary By

Computer Architecture and System Software Lecture 06: Assembly Language Programming

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

SPARC Architecture. SPARC Registers

Transcription:

CSC 3210 Computer Organization and Programming Georgia State University March 12, 2015 This lecture Plan for the lecture: Recap: Memory, The stack, The frame pointer Defining stack Variable Offsets Example gdb examine memory 1

Data types C Type SPARC Bits Unsigned Signed char byte 8 0, 255-128, 127 short half 16 0, 65,535-32,768, 32,767 int, long word 32 0, 4.294x10 9 2.147 x 10 9 All memory references must be aligned x byte quantities must begin in an address divisible by x Example int a, b; char c1; int c, d; //automatic variables int x, y, z; //use register for(z = 1; z < x+y;z++){ for(a = z; a>=z*y; a -= 10){ d = a + z; c1 = d * b; c = a + y/ z; } } 2

Memory Allocation and the Stack Automatic variables near top of memory = the Stack Stack has LIFO property Register %o6 holds the address of the last element placed on the stack = the stack pointer %sp More about the stack The stack grows downward to increase stack space, subtract from stack pointer sub %sp, 64, %sp 0x0000 The stack must be double word aligned %sp -> the stack Top of stack 0xf8000000 3

Chopping Aligning the Stack The address in %sp must be divisible by 8 Clear lowest three bits by using the and operation Add a chopped negative # to increase size add add %sp, -94 & 0xfffffff8, %sp %sp, -94 & -8, %sp Results in 96 being subtracted from %sp 4

The Frame Pointer The value for %sp is not constant So it is difficult to reference a variable s location by using %sp The frame pointer, %fp = %i6, stores a copy of %sp before it is changed The save instruction performs addition and updates %fp Example using %fp Want to add 92 extra bytes and store five 4- byte variables %sp: save %sp, (-92 (5*4))) & -8, %sp 92 extra bytes a4: %fp-20: a3: %fp-16: a2: %fp-12: a1: %fp-8: a0: %fp-4: 5

Addressing Variables Load and Store operations are the only instructions that reference memory Both instructions take two operands One memory location, and one register Can access memory using different data types (byte, half word, word, double word) Load Instructions Mnemonic ldsb ldub ldsh lduh ld ldd Operation Load signed byte, propagate sign left in register Load unsigned byte, clear high 24 bits of register Load signed halfword, propogate sign left in register Load unsigned halfword, clear high 16 bits of register Load word Load double, reg. # even, first 4 bytes into reg. n, next 4 into reg. n + 1 6

Load Instruction Format ld [memory location], reg rd ld [%fp 4], %l1!a0 into %l1 ld [%fp 8], %l2!a1 into %l2 ld [%fp 16], %l4!a3 into %l4 Note: Memory location argument can be a register, register + immediate, or register + register Store Instructions Mnemonic stb sth st std Operation Store low byte of register, bits 0-7, into memory Store low two bytes of register, bits 0-15 into memory Store register Store double, reg. # even, first 4 bytes from reg. n, next 4 from reg. n + 1 st reg rs, [memory location] st %l1, [%fp 4]!%l1 into a0 7

Problems with Stack Variable Offsets Define the constants symbolically: define(a0_s, -4) ld [%fp + a0_s], %l1 define(a1_s, -8) ld [%fp + a1_s], %l2 define(a2_s, -12) ld [%fp + a2_s], %l3 but still have to compute the offsets a0_s = -4 a1_s = -8 a2_s = -12 a3_s = -16.global main main: save %sp, (-92 + -16 ) & -8, %sp ld [%fs + a0_s], %l1! evaluated by the assembler ld [%fs + a1_s], %l2 ld [%fs + a2_s], %l3 8

An Example Using Macros define(`local_var, `define(last_sym, 0) ) define(`var, `define(`last_sym, eval(last_sym-$2))$1 = last_sym ) local_var var(a0_s, 4)!a0_s = -4 var(a1_s, 4)!a1_s = -8.global main main: save %sp, (-92 + last_sym) & -8, %sp ld [%fp + a0_s], %l1 ld [%fp + a1_s], %l2 Data types C Type SPARC Bits Unsigned Signed char byte 8 0, 255-128, 127 short half 16 0, 65,535-32,768, 32,767 int, long word 32 0, 4.294x10 9 2.147 x 10 9 All memory references must be aligned x byte quantities must begin in an address divisible by x 9

But we still have problems local_var var(a_s, 4)!a_s = -4 var(b_s, 4)!b_s = -8 var(ch_s, 1)!ch_s = -9 var(c_s, 2)!c_s = -11 var(d_s, 4)!d_s = -15 ldsh [%fp + c_s], %o0! -11 ld [%fp + d_s], %o1! -15 Defining Stack Variable Offsets Define macros to compute the offsets and make the definitions define(local_var, `define(last_sym, 0) ') define(`var', `define(`last_sym', eval((last_sym - $2 & -$2)) $1 = last_sym') 10

Aligning Variables define(`var', `define(`last_sym', eval((last_sym - $2 & -$2)) $1 = last_sym') a_s = -4 b_s = -8 ch_s = -9 c_s = -12 d_s = -16 a_s = -4 b_s = -8 ch_s = -9 c_s = -11 d_s = -15 Aligning Variables %fp - 16 d a_s = -4 b_s = -8 ch_s = -9 c_s = -12 d_s = -16 %fp - 12 %fp - 9 %fp - 8 c ch b %fp - 4 a %fp 11

gdb examine memory the command x (for "examine") to examine memory in any of several formats independently of your program's data types. x/nfu addr n, the repeat count f, the display format `The default is `d' (decimal) initially `x' (hexadecimal) u, the unit size The unit size is any of b Bytes. h Halfwords (two bytes). w Words (four bytes). This is the initial default. g Giant words (eight bytes, double words). Example x/w $fp 4 x/b $fp - 5 Example int a; char ch; int b; int x, y; //memory //register x = 20; y = 30; a = x + y; b = x y; ch = a * b; 12

define(`local_var', `!local variables define(`last_sym', 0)') define(`var', `define(`last_sym', eval((last_sym - $2) & -$2)) $1 = last_sym') local_var var(a_s, 4) var(ch_s, 1) var(b_s, 4) define(x_r, l0) define(y_r, l1).global main main: save %sp, (-92 + last_sym) & -8, %sp mov 20, %x_r mov 30, %y_r add %x_r, %y_r, %o0 st %o0, [%fp + a_s] sub %x_r, %y_r, %o0 st %o0, [%fp + b_s] ld [%fp + a_s], %o0 ld [%fp + b_s], %o1 call.mul nop stb %o0, [%fp + ch_s] result: mov 1, %g1 ta 0 int a; char ch; int b; int x, y; x = 20; y = 30; a = x + y; b = x y; ch = a * b; 13