0
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?

ARM 32bit Linux でシステムコールを呼び出しHELLOWORLD表示

Posted at

構成

write()

第1引数 : r0 出力先を端末に設定
第2引数 : r1 文字列のアドレス
第3引数 : r2 文字列の長さ
r7write()のシステムコール番号4を設定しsvc命令で呼び出す

return

第1引数 : 正常終了を意味する0を設定
r7returnのシステムコール番号1を設定しsvc命令で呼び出す

ソース

test.s
.section .data
msg:
    .ascii "HELLOWORLD\n"
len = . - msg           @ 現在のアドレス(.)からmsgを引いて文字列のバイト数を算出

.section .text
.global _start

_start:
    mov r0, #1          @ stdout
    ldr r1, =msg        @ 文字列アドレス
    ldr r2, =len        @ 文字列の長さ
    mov r7, #4          @ write syscall
    svc 0               @ syscall呼び出し

    mov r0, #0          @ exit code (=return 0相当)
    mov r7, #1          @ exit syscall
    svc 0
testuser@CasaOS:~/atest$ as -o test.o test.s
testuser@CasaOS:~/atest$ ld -o test test.o
testuser@CasaOS:~/atest$ ls
test  test.o  test.s
testuser@CasaOS:~/atest$ ./test 
HELLOWORLD
0
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
0
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?