1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

raspberry pi 1 model bで、アセンブラ その3

Last updated at Posted at 2016-10-30

#概要
raspberry pi 1 model bで、アセンブラでfizzbuzzやってみた。
#開発環境
raspberry pi 1 model b
raspbian 2016_09_23 jessie lite
#実行
nano fizzbuzz.s
gcc fizzbuzz.s -nostdlib
./a.out
#サンプルコード

.text
.globl _start
_start:
        ldr r8, =msg
        mov r11, #0
loop:
        add r11, r11, #1
        mov r9, r11
loop3:
        cmp r9, #15
        subcs r9, r9, #15
        bcs loop3
        cmp r9, #0
        bne tobu4
        mov r7, #4
        mov r0, #1
        ldr r1, =fizzbuzz
        mov r2, #9
        svc #0
        b   tobu3
tobu4:
        mov r9, r11
loop4:
        cmp r9, #3
        subcs r9, r9, #3
        bcs loop4
        cmp r9, #0
        bne tobu5
        mov r7, #4
        mov r0, #1
        ldr r1, =fizz
        mov r2, #5
        svc #0
        b   tobu3
tobu5:
        mov r9, r11
loop5:
        cmp r9, #5
        subcs r9, r9, #5
        bcs loop5
        cmp r9, #0
        bne tobu2
        mov r7, #4
        mov r0, #1
        ldr r1, =buzz
        mov r2, #5
        svc #0
        b   tobu3
tobu2:
        mov r9, r11
        mov r12, #0
loop2:
        cmp r9, #10
        subcs r9, r9, #10
        addcs r12, r12, #1
        bcs loop2
        cmp r12, #0
        beq tobu
        add r12, #'0'
        strb r12, [r8]
        bl echo
tobu:
        add r9, #'0'
        strb r9, [r8]
        bl echo
        mov r9, #' '
        strb r9, [r8]
        bl echo
tobu3:
        cmp r11, #99
        bcc loop
        b exit
echo:
        mov r7, #4
        mov r0, #1
        ldr r1, =msg
        mov r2, #1
        svc #0
        mov pc, lr
exit:
        mov r7, #1
        mov r0, #0
        svc #0
.data
msg:
        .byte '0'
fizzbuzz:
        .ascii "fizzbuzz "
fizz:
        .ascii "fizz "
buzz:
        .ascii "buzz "

#考察
サブルーチンは、スタックを使わない。
blで、呼び出して、mov pc,lrで戻る。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?