在linux下可以使用系統調用號4打印的東西:打印東西在堆棧(組裝)
mov eax,4 ;system call number
mov ebx,0 ;file descriptor
mov ecx,msg ;adress of message in data segment
mov edx,length ;length of message
但是,你如何打印從堆棧段的東西嗎?
我嘗試這樣做:
push 'H'
push 'e'
push 'l'
push 'l'
push 'o'
push ' '
push 'w'
push 'o'
push 'r'
push 'l'
push 'd'
mov eax,4 ;system call number
mov ebx,0 ;file descriptor
mov ecx,ebp ;adress of message
mov edx,11 ;length of message
但不打印任何東西。
編輯:我做了一些改變,我的代碼,現在是這樣:
section .data
msg: db "Hola mundo",0Ah
ok: db "OK",0Ah
section .text
global _start
_start:
push 'leH'
push 'w ol'
push 'dlro'
mov eax,4 ;system call number
mov ebx,1 ;file descriptor
mov ecx,esp ;adress of message in data segment
mov edx,11 ;length of message
mov eax,1
xor ebx,ebx ;same as move ebx,0 but better
int 0x80
EDIT 2(仍然沒有工作)
section .data
msg: db "Hello world",0Ah
section .text
global _start
_start:
push 'leH'
push 'w ol'
push 'dlro'
mov eax,4 ;system call number
mov ebx,1 ;file descriptor
mov ecx,esp ;adress of message in data segment
mov edx,11 ;length of message
int 0x80
mov eax,1
xor ebx,ebx ;same as move ebx,0 but better
int 0x80
迴應的評論,我組裝和編譯:
nasm -f elf64 hello.asm && ld hello.o && ./a.out
我正在使用Ubuntu 64位Linux。
'ebp'不是堆棧指針,'esp'是。此外,'push'將使用每個字符4個字節,這樣就不會起作用。 – Jester
更不用說使用'push'會反轉你的字符串。 – Jester
@Jester字符串的反轉是我想測試的東西 –