News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

x86 Assembly Language Sample Application

Started by hifiger, October 25, 2015, 11:41:53 AM

Previous topic - Next topic

hifiger

Hi Guys,

This is my very first time joining MASM forum and I really need your help. Please
And I know that Assembly language for you guys is very easy. For me it's very hard. I've done many projects, but not with Assembly :-)
So I was given a very limited time to work on a certain application in Assembly language. The specs are not yet given, so I still have time to ask you for some help.

Where could I download a free sample windows7 applications develop in Assembly masm32 with source code.

I am thinking by starting myself like - if how would I do the following in masm32:
1.) Enter fullname
2.) Enter Height (with input textbox Feet and input textbox Inches)
3.) Enter Weight (with input textbox lb(pound))
4.) Calculate Button - clicking this button will convert feet and height to cm, then weight to Kg
5.) Close Button - clicking this button will close the form

Result:
    Name:  Hifiger
    Height: 5'9"  =  175cm
    Weight: 185lb = 83.9146

I hope you can give me a sample code for this one with some comments on the code.

And maybe I will just start from here by studying what you can give me.

Thanks in advance.

Hifiger

hutch--

Well, show us what you have written and we may be able to help you. What we will not do is write it for you.

gelatine1

If this is your first time working with assembly I think it would be too much at once and I believe it would be better if you started with checking out some hello world program. Then you could check out iczelions tutorial on creating windows programs. Then you might be able to actually write what you've asked for.
Also don't forget there are some examples in masm32/examples directory.

GoneFishing

Hello and welcome to the forum , hifigure !
You've found the right place  - here you'll get help not only with assembly language  ;)
Looking at your input data my first notice was : you certainly have about 8-9 kg of excess weight . It's not that much but it's already the time to think about it  :t
Take care
 
P.S.: to help you to get started with dialog window look in \masm32\examples\dialogs_later\gettext folder .   

jj2007

Here is a little example, your teacher will love it :badgrin:

include \masm32\MasmBasic\MasmBasic.inc           ; download
  Init
  DlgDefine "Please enter your data, tab for next line:", 0, 0, 150, -6, , 12            ; x, y ignored, 150 wide, 4 lines, blank, font size 12
  DlgControl dcEdit,      "Hifiger", WS_BORDER or WS_TABSTOP, 1, -2            ; first control gets the focus; this is the 2nd line
  DlgControl dcEdit,      "5'9''", WS_BORDER or WS_TABSTOP, 1, -4                  ; x, y only, the macro will assign width, height and ID
  DlgControl dcEdit,      "185 lb", WS_BORDER or WS_TABSTOP, 1, -6            ; x, y only, the macro will assign width, height and ID
  DlgControl dcStatic,      "Type your first name:", SS_LEFT, 1, -1, 70.0                       ; 70 means 70% - the buttons need space; line 1
  DlgControl dcButton,      "OK", BS_DEFPUSHBUTTON or WS_TABSTOP, 71.0, -1, 12.0, , IDOK           ; x=71%, y, width=14%, height, ID
  DlgControl dcButton,      "Quit", BS_PUSHBUTTON or WS_TABSTOP, 84.0, -1, 16.0, , IDCANCEL
  DlgControl dcStatic,      "Type your height", SS_LEFT, 1, -3
  DlgControl dcStatic,      "Type your weight", SS_LEFT, 1, -5
  DlgShow
  .if eax==IDOK
      Let edi=Replace$(Utf8$(Dlg$(1)), "'", " ")
      imul ecx, Val(edi), 3040
      add edx, edi
      imul eax, Val(edx), 254
      add ecx, eax
      Let edi=Utf8$(Dlg$(2))
      MsgBox 0, Cat$("The person "+Utf8$(Dlg$(0))+Str$("\nis %4f cm tall ", ecx/100)+Str$("\nand weighs %4f kg", Val(edi)*0.4536)), "Hi", MB_OK
  .endif
  EndOfCode

GoneFishing

#5
I know how difficult are dialoges for a beginner.
I adapted gettext MASM32 example  .  Conversion of input values and  showing new values is left to you  ;)
Also you should have to add input checking routines
Uses plain MASM32 . Tested on Win XP SP3 32

[EDIT]: file hifiger.asm ,line 14 contains a typo
should be:
mytitle  db " Results :",0

hutch--

Guys,

Please remember the "No Homework" rule. This guy has made 1 post asking other people to write his homework for him. Supply examples for him without him making any effort and you have done his homework for him.

dedndave

i hope we get an A   :lol:

these guys won't know shit when they get into the real world   :P

dedndave

in truth, i blame the instructors and the education system, itself
they often place instructors that have no knowledge of the subject
the system also selects a book that is often inadequate
the instructor says, "here's the book, here's the assignment", and there's no classroom discussion whatsoever
you can't toss a guy into the deep end of assembly language like that - lol

a few of us were lucky, because we had some background before entering college
that's not a very good expectation, though

jj2007

Quote from: dedndave on October 26, 2015, 11:16:30 AM
in truth, i blame the instructors and the education system, itself

I don't really know... perhaps the truth is much simpler: an instructor who fights for keeping assembler on the agenda, and a bunch of students who think "hey old fart, why do you want to push that 19th century crap down our throat?". And they hope that here in this forum they find enough old farts who save them when they realise that their votes depend on the old crap :greensml:

hifiger

Thank you Guys.
And by the way, this is not a homework. I am already a programmer and wanted to try the assembly language. It is a different world for me :-)

GoneFishing, your sample code is an eye opener for me knowing who really assembly is :-) Not quite know it well, but at least it's a very good start up for me.  You know, I am a .Net programmer, and seeing the .asm source, my first impression is that - this assembly language is not for lazy people. :-)

Anyways, I actually able to add a conversion into your code, but I know that this is not the ultimate solution. I am just new. So forgive me :-)

Here is the code you gave me, which I modified by adding the conversion:  :biggrin:

==========================================================


    include \masm32\include\masm32rt.inc
   include \masm32\include\dialogs.inc
     
    dlgproc PROTO :DWORD,:DWORD,:DWORD,:DWORD
    GetTextDialog PROTO :DWORD,:DWORD

.data?
      hInstance dd ?   
.data
       frm db " Name: %s",13,10
          db " Height: %d'%d'' = %d.%d cm",13,10
          db " Weight: %d lbs = %d.%d Kg",0
       mytitle  db " Relults :",0            
.code

start:
    mov hInstance, rv(GetModuleHandle,NULL)
    call main
    invoke ExitProcess,eax


main proc

    LOCAL ptxt  :DWORD     ;variable declaration
    LOCAL hIcon :DWORD

    invoke InitCommonControls   ;this will initialize the common controls

    mov hIcon, rv(LoadIcon,hInstance,10)

    mov ptxt, rv(GetTextDialog," ACLC WINDOWS APPLICATION"," Enter fullname ")

    .if ptxt != 0
      fn MessageBox,0,ptxt,"Title",MB_OK
    .endif

    invoke GlobalFree,ptxt

    ret

main endp


GetTextDialog proc dgltxt:DWORD,grptxt:DWORD

    LOCAL arg1[4]:DWORD
    LOCAL parg  :DWORD

    lea eax, arg1
    mov parg, eax

  ; ---------------------------------------
  ; load the array with the stack arguments
  ; ---------------------------------------
    mov ecx, dgltxt
    mov [eax], ecx
    mov ecx, grptxt
    mov [eax+4], ecx
 
    Dialog "Get User Text", \               ; caption
           "Arial",8, \                     ; font,pointsize
            WS_OVERLAPPED or \              ; styles for
            WS_SYSMENU or DS_CENTER, \      ; dialog window
            9, \                            ; number of controls
            50,50,162,170, \                ; x y co-ordinates
            4096                            ; memory buffer size

    DlgGroup  " Enter fullname ",8,4,140,31,300
    DlgEdit   ES_LEFT or WS_BORDER or WS_TABSTOP,17,16,121,11,301
   DlgGroup  " Enter Height : Feet   Inches",8,40,140,31,302
    DlgEdit   ES_LEFT or WS_BORDER or WS_TABSTOP,17,52,57,11,303
   DlgEdit   ES_LEFT or WS_BORDER or WS_TABSTOP,80,52,57,11,304
    DlgGroup  " Enter Weight : lb(pounds)",8,76,140,31,305
    DlgEdit   ES_LEFT or WS_BORDER or WS_TABSTOP,17,88,121,11,306
   DlgButton "Display Info",WS_TABSTOP,8,120,70,13,IDOK
    DlgButton "Close",WS_TABSTOP,92,120,55,13,IDCANCEL

    CallModalDialog hInstance,0,dlgproc,parg

    ret

GetTextDialog endp

dlgproc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD


    LOCAL tlen  :DWORD
    LOCAL hName  :DWORD
    LOCAL hFeet  :DWORD
   LOCAL hInches  :DWORD
   LOCAL hWeight  :DWORD
   LOCAL Feet  :DWORD
   LOCAL Inches  :DWORD
   LOCAL Weight  :DWORD
    LOCAL buffer[260]:BYTE

    LOCAL heightCm: DWORD
    LOCAL heightCmDec: DWORD     

    LOCAL heightInches: DWORD
    LOCAL heightTotalInches :DWORD
    LOCAL tmpResult: DWORD

    LOCAL weightLb: DWORD
    LOCAL kgBase : DWORD
    LOCAL weightKg   : DWORD
    LOCAL weightKgDec   : DWORD

    switch uMsg
      case WM_INITDIALOG
      ; -------------------------------------------------
      ; get the arguments from the array passed in lParam
      ; -------------------------------------------------
        push esi
        mov esi, lParam
        fn SetWindowText,hWin,[esi]                         ; title text address
        fn SetWindowText,rv(GetDlgItem,hWin,300),[esi+4]    ; groupbox text
      
        xor eax, eax
        ret

      case WM_COMMAND
        switch wParam
          case IDOK
                mov tlen, rv(GetWindowTextLength,rv(GetDlgItem,hWin,301))
                cmp tlen , 0
             jne @F
                invoke SetFocus,rv(GetDlgItem,hWin,301)
                   ret
         @@:
             add tlen, 1
                mov hName, alloc(tlen)
                fn GetWindowText,rv(GetDlgItem,hWin,301),hName,tlen
             mov tlen, rv(GetWindowTextLength,rv(GetDlgItem,hWin,303))
             cmp tlen , 0
             jne @F
                invoke SetFocus,rv(GetDlgItem,hWin,303)
               ret
           @@:
             add tlen, 1
                mov hFeet, alloc(tlen)
                fn GetWindowText,rv(GetDlgItem,hWin,303),hFeet,tlen
            mov tlen, rv(GetWindowTextLength,rv(GetDlgItem,hWin,304))
            cmp tlen , 0
             jne @F
                  invoke SetFocus,rv(GetDlgItem,hWin,304)
                 ret
           @@:     
                add tlen, 1
            mov hInches, alloc(tlen)
                fn GetWindowText,rv(GetDlgItem,hWin,304),hInches,tlen   
                mov tlen, rv(GetWindowTextLength,rv(GetDlgItem,hWin,306))
             cmp tlen , 0
             jne @F
                 invoke SetFocus,rv(GetDlgItem,hWin,306)
                ret
         @@:    
                add tlen, 1
            mov hWeight, alloc(tlen)
                fn GetWindowText,rv(GetDlgItem,hWin,306),hWeight,tlen

                invoke atol, hFeet            
                        mov Feet,eax

            invoke atol, hInches 
            mov Inches,eax

                        ;******** Begin: Conversion of Height to Cm ********
                        mov eax, Feet
                        mov ebx, 12                 ;12 inches per one foot
                        mul ebx

                        mov heightInches, eax       ; heightInches = eax (feet input * 12 inches)

                        mov ebx, Inches             ; ebx = Inches
                        add eax, ebx                ; eax = eax(heightInches) + ebx(Inches)
                        mov heightTotalInches, eax  ; eax(heightTotalInches) = eax(heightInches) + ebx (Inches)

                        mov eax, heightTotalInches
                        mov ebx, 254                ; ebx = 254
                        mul ebx                     ; eax = inches * 254

                        ;mov tmpResult, eax         ; tmpResult = inchex * 254
                        mov ebx, 100                ; ebx = 100
                        div ebx                     ; eax = tmpResult/100

                        mov heightCm, eax           ; eax = whole number result of (eax = tmpResult/100)
                        mov heightCmDec, edx        ; edx = remainder result of (eax = tmpResult/100)
                        ;******** End: Conversion of Height to Cm ********

                       
                        ;******** Begin: Conversion of pound(lb) to Kilogram(Kg) *********
                       
            invoke atol, hWeight
                        mov weightLb, eax

                        mov kgBase, 4536             ;kgBase = 0.4536 is the base for computing pount(lb) to Kilogram(kg)
                        mov ebx, kgBase              ;ebx = KgBase
                        mul ebx                      ;eax = eax(hWeight) * ebx(0.45)

                        mov ebx, 10000               ;ebx = 10000: to get the whole number and remainder
                        div ebx                      ;eax = eax/10000:  the whole number will be stored in eax. And the remainder will be stored in adx

                        mov weightKg, eax            ;whole number
                        mov weightKgDec, edx         ;remainder

            invoke wsprintf, addr buffer,addr frm,
                                         hName,Feet,Inches,heightCm,heightCmDec,weightLb,weightKg,weightKgDec
                                         
                        ;******** End: Conversion of pound(lb) to Kilogram(Kg) *********
                                         

                ; show Results             
              invoke MessageBox,0, addr buffer, addr mytitle, MB_OK
     
          case IDCANCEL
            invoke EndDialog,hWin,0
        endsw
      case WM_CLOSE
        invoke EndDialog,hWin,0
    endsw

    xor eax, eax
    ret

dlgproc endp

end start

=====================================================================


thank you GoneFishing

GoneFishing

#11
You're welcome, hifiger
[EDIT]: BTW what is ACLC ? I've found several possible variants on internet   
Some notes on possible optimizations in my code:
as it is now :

   invoke atol, hFeet           
   mov Feet,eax

better:

mov Feet, rv( atol, hFeet)
mov Inches, rv( atol, hInches)
mov Weight, rv( atol, hWeight)


With every little proggie that I write I re-discover the power of assembly language and the power of MASM32 SDK which is perfect starting point for a beginner .  Please notice extensive use of macros which  simplify  our life.
I consider myself as extremly lazy person but sometimes I wake up from hybernation for having some fun: learning , programming little by little etc  :biggrin:   

P.S.: tested - it compiles and works  :t
Further improvments: check for valid input ( use masked edit control ?)
-----------------------------------------------------------------------------------------------
BTW Do anybody remember what is the name of MASM32 example with masked edit control ?
[EDIT]:  I see ... it's hard to remember unexisting thing.

GoneFishing

#12
Good news!
Thanks to this thread Numeric edit controls that accept negative #s we can set our edit controls to accept only numeric input .
We are going to add ES_NUMBER flag to the Height and Weight edit conrols.
Change this code :

DlgGroup  " Enter Height : Feet   Inches",8,40,140,31,302
DlgEdit   ES_LEFT or WS_BORDER or WS_TABSTOP,17,52,57,11,303
DlgEdit   ES_LEFT or WS_BORDER or WS_TABSTOP,80,52,57,11,304
DlgGroup  " Enter Weight : lb(pounds)",8,76,140,31,305
DlgEdit   ES_LEFT or WS_BORDER or WS_TABSTOP,17,88,121,11,306

to this:
Quote
DlgGroup  " Enter Height : Feet   Inches",8,40,140,31,302
DlgEdit    ES_NUMBER or ES_LEFT or WS_BORDER or WS_TABSTOP,17,52,57,11,303
DlgEdit    ES_NUMBER or ES_LEFT or WS_BORDER or WS_TABSTOP,80,52,57,11,304
DlgGroup  " Enter Weight : lb(pounds)",8,76,140,31,305
DlgEdit    ES_NUMBER or ES_LEFT or WS_BORDER or WS_TABSTOP,17,88,121,11,306

Now let's think about if we should add limits to Height/Weight input .

New version is now available!
Changes:
-- added status bar
-- Height / Weight edit controls accept only numerical input
-- Height is limited to 9'99'' which is pretty enough for our extraterrestrial friends
-- Weight is limited to 999 lbs
-- added  Intelligent Guidance System

See attachment below