News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

in masm32 two sums

Started by Xor Stance, March 12, 2005, 12:38:58 AM

Previous topic - Next topic

Xor Stance

I wonder how should I make GUI like the calculator from windows; or just a _____ two type two numbers with GUI.

I have a little knowledge on how
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib            ; calls to functions in user32.lib and kernel32.lib
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

.DATA                     ; initialized data
ClassName db "SimpleWinClass",0        ; the name of our window class
AppName db "Our First Window",0        ; the name of our window
MsgBoxCaption db "Mathematic",0
MsgBoxText db "Again",0
MsgBoxText db "Cancel",0


                                       
;I need here a gui like this a square with a line to input with the instruction

.DATA?                ; Uninitialized data
hInstance HINSTANCE ?        ; Instance handle of our program
CommandLine LPSTR ?
.CODE                ; Here begins our code
start:
invoke GetModuleHandle, NULL            ; get the instance handle of our program.
                                                                       ; Under Win32, hmodule==hinstance mov hInstance,eax
mov hInstance,eax
invoke GetCommandLine                        ; get the command line. You don't have to call this function IF
                                                                       ; your program doesn't process the command line.
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT        ; call the main function
invoke ExitProcess, eax                           ; quit our program. The exit code is returned in eax from WinMain.

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL wc:WNDCLASSEX                                            ; create local variables on stack
    LOCAL msg:MSG
    LOCAL hwnd:HWND

    mov   wc.cbSize,SIZEOF WNDCLASSEX                   ; fill values in members of wc
    mov   wc.style, CS_HREDRAW or CS_VREDRAW
    mov   wc.lpfnWndProc, OFFSET WndProc
    mov   wc.cbClsExtra,NULL
    mov   wc.cbWndExtra,NULL
    push  hInstance
    pop   wc.hInstance
    mov   wc.hbrBackground,COLOR_WINDOW+1
    mov   wc.lpszMenuName,NULL
    mov   wc.lpszClassName,OFFSET ClassName
    invoke LoadIcon,NULL,IDI_APPLICATION
    mov   wc.hIcon,eax
    mov   wc.hIconSm,eax
    invoke LoadCursor,NULL,IDC_ARROW
    mov   wc.hCursor,eax
    invoke RegisterClassEx, addr wc                       ; register our window class
    invoke CreateWindowEx,NULL,\
                ADDR ClassName,\
                ADDR AppName,\
                WS_OVERLAPPEDWINDOW,\
                CW_USEDEFAULT,\
                CW_USEDEFAULT,\
                CW_USEDEFAULT,\
                CW_USEDEFAULT,\
                NULL,\
                NULL,\
                hInst,\
                NULL
    mov   hwnd,eax
    invoke ShowWindow, hwnd,CmdShow               ; display our window on desktop
    invoke UpdateWindow, hwnd                                 ; refresh the client area

    .WHILE TRUE                                                         ; Enter message loop
                invoke GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                invoke TranslateMessage, ADDR msg
                invoke DispatchMessage, ADDR msg
   .ENDW
    mov     eax,msg.wParam                                            ; return exit code in eax
    ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    .IF uMsg==WM_DESTROY                           ; if the user closes our window
        invoke PostQuitMessage,NULL             ; quit our application
    .ELSE
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam     ; Default message processing
        ret
    .ENDIF
WinMain endp

invoke Msg,NULL,addr MsgBoxText,addr MsgBoxText,addr MsgBoxCaption,MB_OK  ;I invoke that square thing

mov eax,ecx

addr eax+1, addr eax-1, addr eax*1,addr eax/1

xor eax,eax
    ret
WndProc endp

end start


I wonder which instructions are use to create a little square in a window; to operate the operations. And how the body will be organize,
I wanted to use parent and child windows for every change in an operation then return to the main menu for it, last year I practice all that without reading anything but I didn't pay that much attention to it,
but only a few times. So I know some more advance in information. The body of "addr" wasn't it like add from the 16-bits?

Thanks in advance.

AeroASM

It will be easier with a dialog; download a Dialog Editor and read Iczelion's tutorial number 10.

sluggy

Xor,
from your WndProc procedure onwards your code is all screwed up, also notice that you have two "WinMain endp" statements....

Xor Stance

I was trying to create another window but I comitted the mistake. I don't really know I'm going to build it, I wonder if in Win32 you use INC and
DEC. I will try to investigate in the Win32API; since I haven't done it.

pbrennick

Char,
Perhaps you are confused, INC and DEC are opcodes, 40 and 48 are the hex values.  There will not be anything in the API as pertains to these opcodes.


DEC - Decrement
        Usage:  DEC     dest
        Modifies flags: AF OF PF SF ZF
        Unsigned binary subtraction of one from the destination.
                                 Clocks                 Size
        Operands         808x  286   386   486          Bytes
        reg8              3     2     2     1             2
        mem             15+EA   7     6     3            2-4

        reg16/32          3     2     2     1             1

        FE /1 DEC r/m8 Decrement r/m8 by 1
        FF /1 DEC r/m16 Decrement r/m16 by 1
        FF /1 DEC r/m32 Decrement r/m32 by 1
        48+rw DEC r16 Decrement r16 by 1
        48+rd DEC r32 Decrement r32 by 1

INC - Increment
        Usage:  INC     dest
        Modifies flags: AF OF PF SF ZF
        Adds one to destination unsigned binary operand.
                                 Clocks                 Size
        Operands         808x  286   386   486          Bytes
        reg8              3     2     2     1             2
        reg16             3     2     2     1             1

        reg32             3     2     2     1             1
        mem            15+EA    7     6     3            2-4  (W88=23+EA)

        FE /0 INC r/m8 Increment r/m byte by 1
        FF /0 INC r/m16 Increment r/m word by 1
        FF /0 INC r/m32 Increment r/m doubleword by 1

        40+ rw INC r16 Increment word register by 1
        40+ rd INC r32 Increment doubleword register by 1


Paul

Xor Stance

#5
If in 32 bits? We move the eax to the ecx; then we use inc, dec, mul, div,^ power and I don't know for root. After I create the window then I don't care righ now about child windows.

code from the window

Do I implement another code here? Or I must use endw then which code goes there for a little square to operate the options with a menu from
1. to 6. I'm using right now the window as a template code, I haven't memorize it well but I do understand more or less which instructions is use for. Since I read from Iczelion that you can use it for now as a template code then later you can learn in advance. That's why I wanted to operate some code.

After I move acc to cntr, I can use the push and pop to do optimization without the need of loop or best if I use only registers?
I wonder if this is correct.

Or I can use:

Menu:

mov eax,1
mov ecx,2
inc eax
dec eax
mult eax
div eax
^2 eax
sqr eax

loop Menu //loop label menu again

.data
MsgText db "1. plus",0
MsgText db "2. minus",0
MsgText db "3.mult",0
MsgText db "4.div",0
MsgText db "5.power",0
MsgText db "6.root",0

invoke

Please can anyone put a complete code doesn't have to be optimize just I'm trying to learn.

Anoter thing, since I now what does push and pop does: with a balance stack will be appreciated.




Mark Jones

Xor, read in your MASM32\help folder, a file called ASMINTRO.hlp. I found this to be very educational. :)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Xor Stance

I already know all that, the only thing I haven't check it before. To use Inc and AL pentium processors rather than Stosb and Losb and some syntax that it help me thanks for the loop. I wonder how can I build my desire code? Thanks if you can help me, if you can't please don't reply.

pbrennick

Char,
This is a complete calculator attached.  Parts are by me and parts courtesy Ewayne.  You can also download his version from his website.

Paul


[attachment deleted by admin]

Xor Stance

Thanks Pbrennick that was I looking for.

pbrennick

Char,
Just so you know, and anybody else, both Ewayne and myself put no restrictions on the software we produce.  You may use it in any way you see fit.

Paul

Xor Stance

Just a quick overview tomorrow I have my exams of math; I have the time right now to update my Phycics Documentation since, handling roots and I know an extra advance math I learnt from myself. I name it Physics since I thought I was going to teach it and it uses math and then I thought my friend has produced a tool like that if you check that. I read that you're going to use time like Physics; I think you can check my friend's tool http://tian2992.tk/ However, I think you can get code to see it; but I guess you already know this concepts.
My documentation will provide at a professional level preparing very easy to handling it to me. I can write short tutorials and easy ones without the explicit complication of explaining something of waste of time. LOL