16/32bit hello world

Continuation of the MASM book. Built 16/32bit exe.


.model small

end_process macro ret_value
            mov   al, ret_value
            mov   ah, 4ch
            int   21h

display     macro string
            mov   dx, offset string
            mov   ah, 09h
            int   21h

; AL <- keycode
read_kbd    macro
            mov   ah, 08h
            int   21h

MSG         db 'Hello 16bit world.', 0dh, 0ah, '$'
MSG2        db '(hit any key).', 0dh, 0ah, '$'
MSGKEY      db '" " typed.', 0dh, 0ah, '$'

            mov   ax, _DATA
            mov   ds, ax

            display     MSG   ; Display message
            display     MSG2  ; Display message
            read_kbd          ; Wait for input

            mov [MSGKEY+1], AL
            mov BX, offset MSGKEY
            display     MSGKEY   ; Display
            end_process 0     ; exit

end START ; end


; for pentium
.model flat, stdcall
; ExitProcess != exitprocess with the option
option casemap:none

NULL            EQU 0
MB_OK           EQU 0
NUM             EQU 1

wsprintfA       proto c :dword, :dword, :dword, :dword, :dword
MessageBoxA     proto :dword, :dword, :dword, :dword
ExitProcess     proto :dword


TITLE0          DB 'Assembler Test', 0
MESSAGE         DB 'Hello 32bit world!', 0
BUFFER          DB 64 DUP(0)

WinMainCRTStartup   proc
    mov eax, NUM
    mov ecx, 10

    mov ebx, eax
    add eax, ebx
    dec ecx
    jnz MYLOOP

    ; offset -> address of the variable
    invoke MessageBoxA, NULL, offset MESSAGE, offset TITLE0, MB_OK
    invoke ExitProcess, 0

WinMainCRTStartup   endp


HELLO16 = hello16.exe
HELLO32 = hello32.exe

HELLO16OBJS = hello16.obj
HELLO32OBJS = hello32.obj

LDFLAGS = /LIBPATH:"C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib" /LIBPATH:"C:\Program Files\Microsoft Visual Studio 10.0\VC\lib"

hello16 : $(HELLO16OBJS)
	link16 $(HELLO16OBJS),$(HELLO16);

hello32 : $(HELLO32OBJS)
	link /NOLOGO /SUBSYSTEM:WINDOWS $(HELLO32OBJS) $(LDFLAGS) kernel32.lib user32.lib /OUT:$(HELLO32)
	del /f *.obj *.o *.exe *.lst

.SUFFIXES: .a16 .asm .obj

	ml /c /Fl $<

	ml /c /coff /Cp /nologo /Fl $< /Zi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.