aboutsummaryrefslogtreecommitdiff
path: root/lab7bonus_fig4.s
diff options
context:
space:
mode:
authorkryptoish <krish_thakur7@icloud.com>2024-12-03 16:58:07 -0800
committerkryptoish <krish_thakur7@icloud.com>2024-12-03 16:58:07 -0800
commitf665f0ff80397ab10dbbea6cfcb302bb131f9719 (patch)
tree131ba7ab978dd127992111d354e8460c61fbc626 /lab7bonus_fig4.s
added files
Diffstat (limited to '')
-rw-r--r--lab7bonus_fig4.s29
1 files changed, 29 insertions, 0 deletions
diff --git a/lab7bonus_fig4.s b/lab7bonus_fig4.s
new file mode 100644
index 0000000..35e20e0
--- /dev/null
+++ b/lab7bonus_fig4.s
@@ -0,0 +1,29 @@
+ MOV R6,stack_begin
+ LDR R6,[R6] // initialize stack pointer
+ MOV R4, result // R4 contains address of result
+ MOV R3,#0
+ STR R3,[R4] // result = 0;
+ MOV R0,#1 // R0 contains first parameter
+ MOV R1,#5 // R1 contains second parameter
+ MOV R2,#9 // R2 contains third parameter
+ MOV R3,#20 // R3 contains fourth parameter
+ BL leaf_example // call leaf_example(1,5,9,20);
+ STR R0,[R4] // result = leaf_example(1,5,9,20);
+ HALT
+leaf_example:
+ STR R4,[R6] // save R4 for use afterwards
+ STR R5,[R6,#-1] // save R5 for use afterwards
+ ADD R4,R0,R1 // R4 = g + h
+ ADD R5,R2,R3 // R5 = i + j
+ MVN R5,R5 // R5 = ~(i + j)
+ ADD R4,R4,R5 // R4 = (g + h) + ~(i + j)
+ MOV R5,#1
+ ADD R4,R4,R5 // R4 = (g + h) - (i + j)
+ MOV R0,R4 // R0 = return value (g + h) - (i + j)
+ LDR R5,[R6,#-1] // restore saved contents of R5
+ LDR R4,[R6] // restore saved contents of R4
+ BX R7 // return control to caller
+stack_begin:
+ .word 0xFF
+result:
+ .word 0xCCCC