ece3803_d2008_hw2_solutions

ece3803_d2008_hw2_solutions - ECE 3803 D2008 Homework 2...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 3803 D2008 Homework 2 solutions 1 ECE 3803 D2008: Microprocessor System Design Homework 2 solutions Subroutines, stack 1. [20 pts] For the attached ARM assembly code listing, determine the contents of the stack and the known register values (except pc ) at the labeled point as the code is executed from start . For the stack, include memory addresses, 32-bit data values, the top-of-stack label, and an explanation of the origin of each item on the stack. Assume at the start: r0 = 0x20, r1 = 0x30, r2 = 0x40, r3 = 0x52, r4 = 0x23, r5 = 0x19, r13 = 0x2800 . r0 = 0x23 ; r0 – r2: partially sorted list r1 = 0x52 r2 = 0x19 r3 = 0x27F4 ; base address of parameters on the stack r4 = 0x23 ; same as initial value r5 = 0x19 ; same as initial value r13 = sp = 0x27E0 ; stack pointer r14 = lr = 0x40 ; sort12 return address Stack Memory address Data (32-bit) Origin 0x2800 ? 0x27FC 0x19 parameter 3 (originally in r5) 0x27F8 0x23 parameter 2 (originally in r4) 0x27F4 0x52 parameter 1 (originally in r3) 0x27F0 0x24 saved lr (r14) – sort3 return address 0x27EC 0x52 saved r3 0x27E8 0x40 saved r2 0x27E4 0x30 saved r1 0x27E0 (TOS) 0x20 saved r0
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
ECE 3803 D2008 Homework 2 solutions 2 2. [10 pts] Write a subroutine user_function in ARM assembly that accepts two 32-bit, signed integer parameters param1 and param2 on the stack and produces the 32-bit result = param1^2 + 4*param2. The result must overwrite param1 on the stack. Your subroutine must preserve all general purpose registers. The following code is used to call the subroutine: ldr r0,=param1 ; param1 and param2 are defined as ldr r1,=param2 ; constants stmfd sp!,{r0,r1} ; push parameters bl user_function ; call subroutine ldr r2,[sp],#8 ; retrieve result, restore sp ; done Here’s one possible implementation: user_function stmfd sp!,{r0-r2,lr} ; save work reg’s, return address add r2,sp,#16 ; point r2 at param1 ldmia r2,{r0,r1} ; load parameters from the stack mul r0,r0,r0 ; r0 = param1 * param1 add r0,r0,r1,asl 2 ; r0 += param2 * 4 str r0,[r2] ; overwrite param2 with result ldmfd sp!,{r0-r2,pc} ; restore work reg’s, return
Image of page 2
ECE 3803 D2008 Homework 2 solutions 3 Binary instruction encoding 3. [20 pts] Encode the following ARM instructions into ARM machine code. Explain the meaning of each field in the instruction.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern