Data in Memory variables have multiple attributes symbolic name

Slides:



Advertisements
Similar presentations
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Advertisements

Optimizing ARM Assembly Computer Organization and Assembly Languages Yung-Yu Chuang with slides by Peng-Sheng Chen.
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
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
I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
MIPS Assembly Language Programming
1 Computer Architecture MIPS Simulator and Assembly language.
Data in Memory variables have multiple attributes symbolic name data type (perhaps with qualifier) allocated in data area, stack, or heap duration (lifetime.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
What is an instruction set?
Microprocessor Systems Design I
CSC 3210 Computer Organization and Programming Chapter 9 EXTERNAL DATA AND TEXT D.M. Rasanjalee Himali.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
Derived from "x86 Assembly Registers and the Stack" by Rodney BeedeRodney Beede x86 Assembly Registers and the Stack Nov 2009.
Computer Architecture and Organization
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Computer Architecture EKT 422
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. 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.
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.
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.
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.
Precept 7: Introduction to IA-32 Assembly Language Programming
Instruction Set Architecture
Computer Architecture and Assembly Language
Assembly language.
Credits and Disclaimers
Chapter 12 Variables and Operators
Homework Reading Machine Projects Labs PAL, pp ,
Chapter7 Structure & C++
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 24: Compiler, Assembler, Linker and Loader – I
Chapter 3 Bit Operations
Computer Organization and Assembly Language (COAL)
Instruction Set Architectures
THE sic mACHINE CSCI/CMPE 3334 David Egle.
Ken D. Nguyen Department of Computer Science Georgia State University
Machine-Level Programming 6 Structured Data
Computer Organization and ASSEMBLY LANGUAGE
ARM Memory.
Assembly Language Programming II: C Compiler Calling Sequences
ECEG-3202 Computer Architecture and Organization
Computer Architecture
Bits and Bytes Topics Representing information as bits
Chapter 9 Instruction Sets: Characteristics and Functions
William Stallings Computer Organization and Architecture 8 th Edition Chapter 10 (Chap 12 edition 9) Instruction Sets: Characteristics and Functions.
Computer Instructions
ECEG-3202 Computer Architecture and Organization
Introduction to Microprocessor Programming
Optimizing ARM Assembly
Comp Org & Assembly Lang
ARM Memory.
Computer Architecture and System Programming Laboratory
Ken D. Nguyen Department of Computer Science Georgia State University
Credits and Disclaimers
Introduction to Assembly Chapter 2
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
An Introduction to the ARM CORTEX M0+ Instructions
Chapter 10 Instruction Sets: Characteristics and Functions
The ‘asm’ construct An introduction to the GNU C/C++ compiler’s obscure syntax for doing inline assembly language.
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 in Memory 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 data sizes 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; } 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) = 4 sizeof(long) = 8

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

Alignment in byte-addressable memory example: aligned load/store of word at address 0 ||||||||||||||||||||||||||||||||||| memory ... =BYTE=0= =BYTE=1= =BYTE=2= =BYTE=3= CPU register: <<<<<<<<<one trip across the bus>>>>>>>>> word 0: =BYTE=0= =BYTE=1= =BYTE=2= =BYTE=3= word 4: byte 4 byte 5 byte 6 byte 7 word 8: byte 8 byte 9 byte a byte b

Alignment in byte-addressable memory example: unaligned load/store of word at address 2 \\\\\\\\\\\\\\\\\\\\|///////////////////// ||||||||| shift network ||||||||| /////////////////////|\\\\\\\\\\\\\\\\\\\\\ memory ... =BYTE=2= =BYTE=3= =BYTE=4= =BYTE=5= CPU register: <<<<<<<<<two trips across the bus>>>>>>>>> word 0: byte 0 byte 1 =BYTE=2= =BYTE=3= word 4: =byte 4= =byte 5= byte 6 byte 7 word 8: byte 8 byte 9 byte a byte b

Data in Memory unaligned access: may be illegal (SPARC system prints "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 to avoid unaligned accesses the compiler can sometimes reorder or pad data structures

Data in Memory you can use the .align pseudo-op in your programs (esp. when you have a word variable allocated after a character string) .asciz "..." (or defensive programming practice will .align 4 always allocate doublewords first, then .word ... words, then halfwords, then strings) 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 -- see examples beginning on slide 13) most processors today have added hardware to support unaligned operands

Data in Memory byte numbering how are bytes within a multiple byte structure numbered? big-endian => byte 0 is most significant = left-to-right … little-endian => byte 0 is least significant = positional representation word 0: byte 0 byte 1 byte 2 byte 3 word 4: byte 4 byte 5 byte 6 byte 7 byte 7 byte 6 byte 5 byte 4 :word 4 byte 3 byte 2 byte 1 byte 0 :word 0

Data in Memory byte numbering examples character string "abcdef" in C (null-terminated) 100 101 102 103 104 105 106 there is no difference in addresses for a character string between big-endian and little-endian 100 101 102 103 104 105 106 big-endian 'a' 'b' 'c' 'd' 'e' 'f' 0 little-endian 'a' 'b' 'c' 'd' 'e' 'f' 0 'a' 'b' 'c' 'd' 'e' 'f'

Unaligned Access Examples example generated code for unaligned access within packed struct #include<stdio.h> struct c_and_i { char x[5]; int y; } __attribute__ (( packed )) test; int main() printf("%p %p\n",&(test.x),&(test.y)); test.y = 1; return 0; }

Unaligned Access Examples ARM - .file "align.c" .comm test,9,4 .section .rodata .align 2 .LC0: .ascii "%p %p\012\000" .text .global main .type main, %function

Unaligned Access Example (ARM cont'd) main: stmfd sp!, {fp, lr} add fp, sp, #4 ldr r0, .L3 // address of format string in r0 ldr r1, .L3+4 // address of x in r1 ldr r2, .L3+8 // address of y in r2 bl printf // printf ldr r3, .L3+4 // address of x in r3 ldr r2, [r3, #4] // start of unaligned access and r2, r2, #255 orr r2, r2, #256 str r2, [r3, #4] mov r2, #0 strb r2, [r3, #8] // end of unaligned access mov r3, #0 mov r0, r3 ldmfd sp!, {fp, pc}

Unaligned Access Example (ARM cont'd) .L4: .align 2 .L3: .word .LC0 .word test .word test+5 .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.7.3-12ubuntu1) 4.7.3"

Unaligned Access Example (X86) x86 - uses single movl to access unaligned word .file "align.c" .version "01.01" .section .rodata .LC0: .string "%p %p\n" .text .globl main .type main, @function

Unaligned Access Example (X86 cont'd) main: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp movl $0, %eax addl $15, %eax shrl $4, %eax sall $4, %eax subl %eax, %esp subl $4, %esp pushl $test+5 pushl $test pushl $.LC0 call printf addl $16, %esp

Unaligned Access Example (X86 cont'd) movl $1, test+5 // unaligned access movl $0, %eax leave ret .size main, .-main .comm test,9,1 .ident "GCC: (GNU) 3.4.1"