Created
March 15, 2015 11:22
-
-
Save scottt/b1969358397a83f04c5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.syntax unified | |
.thumb | |
.data | |
out: | |
.space 10*4 | |
semihost_arg: | |
.space 4*4 | |
.text | |
.cfi_sections .eh_frame, .debug_frame | |
.type fib, %function | |
fib: | |
.cfi_startproc | |
push {r4, r5, r6, lr} | |
.cfi_def_cfa_offset 16 | |
.cfi_offset 4, -16 | |
.cfi_offset 5, -12 | |
.cfi_offset 6, -8 | |
.cfi_offset 14, -4 | |
cmp r0, 0x01 // if x == 1 | |
beq .L_return // return 1 | |
cmp r0, 0x00 // if x == 0 | |
it eq | |
moveq r0, 0x01 | |
beq .L_return // return 1 | |
mov r5, r0 | |
sub r0, 1 | |
bl fib // fib(n-1) | |
mov r4, r0 | |
mov r0, r5 | |
sub r0, 2 | |
bl fib | |
add r0, r4 | |
.L_return: | |
pop {r4, r5, r6, pc} | |
.cfi_endproc | |
.size fib, . - fib | |
/* See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471k/pge1358787045051.html */ | |
#define SYS_OPEN 0x01 | |
#define SYS_WRITE 0x05 | |
#define SYS_CLOSE 0x02 | |
#define angel_SWIreason_ReportException 0x18 | |
/* See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471k/pge1358787050566.html */ | |
#define ADP_Stopped_ApplicationExit 0x20026 | |
.equ n_time, 6 | |
.global _start | |
.type _start, %function | |
_start: | |
.cfi_startproc | |
push {r4, r5, r6, lr} | |
.cfi_def_cfa_offset 16 | |
.cfi_offset 4, -16 | |
.cfi_offset 5, -12 | |
.cfi_offset 6, -8 | |
.cfi_offset 14, -4 | |
ldr r4, =out | |
/* do { | |
r0 = fib(r5); | |
out[r4] = r0; | |
r4 += 4; | |
} while (r5 != 5); | |
*/ | |
mov r5, 0 | |
.L_loop: | |
mov r0, r5 | |
bl fib | |
str r0, [r4] | |
add r4, 4 | |
add r5, 1 | |
cmp r5, n_time | |
bne .L_loop | |
/* semihost_arg[0] = "out"; | |
semihost_arg[1] = 5; // "wb" | |
semihost_arg[2] = 3; // strlen("out") | |
r4 = __semihost(SYS_OPEN, semihost_arg); | |
*/ | |
ldr r1, =semihost_arg | |
ldr r0, =filename | |
str r0, [r1] | |
mov r0, 5 | |
str r0, [r1, 4] | |
mov r0, 3 | |
str r0, [r1, 8] | |
mov r0, SYS_OPEN | |
bkpt 0xab | |
mov r4, r0 | |
/* semihost_arg[0] = fd; // r4 | |
semihost_arg[1] = out; | |
semihost_arg[2] = 5 * 4; // 5 * sizeof(int) | |
__semihost(SYS_WRITE, semihost_arg); | |
*/ | |
ldr r1, =semihost_arg | |
str r4, [r1] | |
ldr r0, =out | |
str r0, [r1, 4] | |
mov r0, n_time*4 | |
str r0, [r1, 8] | |
mov r0, SYS_WRITE | |
bkpt 0xab | |
/* semihost_arg[0] = fd; // r4 | |
__semihost(SYS_CLOSE, semihost_arg); | |
*/ | |
ldr r1, =semihost_arg | |
str r4, [r1] | |
mov r0, SYS_CLOSE | |
bkpt 0xab | |
/* __semihost(angel_SWIreason_ReportException, ADP_Stopped_ApplicationExit); */ | |
mov r0, angel_SWIreason_ReportException | |
ldr r1, =ADP_Stopped_ApplicationExit | |
bkpt 0xab | |
pop {r4, r5, r6, pc} | |
.cfi_endproc | |
.size _start, . - _start | |
filename: | |
.asciz "out" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment