CS代写 Assessment 4 preview

Assessment 4 preview

DISCLAIMER
This presentation does not cover all the potential topics.

Copyright By PowCoder代写 加微信 powcoder

We have 1-1.5 more lectures before the assessment that is fair game

Control (compound if statements) Data access
Stack layout

Compound if (&&)

Compound if (||)

Loads and Stores
ldr str ldrh strh ldrb strb ldrsh ldrsb

Addressing modes
Base register address mode: [r0]
Base displacement addressing mode [r0, 8] or [r0, r1]

C to ARM (DRAW PICTURES)
If r0 contains the address of A and r1 contains the address of B, what is
ldr r3, [r1]
str r3, [r0]
// store A
If r0 contains the address of A and r1 contains the value of B, what is A = B?
str r1, [r0] // store B->A

C to ARM (DRAW PICTURES)
If r0 contains the address of A and r1 contains the address of B, what is A = *B?
ldr r3, [r1]
ldr r3, [r3]
str r3, [r0]
// store A

If r0 contains the address of A and r1 contains the address of B, what does this sequence do?
ldr r3, [r0] ldr r4, [r1] str r3, [r4]
*B = A; r3

Array Access
g = h + A[4] // assume A is a double array and doubles are 64-bits (8 bytes) If r0 holds the value of g, r1 holds the value of h, r2 holds the address of A.
ldr r4, [r2, 32]
add r0, r1, r4
B[10] = A[3] // assume A and B are shorts (16-bits),
// r0 holds address of A, r1 address of B
ldr r4, [r0, 6]
str r4, [r1, 20]

Large Constants
Problem – how do we load an arbitrary 32-bit number into a register?
Solution: Assembly provides for “literal pool”. The literal pool is a set of constants (32-bit) that are put into the text segment (along with the program’s instructions). We can access the text segment by using the “PC” as the base register + a offset.
Same as this (assembler does this for you)

Data Segment Access
Problem – how do we load from the data segment? The address is 32 bits and we need to get that address into a register.
Solution: Assembly provides for “literal pool”. Use the “=” trick in front of a label. A label is just a 32-bit number

call a function with BL
bl saves the address of the next instruction in lr return from a function with BX
bx lr branches to the address contained in lr

Each function has its own stack frame
Prologue and Epilogue – establish the stack frame
FP points to start of stack frame SP points to end of stack frame

Use .equ as offsets from the fp

Set the FP
fnEntry: push {r6-r7, fp, lr}
What should the next instruction be?
add fp, sp, FP_OFFSET
What is the value of FP_OFFSET?

How do you get the 5th parameter
6th p 5th p
The caller puts the 5th parameter at the end of its stack frame.
So grab it from your FP .
ldr r4, [fp, +4]
.equ somePName, +4
ldr r4, [fp, somePName]

What is the offset to local variable “i”?
6th p 5th p

public/examples/arm/extraparam

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com