Skip to content
Open

hi #4

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.o
*.0
30 changes: 16 additions & 14 deletions lab-1/fib.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ fibonacci:
@ PROLOG
push {r3, r4, r5, lr}

@ R4 = R0 - 0 (update flags)
@ if(R0 <= 0) goto .L3 (which returns 0)

@ Compare R4 wtih 1
@ If R4 == 1 goto .L4 (which returns 1)

@ R0 = R4 - 1
@ Recursive call to fibonacci with R4 - 1 as parameter

@ R5 = R0
@ R0 = R4 - 2
@ Recursive call to fibonacci with R4 - 2 as parameter

@ R0 = R5 + R0 (update flags)
subs r4,r0,#0 //R4 = R0 - 0 (update flags)

cmp r0 #0 //if(R0 <= 0) goto .L3 (which returns 0)
ble .L3

cmp r4,#1 // Compare R4 wtih 1
beq .L4 // If R4 == 1 goto .L4 (which returns 1)

subs r0,r4,#1 // R0 = R4 - 1
bl fibonacci // Recursive call to fibonacci with R4 - 1 as parameter
addi r5,r5,#0 // R5 = R0

subs r0,r4,#2 // R0 = R4 - 2
bl fibonacci // Recursive call to fibonacci with R4 - 2 as parameter

add r0,r5,r0 // R0 = R5 + R0 (update flags)

pop {r3, r4, r5, pc} @EPILOG

Expand Down
15 changes: 12 additions & 3 deletions lab-2/mutex.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,28 @@
.type lock_mutex, function
lock_mutex:
@ INSERT CODE BELOW
ldr r2,=locked //load value of locked and save to r2

luck_loop:
//When No.(x-1) thread enter,it will modify flag of r1 for tell No.x "I'm working."
//r1 is locked-flag in the program
ldrex r1,[r0] //As point, That's enter address of r0 to load it and save to r1.
cmp r1,#locked
beq luck_loop //if No.(x-1) still work, return to wait.
strex r1,r2,[r0] //Save the state from [r0] to r2 is success?
cmp r1,#success
bne luck_loop
@ END CODE INSERT
bx lr

.size lock_mutex, .-lock_mutex

.global unlock_mutex
.type unlock_mutex, function
unlock_mutex:
@ INSERT CODE BELOW

ldr r1, =unlocked
str r1,[r0]
@ END CODE INSERT
bx lr
.size unlock_mutex, .-unlock_mutex

.end