Visual Studio 2019-MASM-32位程序集-Hello World程序、Visual、Studio、MASM

2023-09-03 14:56:29 作者:经典的

我通过&MIPS汇编语言学习了汇编语言编程的概念。 我写了几个程序,像斐波那契,堆栈相关的东西等等。 现在,我要介绍用于.386指令集的下一级32位Windows程序集。

这是我已经拥有的。

.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, deExitCode:DWORD

.data
msg db "Hello, World!", 0

.code

main PROC


    INVOKE ExitProcess, 0
main ENDP
END main
但是,如何调用像print_string这样的系统函数呢?我真的不知所措。 我尝试了几个相关的SO答案,但它们使用NASM,因此它不适用于我。

推荐答案

vs2017中文旗舰版下载 visual studio 2017下载 官方中文旗舰版

这是一个基本的Win32控制台模式HelloWorld!ASM程序,将使用MASM615编译,并在我的Win10 64位系统上运行。您可以参考作者的网站了解任何更改(如果有),以使其使用VS2019等编译。

; 32-Bit Intel Protected Mode Programming
; KIP IRVINE Assembly Language for x86 / Intel-Based Computers. 
;

.386
.model flat,stdcall
.stack 4096

; DEFINE/DECLARE necessary WIN32 constants, functions etc.
;------------------------------------------------------------
; Win32 Console handles
STD_OUTPUT_HANDLE EQU -11       ; predefined Win API constant


; ALIAS  : The following Win32 API functions have an
; extra "A" at the end of their name, 
; so they are redefined here with text macros:
WriteConsole EQU <WriteConsoleA>


;                   FUNCTION PROTOTYPES
; -------------------------------------------------------------
ExitProcess PROTO,          ; exit program
    dwExitCode:DWORD        ; return code


GetStdHandle PROTO,         ; get standard handle
    nStdHandle:DWORD        ; type of console handle


WriteConsole PROTO,                 ; write a buffer to the console
    handle:DWORD,                   ; output handle
    lpBuffer:PTR BYTE,              ; pointer to buffer
    nNumberOfBytesToWrite:DWORD,    ; size of buffer
    lpNumberOfBytesWritten:PTR DWORD,   ; num bytes written
    lpReserved:DWORD                    ; (not used)

; User Defined Data Section
; ---------------------------------------------------------------
.data
mesg1               BYTE    "Hello world!",0dh,0ah,0
sizeMesg1           = ($-mesg1)-1       ; ex-cluding the sign bit
BytesWritten        DWORD   0
ConsoleOutHandle    DWORD   0

.code
main proc
    
    ; Get Standart Output Handle
    INVOKE GetStdHandle, STD_OUTPUT_HANDLE  ; Get a handle to console SCREEN.
    mov ConsoleOutHandle, eax
    
    ; Write Message to the Handle => CONSOLE
    INVOKE WriteConsole, ConsoleOutHandle, ADDR mesg1, (LENGTHOF mesg1)-1, ADDR BytesWritten, 0
    
    
    invoke ExitProcess,0
main endp
;-------------------------------------------------------------------

end main
 
精彩推荐
图片推荐