170 likes | 341 Views
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
E N D
Accessing MemoryChapter 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, 232 bytes in memory • Each location is numbered consecutively • Memory data types • Byte = 1 byte Halfword = 2 bytes • Word = 4 bytes Doubleword = 8 bytes
Data types • All memory references must be aligned • x byte quantities must begin in an address divisible by x
Memory Allocation input .section “.data” input: .word 0x12345678 limit: .half 0x9a prompt: .asciz “Hello!” limit prompt
Memory Allocation .section “.data” input: .word 0x12345678 limit: .half 0x9a prompt: .asciz “Hello!” 300 – divisible by 4 input takes up 4 byte locations
Memory Allocation .section “.data” input: .word0x12345678 limit: .half 0x9a prompt: .asciz “Hello!” 304 – divisible by 2 limit 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: .word0x12345678 limit: .half 0x9a prompt: .asciz “Hello!” 306 – divisible by 1 Each element of prompt takes up 1 byte location
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)
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
Store Instructions Why don’t we have all the same options as we did for the load instructions?
mov 300, %o0 mov 0x12345678, %o1 st %o1, [%o0] sth %o1, [%o0 + 6] sth %o1, [%o0 + 9] stb %o1, [%o0 + 13] 78 56 34 12 78 56 error 78
mov 0x9abcdef0, %o2 mov 0x87654321, %o3 std %o2, [%o0 + 4] 78 56 34 12 f0 de bc 9a 21 43 65 87
Rules to Remember • Lower byte Lower address • Reference is to the lowest address • Memory references must be byte aligned
Data Section .section “.data” first: .word 0x03, 0x0ef321 second: .byte 0x5c .align 2 third: .half 0x987, 0x7e string: .asciz “done”
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