6
4

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で、アセンブラ

Last updated at Posted at 2016-10-29

概要

raspberry pi 1 model bで、アセンブラやってみた。

開発環境

raspberry pi 1 model b
raspbian 2016_09_23 jessie lite

実行

nano test2.s
gcc test2.s -nostdlib
./a.out

サンプルコード

.text
.globl _start
_start:
    ldr r8, =msg
    mov r7, #4
    mov r0, #1
    ldr r1, =msg
    mov r2, #1
    svc #0
    mov r9, #'e'
    strb r9, [r8]
    svc #0
    mov r9, #'l'
    strb r9, [r8]
    svc #0
    mov r9, #'l'
    strb r9, [r8]
    svc #0
    mov r9, #'o'
    strb r9, [r8]
    svc #0
    mov r9, #'w'
    strb r9, [r8]
    svc #0
    mov r9, #'o'
    strb r9, [r8]
    svc #0
    mov r9, #'r'
    strb r9, [r8]
    svc #0
    mov r9, #'l'
    strb r9, [r8]
    svc #0
    mov r9, #'d'
    strb r9, [r8]
    svc #0
    mov r7, #1
    mov r0, #0
    svc #0
.data
msg:
    .byte 'h'

考察

レジスタ
 r0~r15まで、あるが、r13,r14,r15は、スタックポインタ、リンクレジスタ、プログラムカウンタで使えない。
 r7,r0,r1,r2,r3は、システムコールで使う。
 r4,r5,r6,r8,r9,r10,r11,r12が使える。
システムコール
 r7に1を入れて、r0に0を入れて、svcを呼べば、「exit」。
 r7に4を入れて、r0に1を入れて、r1にアドレスを入れて、r2に長さを入れて、svcを呼べば、「write」。
メモリへのアクセス
 ldrで、レジスタにアドレス入れて、ldrbで読み込む。strbで書き出す。

6
4
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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?