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?

Linux アセンブリ 入力を受け付け画面表示

Posted at

検証画面

nasm -f elf64 test.asm -o test.o
ld test.o -o test
./test

image.png

コード

section .text
global _start

_start:
    ; 標準入力から読み取り
    mov rax, 0          ; sys_read システムコール番号
    mov rdi, 0          ; 0=標準入力
    mov rsi, buffer     ; バッファのアドレス
    mov rdx, 1024       ; 読み取る最大バイト数
    syscall

    ; 読み取ったバイト数を保存
    mov rbx, rax        ; RAXには実際に読まれたバイト数が格納される

    ; 標準出力に書き込み
    mov rax, 1          ; sys_write システムコール番号
    mov rdi, 1          ; 1=標準出力
    mov rsi, buffer     ; 書き込むデータのアドレス
    mov rdx, rbx        ; 書き込むバイト数
    syscall

    ; プログラムの終了
    mov rax, 60         ; sys_exit システムコール番号
    mov rdi, 0          ; 終了ステータス
    syscall

section .bss
buffer resb 1024        ; 1024バイトのバッファを確保

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?