Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this machine code generated for "inc qword [rsp]"?

Consider this x64 NASM-syntax assembly:

inc qword [rax]
inc qword [rcx]
inc qword [rdx]
inc qword [rbx]
inc qword [rsp]
inc qword [rbp]
inc qword [rsi]
inc qword [rdi]

After assembling with nasm (and linking with gnu ld), objdump -d reports the following:

4000b0:       48 ff 00                incq   (%rax)
4000b3:       48 ff 01                incq   (%rcx)
4000b6:       48 ff 02                incq   (%rdx)
4000b9:       48 ff 03                incq   (%rbx)
4000bc:       48 ff 04 24             incq   (%rsp)
4000c0:       48 ff 45 00             incq   0x0(%rbp)
4000c4:       48 ff 06                incq   (%rsi)
4000c7:       48 ff 07                incq   (%rdi)

The code generated for inc qword [rbp] makes sense since the mod field is set. However, I can't figure out where the 24 comes from when assembling inc qword [rsp]. I've been looking at coder64 #xFF and nothing there suggests to me that the 24 should be generated. I'm obviously missing something at a higher level.

like image 744
jli Avatar asked Sep 29 '12 19:09

jli


Video Answer


1 Answers

There is no [RSP] ModR/M byte. So it uses the [sib] ModR/M. The sib means there's a sib byte, and 0x24 is the sib byte for RSP.

like image 68
CrazyCasta Avatar answered Oct 21 '22 02:10

CrazyCasta