Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .syntax unified
- .cpu cortex-m3
- .thumb
- .align 2
- .global fir
- .thumb_func
- @ CG2028 Assignment, Sem 2, AY 2018/19
- @ (c) CG2028 Teaching Team, ECE NUS, 2019
- @Register map
- @R0 - N, returns y
- @R1 - b (addr)
- @R2 - x_n
- @R3 - y_n
- @R4 - b (value)
- @R5 - x_store[j] (addr)
- @R6 - x_store[j] (value)
- @R7 - counter for circular buffer
- @R8 - curr (addr)
- @R9 - x_store (addr)
- @R10 - loop counter
- @R11 - curr (value)
- fir:
- @ PUSH / save (only those) registers which are modified by your function
- @ parameter registers need not be saved.
- PUSH {R3-R11}
- @ write asm function body here
- LDR R4, [R1] @ R4: b (value)
- MUL R3, R2, R4 @ R3: x_n * b[0]
- MOV R10, R0 @ use R10 as loop counter, initialized to N
- LDR R8, =curr
- LDR R9, =x_store
- LDR R11, [R8] @ R11: curr (value)
- MOV R7, R11 @ R7: counter for circular buffer
- ADD R5, R9, R11, LSL #2 @ R5: x_store[curr] (addr)
- loop:
- LDR R4, [R1, #4]! @ R4: b[++j] (value)
- LDR R6, [R5], #4 @ R6: x_store[j++] (value)
- MLA R3, R4, R6, R3 @ y_n += b * x_store[j]
- ADD R7, #1
- CMP R7, R0
- BEQ if1 @ if R7 == N, reset R7 to 0 and R5 to x_store (addr)
- return_from_if1:
- SUBS R10, #1 @ loop counter --
- BNE loop
- @LDR R4, [R8]
- SUBS R11, #1 @ curr--, since we write to the left of the slot we are reading
- BMI if2 @ if R11 < 0, wrap around to N-1
- return_from_if2:
- ADD R5, R9, R11, LSL #2 @ R5: x_store[curr] (addr)
- STR R2, [R5] @ R2: x_n
- STR R11, [R8] @ R11: curr (value)
- @ prepare value to return (y_n) to C program in R0
- MOVW R4, #10000
- UDIV R3, R4 @ y_n/10000
- MOV R0, R3
- @ POP / restore original register values. DO NOT save or restore R0. Why?
- POP {R3-R11}
- @ return to C program
- BX LR
- if1:
- MOV R7, #0
- LDR R5, =x_store
- BAL return_from_if1
- if2:
- MOV R11, R0
- SUB R11, #1
- BAL return_from_if2
- @label: .word value
- .equ N_MAX, 10
- @.lcomm label num_bytes
- .lcomm x_store N_MAX * 4
- .section ".data"
- .global curr
- curr: .word 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement