From 79b920e1b81dd596fee2a7f849ac6cbb304c85bb Mon Sep 17 00:00:00 2001 From: paicc Date: Sun, 3 Aug 2014 14:13:40 +0800 Subject: [PATCH 1/3] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5761abc..4cdd751 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.o +*.0 From 9eb7162510d3d2590ffc49b14a5cbae13ef2bf8c Mon Sep 17 00:00:00 2001 From: paicc Date: Tue, 5 Aug 2014 13:53:52 +0800 Subject: [PATCH 2/3] Update fib.s --- lab-1/fib.s | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lab-1/fib.s b/lab-1/fib.s index 14c6734..593aca1 100644 --- a/lab-1/fib.s +++ b/lab-1/fib.s @@ -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 From 5603e32aa34f7b6a99d7681a2a16ef4cecc2d351 Mon Sep 17 00:00:00 2001 From: paicc Date: Sun, 21 Sep 2014 18:49:50 +0800 Subject: [PATCH 3/3] Update mutex.s --- lab-2/mutex.s | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lab-2/mutex.s b/lab-2/mutex.s index d23565d..0ad6b4f 100644 --- a/lab-2/mutex.s +++ b/lab-2/mutex.s @@ -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