Assembly nasm 64位推送qword?

Assembly nasm 64位推送qword?,assembly,x86-64,nasm,shellcode,Assembly,X86 64,Nasm,Shellcode,我似乎有一个有趣的问题,尽管我可能在做一些明显错误的事情 我的问题是我试图将aabbcccc推到堆栈上,然后通过stdout打印它们。然而,在我的x86_64环境中,push 0x414141push41410000000 因此,下面的代码块: global _start section .text _start: push 0x43434343 ; CCCC push 0x42424242 ; BBBB push 0x41414141 ;

我似乎有一个有趣的问题,尽管我可能在做一些明显错误的事情

我的问题是我试图将aabbcccc推到堆栈上,然后通过stdout打印它们。然而,在我的x86_64环境中,
push 0x414141
push
41410000000

因此,下面的代码块:

    global _start
    section .text
    _start:
    push 0x43434343  ; CCCC
    push 0x42424242  ; BBBB
    push 0x41414141  ; AAAA
    xor rax,rax      ; Zero RAX
    mov byte al,0x1  ; 1 for sys_write
    mov rdi,rax      ; 1 for stdout
    mov rsi,rsp      ; RSP for source
    mov byte dl,0xC  ; 12
    syscall          

    xor rax,rax      ; Zero RAX
    mov al, 0x3C     ; 60 for sys_edxit
    cdq              ; 0 for clean exit.
    syscall
输出
AAAABBBB
,我以为只有8个字节,实际上是我要求的12个字节。当通过管道传输到输出文件并在hexedit中查看时,我注意到它正在显示
414100000000424242

我认为
push
指令推送一个
dword
值。在
qword
大小的堆栈上?我这样想对吗

这可以通过考虑额外的字节并将我的长度更改为20来避免。但这会导致像
sys\u open
这样的问题

所以我的问题是,我做错了什么?

对于64位代码,堆栈(RSP)总是在8字节边界上对齐。也没有“push qword imm64”指令(请参见注释)

我的建议是将字符串“aaaabbcccc”存储在它所属的数据部分(或“.rodata”)中,而不是弄乱堆栈。或者在外壳代码中

push   'CCCC'                  ; push qword, including 4 bytes of zeros
mov    rax, 'AAAABBBB'         ; mov reg, imm64; pick any register
push   rax                     ; push qword
另一种保持你的变态的方法可能是:

sub rsp,16
mov dword [rsp],'AAAA'
mov dword [rsp+4],'BBBB'
mov dword [rsp+8],'CCCC'
....
add rsp,16
注意:AMD的手册上说有一个“push imm64”指令。AMD的手册是错误的-此指令实际上推动32位立即数(符号扩展为64位)

英特尔的手册没有这个问题:

同样相关:-您绝对不能在64位模式下执行dword push。

@DCoder:根据
push
指令上的操作伪码,您是对的,操作数将进行符号扩展。--六羟甲基三聚氰胺六甲醚。。。他刚刚删除了他的评论?