Upload
padma
View
38
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Accessing Memory Chapter 5. Lecture notes for SPARC Architecture, Assembly Language Programming and C, Richard P. Paul by Anu G. Bourgeois. Memory. Addresses are 32 bits wide Therefore, 2 32 bytes in memory Each location is numbered consecutively Memory data types - PowerPoint PPT Presentation
Citation preview
Accessing MemoryChapter 5
Lecture notes for SPARC Architecture, Assembly Language
Programming and C, Richard P. Paul
by Anu G. Bourgeois
2
Memory
• Addresses are 32 bits wide
• Therefore, 232 bytes in memory
• Each location is numbered consecutively
• Memory data types– Byte = 1 byte Halfword = 2 bytes– Word = 4 bytes Doubleword = 8 bytes
3
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.294x109 2.147 x 109
• All memory references must be aligned• x byte quantities must begin in an address divisible by x
Memory Allocation
.section “.data”input: .word 0x12345678limit: .half 0x9aprompt: .asciz “Hello!”
Address (decimal)
Data(hex)
299
300 78
301 56
302 34
303 12
304 9a
305 00
306 ‘H’
307 ‘e’
308 ‘l’
309 ‘l’
310 ‘o’
311 ‘!’
312
3134
input
limit
prompt
Memory Allocation
.section “.data”input: .word 0x12345678limit: .half 0x9aprompt: .asciz “Hello!”
Address (decimal)
Data(hex)
299
300 78
301 56
302 34
303 12
304 9a
305 00
306 ‘H’
307 ‘e’
308 ‘l’
309 ‘l’
310 ‘o’
311 ‘!’
312
3135
300 – divisible by 4input takes up 4 byte locations
Memory Allocation
.section “.data”input: .word 0x12345678limit: .half 0x9aprompt: .asciz “Hello!”
Address (decimal)
Data(hex)
299
300 78
301 56
302 34
303 12
304 9a
305 00
306 ‘H’
307 ‘e’
308 ‘l’
309 ‘l’
310 ‘o’
311 ‘!’
312
3136
304 – divisible by 2limit takes up 2 byte locations
Note: location 305 will have leading zeroes fill in the extra byte not specified in the data section
Memory Allocation
.section “.data”input: .word 0x12345678limit: .half 0x9aprompt: .asciz “Hello!”
Address (decimal)
Data(hex)
299
300 78
301 56
302 34
303 12
304 9a
305 00
306 ‘H’
307 ‘e’
308 ‘l’
309 ‘l’
310 ‘o’
311 ‘!’
312
3137
306 – divisible by 1Each element of prompt takes up 1 byte location
8
Addressing Variables
• Load and Store operations are the only instructions that reference memory
• Both instructions take two operands– One memory, and one register
• Can access memory using different data types (byte, half word, word, double word)
9
Load Instructions
Mnemonic Operation
ldsb Load signed byte, propagate sign left in register
ldub Load unsigned byte, clear high 24 bits of register
ldsh Load signed halfword, propogate sign left in register
lduh Load unsigned halfword, clear high 16 bits of register
ld Load word
ldd Load double, reg. # even, first 4 bytes into reg. n, next 4 into reg. n + 1
10
set input, %o0
ld [%o0], %o1 %o1 = 0x12345678
ldub [%o0 + 7], %o2 %o2 = ‘e’
ldsh [%o0 + 3], %o3 error
ldsh [%o0 + 4], %o4 %o4 = 0x9a
ldsb [%o0 + 4], %o5 %o5 = 0xffffff9a
11
Store Instructions
Mnemonic Operation
stb Store low byte of register, bits 0-7, into memory
sth Store low two bytes of register, bits 0-15 into memory
st Store register
std Store double, reg. # even, first 4 bytes from reg. n, next 4 from reg. n + 1
Why don’t we have all the same options as we did for the load instructions?
Address(decimal)
Data(hex)
300
301
302
303
304
305
306
307
308
309
310
311
312
313
12
mov 300, %o0
mov 0x12345678, %o1
st %o1, [%o0]
sth %o1, [%o0 + 6]
sth %o1, [%o0 + 9]
stb %o1, [%o0 + 13]
78563412
7856
error
78
Address(decimal)
Data(hex)
300
301
302
303
304
305
306
307
308
309
310
311
312
313
13
mov 0x9abcdef0, %o2
mov 0x87654321, %o3
std %o2, [%o0 + 4]
78563412
f0debc9a21436587
Rules to Remember
1. Lower byte Lower address
2. Reference is to the lowest address
3. Memory references must be byte aligned
14
Data Section
.section “.data”first: .word 0x03, 0x0ef321second: .byte 0x5c.align 2third: .half 0x987, 0x7estring: .asciz “done”
Pointer Address data
first 400 03
401 00
402 00
403 00
404 21
405 f3
406 0e
407 00
second 408 5c
409 undef
third 410 87
411 09
412 7e
413 00
string 414 ‘d’
415 ‘o’
416 ‘n’
417 ‘e’
418 0
419
Allocating Space
.skip is a psedo-op that will provide space without any initialization
my_array: .skip 4*100
Provides space for a 100-word unintialized array
16