/**
zun-doko-kiyoshi in ARM Linux EABI
*/
.section .text
.global _start
.macro sys_write
mov r7, $0x04
svc $0x00
.endm
.macro rand_init
/* using all high resiters for rand: r8-r12 */
/* set seed from time */
ldr r0, =time
/* sys_time */
mov r7, $0x0d
svc $0x00
ldr r0, =time
ldr r8, [r0]
/* load constant for rand */
ldr r9, =1103515245
ldr r10, =12345
ldr r11, =2147483647
.endm
.macro rand
/* random update r8 */
mov r12, r8
mla r8, r12, r9, r10
and r8, r8, r11
.endm
_start:
rand_init
/* r6 is current zun count */
mov r6, $0
loop:
rand
/* check bit / eq = zun, ne = doko */
tst r8, $0x80
adreq r1, zun
moveq r2, #zun_len
addeq r6, $1
adrne r1, doko
movne r2, #doko_len
mov r0, $0x01
sys_write
bne check_kiyoshi
b loop
check_kiyoshi:
/* now this is doko state and check zun count */
cmp r6, $5
/* zun count is greater than 5 */
bge call_kiyoshi
/* failed to call kiyoshi and reset state */
mov r6, $0
b loop
call_kiyoshi:
/* now this is kiyoshi state */
adr r1, kiyoshi
mov r2, #kiyoshi_len
mov r0, $0x01
sys_write
mov r0, $0x00
/* sys_exit */
mov r7, $0x01
svc $0x00
zun:
.string "ズン\n"
zun_len = . - zun
.align 2
doko:
.string "ドコ\n"
doko_len = . - doko
.align 2
kiyoshi:
.string "キヨシ\n"
kiyoshi_len = . - kiyoshi
.align 2
.section .data
time: .word 0
cross compile
arm-linux-gnueabi-as ./sketch.s -o sketch.o && arm-linux-gnueabi-ld -o sketch -e _start sketch.o && qemu-arm-static ./sketch