Download presentation
Presentation is loading. Please wait.
Published byRoger Hill Modified over 9 years ago
1
Working With Main Memory
2
Why Main Memory Register space limited Used for communication
3
Sections of Code.data section Things to place into memory at start.text section Code Any order, can have multiple.text/.data segments
4
Defining Memory Memory described as words/bytes/asciiz, etc… Hex: Ascii
5
Endianess Endianess : bytes order of a word in main memory
6
Little vs Big Endian Big is "Normal": Little weird – Words in order – Bytes in a word backwards
7
Integers Normal… Both endians store words (integers) same way – Disagree about how bytes are numbered +0+1+2+3 +2+1+0
8
Single Byte Structures Agree on address of single byte structures – Just look different +0+1+2+3 +2+1+0
9
Endian MARS is little endian: – Bytes/strings look goofy – Words (integers) unaffected
10
Why? Little Endian – Read different sized value at same address Big Endian – Easier to read hex – Reading start of word gives sign/magnitude
11
Base Register Data starts in defined location – 0x1001000 for MARS – 0x1000000 for reading simulator
12
Finding Memory Memory reference consist of offset(base) – base address : start here – offset : Go forward this many bytes 6(0x1001000) 32107654
13
Arrays C++ Array – Base address – Offset : number of elements int quiz[3]; quiz[1] = 5;
14
Load Word / Store Word Memory access – lw : get word from memory – put in register – sw : put register value into memory lw $targetRegister, offset($baseAddressRegister) lw $9, 12($8) – Start from address in register $8 Should have 0x1001000 – Move over 16 bytes from there – Read a word into $9
15
LUI & Base Register lw $9, 12($8) Need address of.text section (0x10010000) in register Could do: ori $8, $0, 0x1001 sll $8, $8, 16
16
LUI & Base Register lui : load upper immediate – Place pattern in upper half of register lui $8, 0x1001 10010000
17
Offsets Locations in order declared: x : 0(0x10010000) y: 4(0x10010000)
18
Accessing Memory x = x + y where x and y are in main memory:
19
Load Delay Load delay: Can't use register in instruction after it is loaded – Real MIPS hardware – Tutorial's SPIM simulator – Don't worry about for MARS
20
Labels Labels usually used to specify memory locations – Not allowed for now
21
Labels Behind the scenes… – lw/sw with label = 2 instructions
22
Weirdness sizeof(2 chars and an int) != sizeof(2 chars and an int)
23
Memory Alignment Memory alignment : restrictions on where read/write can start – Want to read 4 bytes: Start on multiple of 4 – Want to read 2 bytes: Start on multiple of 2 – Want to read 1 byte: Start on any byte
24
Offsets Locations in order declared – Must be aligned
25
Offsets Locations in order declared – Must be aligned 32107654111098 aa
26
Offsets Locations in order declared – Must be aligned 32107654111098 aaff
27
Offsets Locations in order declared – Must be aligned 32107654111098 aaff bb
28
Offsets Locations in order declared – Must be aligned 32107654111098 aaff cc bb
29
Offsets Alternative order
30
Offsets Alternative order 32107654111098 aa
31
Offsets Alternative order 32107654111098 bbaa
32
Offsets Alternative order 32107654111098 cc bbaa
33
Offsets Alternative order 32107654111098 cc bbaaff
34
Byte Packing Byte packing : ordering class/struct members for proper alignment
35
Loading Bytes lb $dest, offset(base) : load byte sb $source, offset(base) : store byte lh $dest, offset(based) : load half word sh $ source, offset(base) : store half word
36
LB Sign Extension Code: Memory Result f f f f f f b b 1111 1111 1111 1111 1111 1111 1011 1011
37
Loading Bytes Loads sign extend value – Perfect for numeric data lbu/lhu load unsigned – no sign extension – use for chars, etc…
38
LB Sign Extension Code: Memory Result 0 0 0 0 0 0 b b 0000 0000 0000 0000 0000 0000 1011 1011
39
Horner's Method Reduce multiplications to evaluate polynomial Ex: 6x 3 – 3x 2 + 7x + 2 First, put the coefficient of the first term into the accumulator: 6 Next, multiply that value by x: 6x Add the coefficient of the next term: 6x - 3 Next, multiply that sum by x: 6x 2 - 3x Add the coefficient of the next term: 6x 2 - 3x + 7 Next, multiply that sum by x: 6x 3 - 3x 2 + 7x Finally, add the coefficient of the last term: 6x 3 - 3x 2 + 7x + 2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.