Load and Store Instructions and Memory Requests Made During Program Execution

 

Given the following code:

 

         .data

         .align 2

a: .word 0x11223344

b: .word 0x87654321

c: .hword 0x1234, 0x5678

d: .byte 0x12, 0x34, 0x56, 0x78

         .text

.global _start

_start:

         movia r8, a

         ldw        r9, 0(r8)

         ldw r10, 4(r8)

         ldh r11, 4(r8)

         ldhu r12, 4(r8)

         ldbu r13, 0xf(r8)

         ldw r14, 0xc(r8)

         sth r14, 0xc(r8)

         ldw r15, 0xc(r8)

         ldw r16, 8(r8)

         ldh r17, 6(r8)

         sth r14, 0xe(r8)

         ldw r18,0x(r8)

        

 

a)       Which registers would the above code update?

b)      What would be the values of these registers? Assume a is stored at memory address 0x100

c)       When this program executes how many memory references will it make?

d)      How many bytes will it read from memory and how many bytes will it write to memory?

 

Answers Below

 

a)      r8-r16, PC

b)      r8=0x100, r9=0x11223344, r10=0x87654321, r11=0x00004321, r12=0x00004321, r13=0x78, r14=0x78563421, r15=0x78563421, r16=0x56781234, r17=0xffff8765, r18=0x11223344

c)       14 for instruction fetches, and 12 for data

d)      31 bytes will be read, and 4 bytes will be written