Data in Memory variables have multiple attributes symbolic name data type (perhaps with qualifier) allocated in data area, stack, or heap duration (lifetime.

Slides:



Advertisements
Similar presentations
1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
Advertisements

INSTRUCTION SET ARCHITECTURES
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 7, 2012 CSCE 212Honors Computer Organization.
SPARC Architecture & Assembly Language
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
Microprocessors General Features To be Examined For Each Chip Jan 24 th, 2002.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Boolean Algebra Discrete Mathematics and Its Applications Baojian Hua
What is an instruction set?
Microprocessor Systems Design I
ARM C Language & Assembler. Using C instead of Java (or Python, or your other favorite language)? C is the de facto standard for embedded systems because.
CSE378 MIPS ISA1 MIPS History MIPS is a computer family –R2000/R3000 (32-bit); R4000/4400 (64-bit); R8000; R10000 (64-bit) etc. MIPS originated as a Stanford.
Data Types in the Kernel Sarah Diesburg COP 5641.
CSC 3210 Computer Organization and Programming Chapter 9 EXTERNAL DATA AND TEXT D.M. Rasanjalee Himali.
Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages.
4-1 Chapter 4 - The Instruction Set Architecture Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring.
Instruction Set Architecture
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
CMPE 511 Computer Architecture A Faster Optimal Register Allocator Betül Demiröz.
Natawut NupairojAssembly Language1 Memory and Stack.
Derived from "x86 Assembly Registers and the Stack" by Rodney BeedeRodney Beede x86 Assembly Registers and the Stack Nov 2009.
November 18, 2015Memory and Pointers in Assembly1 What does this C code do? int foo(char *s) { int L = 0; while (*s++) { ++L; } return L; }
Computer Architecture and Organization
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Computer Architecture EKT 422
ARM (Advanced RISC Machine; initially Acorn RISC Machine) Load/store architecture 65 instructions (all fixed length – one word each = 32 bits) 16 registers.
Info stored in computer (memory) Numbers All in binaray – can be converted to octal, hex Characters ASCII – 1-byte/char Unicode – 2-byte/char Unicode-table.com/en.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Dr Mohamed Menacer College of Computer Science and Engineering, Taibah University CE-321: Computer.
What is a program? A sequence of steps
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
Group # 3 Jorge Chavez Henry Diaz Janty Ghazi German Montenegro.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
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.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
Writing Functions in Assembly
Instruction Set Architecture
Data in Memory variables have multiple attributes symbolic name
Assembly language.
Basics Of X86 Architecture
Writing Functions in Assembly
Ken D. Nguyen Department of Computer Science Georgia State University
The University of Adelaide, School of Computer Science
Architecture CH006.
Assembly Language Programming II: C Compiler Calling Sequences
ECEG-3202 Computer Architecture and Organization
Chapter 9 Instruction Sets: Characteristics and Functions
ECEG-3202 Computer Architecture and Organization
Introduction to Microprocessor Programming
Optimizing ARM Assembly
Comp Org & Assembly Lang
Ken D. Nguyen Department of Computer Science Georgia State University
Computer Architecture and System Programming Laboratory
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Data in Memory variables have multiple attributes symbolic name data type (perhaps with qualifier) allocated in data area, stack, or heap duration (lifetime or extent) scope (visibility of the variable name) linkage (may have been allocated elsewhere) address in memory (none if only allocated in register) alignment byte order for multibyte variables initialization (optional) current value storage class variable

Data in Memory simple data types are: char, int, float, double (C uses the keyword void to denote untyped) qualifiers: signed, unsigned, long, short, volatile (compilers sometimes ignore "long", "short") ("volatile" is used to suppress optimizations) data sizes byte - 8 bits = 1 byte - character halfword - 16 bits = 2 bytes - short integer word - 32 bits = 4 bytes - integer, long integer in 32-bit model doubleword - 64 bits = 8 bytes - double, long integer in 64-bit model

Data in Memory int main(){ printf("sizeof(char) = %d\n",sizeof(char)); printf("sizeof(short) = %d\n",sizeof(short)); printf("sizeof(int) = %d\n",sizeof(int)); printf("sizeof(long) = %d\n",sizeof(long)); return 0; } On a CS machine: compile with just gcc compile with "gcc -m64" sizeof(char) = 1 sizeof(char) = 1 sizeof(short) = 2 sizeof(short) = 2 sizeof(int) = 4 sizeof(int) = 4 sizeof(long) = 8 sizeof(long) = 8

Data in Memory Alignment in byte-addressable memory memory access is typically on word-by-word basis (aligned) (original meaning of "memory word" was the unit of transfer to/from memory) alignment restrictions on load/store instructions prevent multiple-byte units from spanning across two memory words, thus allowing individual load or store instructions to make one and only one memory access -- which makes hardware easier to build

Data in Memory... =BYTE=0==BYTE=1==BYTE=2==BYTE=3= | | | | | | | | | | | | | | | | >>>>>>>>>>>>>>>>> | | | | | | | | | | | | | | | | =BYTE=0==BYTE=1==BYTE=2==BYTE=3= byte 4byte 5byte 6byte 7 byte 8byte 9byte abyte b memory Access this word word 0: word 4: word 8:

Data in Memory example: unaligned load/store of word at address 2 =BYTE=2==BYTE=3==BYTE=4==BYTE=5= \\\\\\\\\\\\\\\\\\\\\|///////////////////// |||||||||| shift network ||||||||||||| /////////////////////|\\\\\\\\\\\\\\\\\\\\\ >>>>>>>>>>>>>>>> byte 0byte 1=BYTE=2==BYTE=3= =BYTE=4==BYTE=5=byte 6byte 7 byte 8byte 9byte abyte b memory word 0: CPU register | | | | | | | | | | | | | | | | word 4: word 8:...

Data in Memory unaligned access: may be illegal (system may print "Bus error (core dumped)") may cause a trap into the operating system, or, requires extra shifting network hardware and extra time to perform two memory accesses and the necessary insertion of bytes (i.e., to merge bytes from two memory words into the single-word-length CPU register on a load, or to distribute the bytes from a register into two different memory words on a store)

Data in Memory Alignment rules: bytes can start anywhere halfwords start on a halfword boundary = address divisible by 2 words start on a word boundary = address divisible by 4 doublewords start on a doubleword boundary = address divisible by 8

Data in Memory Alignment: to avoid unaligned accesses the compiler can sometimes reorder or pad data structures You can use the.align pseudo-op in your programs (esp. when you have a word word variable allocated after a character string).asciz “...” (or defensive programming practice.align 4 will always allocate doublewords first,.word... then words, then halfwords, then strings)

Data in Memory Alignment: However, in some languages (e.g., FORTRAN, COBOL), unaligned accesses must still be legal for programs, so the operating system on an aligned memory processor must include an unaligned trap handler (or the compiler must generate extra code). Most processors today have added hardware to support unaligned operands

Data in Memory Depending on which computing system you use, you will have to consider the byte order in which multibyte numbers are stored, particularly when writing those numbers to a file. The two orders are called "Little Endian" and "Big Endian". Endianness is important as a low-level attribute of a particular data format. Failure to account for varying endianness across architectures when writing software code for mixed platforms and when exchanging certain types of data might lead to failures and bugs.bugs These issues have been understood and properly handled for many decades.

Data in Memory Byte ordering: (pp. 71 – 72 in the 1 st ed., 91 – 92 in the 2 nd ) how are bytes within a multiple byte structure ordered? big-endian => byte 0 is most significant = left-to-right byte 0byte 1byte 2byte 3 byte 4byte 5byte 6byte 7 word 0: word 4:... byte 7byte 6byte 5byte 4 byte 3byte 2byte 1byte 0 word 0: word 4:... little-endian => byte 0 is least significant = positional representation

Data in Memory Byte ordering (cont’d): If a big-endian computer sends word 0x89abcdef as bytes 0x89, 0xab, …, then, without conversion, a little-endian computer will receive these bytes and assemble them as 0xefcdab89 Example: 16-bit halfword with value 0xabcd at address 0x100 little-endianbig-endian cdab cd

Data in Memory Byte numbering (cont’d): Example: 32-bit word with value 0x1234 at address 0x100 little-endian big-endian

Data in Memory Byte numbering (cont’d): Example: character string “abcdef” in C (null-terminated) little-endian big-endian There is no difference in addresses for a character string between big-endian and little-endian. ‘a’‘b’‘c’‘d’‘e’‘f’ ‘a’‘b’‘c’‘d’‘e’‘f’0

Example generated code for unaligned access within packed struct ARM -.file “align.c” section.rodata.align 2.LC0:.ascii "%p %p\012\000".text.align 2.global main.type main, %function args = 0, pretend = 0, frame = frame_needed = 1, uses_anonymous_args = 0 push {r7, lr} add r7, sp, #0 movw r3, #:lower16:.LC0 movt r3, #:upper16:.LC0

Example generated code for unaligned access within packed struct ARM - mov r0, r3 movw r1, #:lower16:test movt r1, #:upper16:test ldr r2,.L2 bl printf movw r3, #:lower16:test movt r3, #:upper16:test ldr r2, [r3, #4] uxtb r2, r2 orr r2, r2, #256 str r2, [r3, #4] mov r2, #0

Example generated code for unaligned access within packed struct ARM - strb r2, [r3, #8] mov r3, #0 mov r0, r3 pop {r7, pc}.L3:.align 2.L2:.word test+5.size main,.-main.ident "GCC: (Ubuntu/Linaro ubuntu5) 4.6.3"

Example generated code for unaligned access within packed struct SPARC - uses multiple load/store bytes to accomplish access to unaligned word.file"align.c".section".rodata".align 8.LLC0:.asciz"%p %p\n".section".text".align 4.global main.typemain, #function.proc04 main: !#PROLOGUE# 0 save%sp, -112, %sp

Example generated code for unaligned access within packed struct SPARC - !#PROLOGUE# 1 sethi%hi(.LLC0), %g1 or%g1, %lo(.LLC0), %o0 sethi%hi(test), %g1 or%g1, %lo(test), %o1 sethi%hi(test+5), %g1 or%g1, %lo(test+5), %o2 callprintf, 0 nop sethi%hi(test), %g1 or%g1, %lo(test), %o5 ldub[%o5+5], %g1 // start of unaligned access and%g1, 0, %g1 // stb%g1, [%o5+5] // ldub[%o5+6], %g1 // accesses individual bytes, and%g1, 0, %g1 // so four ldub/stb pairs stb%g1, [%o5+6] // instead of a single st

Example generated code for unaligned access within packed struct SPARC - ldub[%o5+7], %g1 // and%g1, 0, %g1 // stb%g1, [%o5+7] // ldub[%o5+8], %g1 // and%g1, 0, %g1 // or%g1, 1, %g1 // stb%g1, [%o5+8] // end of unaligned access mov0, %g1 mov%g1, %i0 ret restore.sizemain,.-main.commontest,9,1 // 9-byte struct, 1-byte // boundary.ident"GCC: (GNU) 3.4.1"

Example generated code for unaligned access within packed struct x86 - uses single movl to access unaligned word.file"align.c".version"01.01".section.rodata.LC0:.string"%p %p\n".text.globl main: pushl%ebp movl%esp, %ebp subl$8, %esp andl$-16, %esp movl$0, %eax addl$15, %eax

Example generated code for unaligned access within packed struct x86 – shrl$4, %eax sall$4, %eax subl%eax, %esp subl$4, %esp pushl$test+5 pushl$test pushl$.LC0 callprintf addl$16, %esp movl$1, test+5 // unaligned access movl$0, %eax leave ret.sizemain,.-main.commtest,9,1.ident"GCC: (GNU) 3.4.1"