Assembly Language for Beginners

(Jeff_L) #1

3.29. WINDOWS 16-BIT


Couple important things here: thePASCALcalling convention dictates passing the first argument first
(MB_YESNOCANCEL), and the last argument—last (NULL). This convention also tells thecalleeto restore
thestack pointer: hence theRETNinstruction has0Ah as argument, which implies that the pointer has to
be increased by 10 bytes when the function exits. It is like stdcall (6.1.2 on page 734), but the arguments
are passed in “natural” order.


The pointers are passed in pairs: first the data segment is passed, then the pointer inside the segment.
There is only one segment in this example, soDSalways points to the data segment of the executable.


3.29.3 Example #3.


#include <windows.h>


int PASCAL WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
int result=MessageBox (NULL, "hello, world", "caption", MB_YESNOCANCEL);


if (result==IDCANCEL)
MessageBox (NULL, "you pressed cancel", "caption", MB_OK);
else if (result==IDYES)
MessageBox (NULL, "you pressed yes", "caption", MB_OK);
else if (result==IDNO)
MessageBox (NULL, "you pressed no", "caption", MB_OK);

return 0;
};


WinMain proc near
push bp
mov bp, sp
xor ax, ax ; NULL
push ax
push ds
mov ax, offset aHelloWorld ; "hello, world"
push ax
push ds
mov ax, offset aCaption ; "caption"
push ax
mov ax, 3 ; MB_YESNOCANCEL
push ax
call MESSAGEBOX
cmp ax, 2 ; IDCANCEL
jnz short loc_2F
xor ax, ax
push ax
push ds
mov ax, offset aYouPressedCanc ; "you pressed cancel"
jmp short loc_49
loc_2F:
cmp ax, 6 ; IDYES
jnz short loc_3D
xor ax, ax
push ax
push ds
mov ax, offset aYouPressedYes ; "you pressed yes"
jmp short loc_49
loc_3D:
cmp ax, 7 ; IDNO
jnz short loc_57
xor ax, ax
push ax
push ds
mov ax, offset aYouPressedNo ; "you pressed no"
loc_49:
push ax

Free download pdf