使用msdn api在装配体中打印Hello World

时间:2018-11-26 07:45:10

标签: assembly x86 masm msdn

我今天才开始学习汇编语言,而且我正在使用masm。我尝试使用msdn api打印问候世界

这是我的代码:

1 .386
2 .model flat, stdcall
3 option casemap :none
4
5 include \masm32\include\kernel32.inc
6 include \masm32\include\masm32.inc
7 includelib \masm32\lib\kernel32.lib
8 includelib \masm32\lib\masm32.lib
9
10 .data
11 stroutput db "Hello World",0
12
13 .code
14 main:
15      push stroutput
16      call printf                    ; print hello world
17      add esp, 4
18      end main

但我遇到了错误:

  

hello.asm(15):错误A2070:无效的指令操作数
  hello.asm(16):错误A2006:未定义符号:_printf

编辑,我尝试根据以下建议修改代码:

.686
.model flat, stdcall

EXTERN printf : proc

include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib    
includelib \masm32\lib\user32.lib

.data
msgCaption db 'Try', 0

.code
Main:                      
push offset msgCaption  
call printf
push eax       

End Main

,但仍然出现错误: hello.obj:错误LNK2001:无法解析的外部符号_printf

0 个答案:

没有答案