ece3803_d2008_hw2_solutions

ece3803_d2008_hw2_solutions - ECE 3803 D2008 Homework 2...

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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
Background 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. Express each instruction as 4 individual bytes arranged in the order they appear in memory (starting from the lowest address). ands
Background image of page 3

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

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

This note was uploaded on 04/17/2008 for the course ECE 3803 taught by Professor Bogdanov during the Spring '08 term at WPI.

Page1 / 8

ece3803_d2008_hw2_solutions - ECE 3803 D2008 Homework 2...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online