目的
以下の記事でMOV
命令で使える即値と、LDR
命令について検証しました。
32ビットARMアセンブリのMOV命令で使える即値の仕組みを理解する
今回はMOVW
及びMOVT
命令を使って即値を代入してみます。
MOVW
: 上位16ビットへ即値を格納
MOVT
: 下位16ビットへ即値を格納
以下の命令でコンパイル及び逆アセンブルします。
as -o test.o test.s
ld -o test test.o
objdump -d test > test.asm
検証用コード
.global _start
_start:
MOVW r0, #0x5678
MOVT r0, #0x1234
LDR r1, =0x12345678
B
test: file format elf32-littlearm
Disassembly of section .text:
00010054 <_start>:
10054: e3050678 movw r0, #22136 @ 0x5678
10058: e3410234 movt r0, #4660 @ 0x1234
1005c: e51f1000 ldr r1, [pc, #-0] @ 10064 <_start+0x10>
10060: eafffffe b 10060 <_start+0xc>
10064: 12345678 .word 0x12345678
動作確認
GDBにてb .
命令まで実行してR0
及びR1
レジスタの中身を確認する。
命令は以下の通り。
gdb test
b *0x10060
run
info registers r0 r1
実際の操作。
以下のように両方のレジスタに0x12345678
が入っている。
testuser@CasaOS:~/atest$ gdb test
GNU gdb (Debian 13.1-3) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...
(No debugging symbols found in test)
(gdb) b *0x10060
Breakpoint 1 at 0x10060
(gdb) run
Starting program: /home/testuser/atest/test
Breakpoint 1, 0x00010060 in _start ()
(gdb) info registers r0 r1
r0 0x12345678 305419896
r1 0x12345678 305419896
動作環境(Linux / ARM 版)
OS: Armbian 23.08.0-trunk (Debian 12 Bookworm)
Kernel: Linux 6.1.38-meson (armv7l)
CPU: ARM Cortex-A5, 4 cores, Little Endian
Architecture: armv7l
GNU assembler: 2.40 (arm-linux-gnueabihf) using BFD version (GNU Binutils for Debian) 2.40
GNU ld: (GNU Binutils for Debian) 2.40
GDB: GNU gdb (Debian 13.1-3) 13.1
備考: Windows10からSSH接続して使用