Assembly (NASM)問題

本帖最後由 luckiejacky 於 2016-8-16 13:49 編輯
  1. SECTION .data

  2. msg: db "Hello world, this is assembly",10,0


  3. SECTION .text

  4. extern _printf
  5. global main

  6. main:
  7.         push ebp
  8.         mov ebp, esp
  9.        
  10.         push msg
  11.         call _printf
  12.        
  13.         mov esp, ebp
  14.         pop ebp
  15.         ret
複製代碼
Assembled with
  1. nasm -f win32 -o test_asm.obj test_asm.asm
  2. link test_asm.obj kernel32.lib libcmt.lib /SUBSYSTEM:Console /EntryPoint:main
複製代碼
但系一Run就Crash?

http://www.idabook.com/scripts/generate_nasm.idc

用緊Lee條script,但佢唔會自動generate data variables?
  1. sub_1015CD_.asm:8: error: symbol `aCommdlg_coloro' undefined
  2. sub_1015CD_.asm:9: error: symbol `__imp__RegisterWindowMessageW@4' undefined
  3. sub_1015CD_.asm:10: error: symbol `dword_1040508' undefined
  4. sub_1015CD_.asm:13: error: symbol `aCommdlg_setrgb' undefined
  5. sub_1015CD_.asm:14: error: symbol `__imp__RegisterWindowMessageW@4' undefined
  6. sub_1015CD_.asm:15: error: symbol `dword_104050C' undefined
複製代碼

TOP

沒用過nasm, 但可能同calling convention有關, printf calling convention係cdecl, push parameter 由右到左, caller 要還原esp , 但printf 是variable argument, 不知有沒有特別不同.

其他常見的calling convention : stdcall, fastcall, pascal, thiscall.

TOP

會不會是第15行 push msg後,在第19行pop 錯?

TOP