2013년 3월 13일 수요일

[asm]win32 helloworld

.386
.MODEL flat, stdcall
.STACK 4096


;include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib


STD_OUTPUT_HANDLE EQU -11

GetStdHandle PROTO,
  nStdHandle:DWORD

WriteConsole EQU 

ExitProcess PROTO,
 dwExitCode:DWORD

.data
consoleOutHandle dd ?
bytesWritten   dd ?
message db "Hello World", 13, 10, 0

.code
ProcStrLength PROC USES edi,
    ptrString:PTR BYTE
 mov edi, ptrString
 mov eax, 0
L1:
 cmp byte ptr [edi], 0
 je  L2
 inc edi
 inc eax
 jmp L1
L2: ret
procStrLength ENDP

ProcWriteString proc
 pushad

 INVOKE procStrLength, edx
 cld

 INVOKE WriteConsole,
     consoleOutHandle,
     edx,
     eax,
     offset bytesWritten,
     0
 
 popad
 ret
procWriteString endp

main PROC
 INVOKE GetStdHandle, STD_OUTPUT_HANDLE

 mov [consoleOutHandle], eax

 mov edx, offset message

 INVOKE procWriteString

 INVOKE ExitProcess, 0

main ENDP

END main



compile ml /c /coff link link /subsytem:console

댓글 없음:

댓글 쓰기