Use assembly to write the sum cos also the delay subroutineS
Solution
/* save file sum.s and you can run in gcc compiler */
/* This is the assembly program to add two variables together and print the result*/
/*Data section */
.data
.baligan 4
result : .asciz \"\ %d + %d = %d\ \"
x : .word 33 @ .word indicates integer variables
y: .word 44
z: .word 0 @ z containts the result of a+b
/* Code section */
.text
.global main
.extern printf
main:
push {ip,lr} @Used to push return address and dummy register for alignment
ldr r1,=x @used to get address of x into r1
ldr r1,[r1] @used to get x into r1
ldr r2,=y @used to get address of x into r2
ldr r2,[r2] @used to get y into r2
add r1,r1,r2 @adding r1 and r2 and sotring the result into r1
ldr r2,=z @used to get address of z into r2
str r1,[r1] @it sotres r1 into z
ldr r0,=result @used to get address of result into r0
ldr r1,=x @ r1 <- x
ldr r1,[r1]
ldr r2,=x @ r2 <- y
ldr r2,[r2]
ldr r3,=z @ r3 <- z
ldr r3,[r3]
b1 printf @print result and pass params into r1,r2 and r3
pop {ip,pc} @pop return address into pc
