News:

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

The task to the school

Started by dawidekz, February 01, 2009, 06:37:24 PM

Previous topic - Next topic

kromag

Quote from: MichaelW on February 05, 2009, 09:26:50 PM
Try posting your source, otherwise we are just guessing at what the problem might be.

Regards,

William.

dawidekz

I have only the programme to which I gave link (first.zip). and I would like to connect this with the code from raymond.
I do not know as to do:
- taking given a, b, c
- the calculation by procedure raymond
- the displaying of the result

I do not have anything except first.asm and code inserted by raymond and d0d0

PBrennick

Do you have any experience with displaying results? As to adding Raymonds procedure - copy and paste? What to do next?

1. You need to ask the user for values to be converted.
2. You need to invoke the QuadRoots procedure using a, b and c values (that were input).
3. Display the results on the screen.

Notes: You could do this easily as a console app but if you decide to use a GUI, you will need to create a dialog box with 3 boxes for data entry, one (or two) box(es) for the results. An Okay button and a Close button at a minimum. I mention this because you mentioned winapi.

Have you written any programs before?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

kromag

dawidekz: I meant that not all of us can download a file; sorry.

    So, if you perhaps posted the source, giving the problem, in text form others might be able to help.
---

William

dawidekz

the programme has to be in GUI
I two years ago was on school assembler in the console, but in GUI not. I store from the console also little
I anything from this don't remember in this moment :/ (from assembler) and I have to give back the programme to pass the subject..
I copy and paste, and I do not know any then more to do, to put together what this in the whole


Quote from: PBrennick on February 08, 2009, 08:11:09 PM
Do you have any experience with displaying results? As to adding Raymonds procedure - copy and paste? What to do next?

1. You need to ask the user for values to be converted.
2. You need to invoke the QuadRoots procedure using a, b and c values (that were input).
3. Display the results on the screen.

Notes: You could do this easily as a console app but if you decide to use a GUI, you will need to create a dialog box with 3 boxes for data entry, one (or two) box(es) for the results. An Okay button and a Close button at a minimum. I mention this because you mentioned winapi.

Have you written any programs before?

Paul


PBrennick

Okay,
Look at the examples in masm32. Find one that involves using a dialog box. Edit the resource file so as to create the edit boxes as previously described. You would use GetDlgItemInt to get the user input from the 3 boxes and then invoke the QuadRoot procedure. Next you can use a couple of different ways to display the results in another edit box (or static).

for now, open win32.hlp and learn about GetDlgItemInt. Get a program up and running that gets you that far then we can talk again (if not me, then someone else.)

There are many examples you can rework to do this and you must do that yourself. Reworking code successfully to turn it to your own use is a good method of learning. It involves hand-eye-brain which is the best way to burn knowledge into your brain.

If you tell me you need to turn this in tomorrow ...

Paul
The GeneSys Project is available from:
The Repository or My crappy website

MichaelW

dawidekz,

For a dialog, there is an example that has a user interface similar to what Paul described, here:

\masm32\examples\exampl02\resdlg2

The example has 4 single-line edit controls and two buttons. It's just a shell that does not actually do anything with the user input, but it does give you a basic idea of how the dialog and code could be laid out.
eschew obfuscation

dawidekz

Well, step after step, I've resdlg2, now I would like to add numbers in edit and inscribe result in edit "result" (edit1+edit2+edit3=result)
How make it straight and fastly ?

Quote from: MichaelW on February 08, 2009, 09:34:59 PM
dawidekz,

For a dialog, there is an example that has a user interface similar to what Paul described, here:

\masm32\examples\exampl02\resdlg2

The example has 4 single-line edit controls and two buttons. It's just a shell that does not actually do anything with the user input, but it does give you a basic idea of how the dialog and code could be laid out.


MichaelW

Assuming that your inputs a, b, and c will be integers, I think you should modify the resource definitions for the first three edit controls adding the ES_NUMBER style so you will not have to deal with non-digits entered into the controls. See MSDN: Edit Control Styles. For the example dialog the dialog and the controls in it are defined in the resource definition file rsrc.rc. See MSDN: About Resource Files and MSDN: Resource-definition Statements. You can open the file in any text editor. The edit controls currently have the ES_AUTOHSCROLL and ES_LEFT styles. The "|" between the styles in an OR operator. Note that the file must be named rsrc.rc.

Assuming you wish to do the addition in response to the user clicking the calculate button, you will need to modify the handler for the calculate-button click event to get the inputs from the edit controls, perform the addition, and display the result. The handler for the calculate-button click event is the one that currently displays the "Calculate Button" message box. See MSDN: BN_CLICKED Notification. Note that the code can ignore the high-order word of wParam in this case because BN_CLICKED is defined as the value zero. I would do as Paul suggested and use the GetDlgItemInt Function to get the values of the a, b, and c inputs from the controls. The nIDDlgItem parameter should be the control ID for each of the controls, and these are defined in rsrc.rc as 100, 101, and 102.

Two possibilities for displaying the result are to convert it to a string and use the SetDlgItemText Function to copy the string to the result control, or convert it to an integer and use the SetDlgItemInt Function.

In case it's not clear how to build the application, you can load the source, resdlg2.asm or whatever you chose to name it, into Quick Editor and select Build All from the project menu. When you do so, QE should first run the resource compiler to compile rsrc.rc to rsrc.res, then the Resource To Object Converter to convert the compiled resource rsrc.res to the object module rsrc.obj, then ML to assemble the source file, then the linker to create the final EXE.
eschew obfuscation

dawidekz

I decided first to do the programme under DOS. the error appears me on compilation (TASM)

Turbo Assembler  Version 3.1  Copyright (c) 1988, 1992 Borland International

Assembling file:   rownanie.asm
**Error** rownanie.asm(62) Symbol already different kind: CYFRY
Error messages:    1
Warning messages:  None
Passes:            1
Remaining memory:  413k

source:

.486
dane SEGMENT use16
    wsp_a dd   ?,'$'
    wsp_b dd   ?,'$'
    wsp_c dd -15.0
Nap1   DB   "Podaj A ",'$'
Nap2   DB   "Podaj B ",'$'
crlf   DB   0Dh,0ah,'$'
adres   DW   ?,'$'
    dwa dd 2.0
    cztery dd 4.0
    x1 dd ?
    x2 dd ?
    d_uj_napis db "Wyznacznik jest ujemny!", 13, 10, "$"
    jed_wyn_napis db "Obliczono jedyny pierwiastek", 13, 10, "$"
    dwa_wyn_napis db "Obliczono oba pierwiastki", 13, 10, "$"
;zmienne do wypisywania liczb
    cyfry dw ?
    temp dd ?
    dziesiec dd 10.0
    jeden dd 1.0
    ctrl_wrd dw ?
    dziesietnie db "+", 40 dup (" ")
;;;
dane ENDS

program SEGMENT use16
    assume cs:program, ds:dane
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;wypisuje liczbe 32-bitowa zmiennoprzecinkowa
;edx - offset liczby
wyp_float PROC

   
   mov   wsp_b,0
   mov   wsp_a,0
   
   
   lea   dx,Nap1
   call   pisz
   
   call   wczytaj
   mov wsp_a,ebx
   
   lea   dx, crlf
   call   pisz
   
   lea   dx,Nap2
   call   pisz

   call   wczytaj
   mov wsp_b,ebx

   lea   dx, crlf
   call   pisz


wczytaj proc
   pop   adres
   mov   ebx, 0
cyfry:   
   mov   ah,1
   int   21h
   
   cmp   al,0dh
   je   dalej
   
   mov   edx,ebx
   add   ebx,edx
   xor   ah,ah
   sub   al,30h
   add   ebx,eax
   jmp   cyfry   
   
dalej:
      

   push   adres
   ret
wczytaj   endp
;--------------------------------------





    pushad
    pushf

pocz_wyp:
    fstcw ctrl_wrd
    bts ctrl_wrd, 10 ;ustawia 10. bit
    btr ctrl_wrd, 11 ;zeruje 10. bit
    fldcw ctrl_wrd ;ustawia zaokraglanie w dol

    fld jeden
    fld dziesiec
    fyl2x ;st(0) = lg2 (10)
    fld jeden
    fld DWORD PTR [edx] ;laduje liczbe na stos

;trzeba cos zrobic z ujemna
    ftst ;porownuje st(0) z zerem
    fstsw ax ;stan koprocesora do ax
    sahf ;flagi <-- ah <-- koprocesor

    ja nieujemna
    mov dziesietnie[0], "-"
    fchs ;zamiana znaku

nieujemna:
    fyl2x
    fdiv st(0), st(1) ;cyfry czesci calkowitej
    fist cyfry ;teraz juz gotowa wartosc calkowita
    fstp st(0) ;\
    fstp st(0) ; > wyczyszczenie stosu
    fld DWORD PTR [edx] ;/ i zaladowanie naszej liczby
   
    cmp dziesietnie[0], "-"
    jne nieujemna2
    fchs

nieujemna2:
    inc cyfry ;lepiej tu "zaokraglic" w gore, bo w dol
    mov cx, cyfry ;laduje licznik petli
    cmp cx, 0 ;jesli liczba < 1
    ja calk ;nie przeprowadza tej petli
    mov dziesietnie[0], "0"
    jmp ulamk

calk:
    fist temp ;czesc calkowita naszej liczby
    mov eax, DWORD PTR temp
    mov edi, 10 ;podstawa dziesietna

ptl_calk:
    mov edx, 0
    div edi
    mov bx, cx
    add dl, "0" ;zamiana na ASCII
    mov dziesietnie[bx], dl ;kolejna cyfra calkowita
    loop ptl_calk

ulamk:
    mov bx, cyfry
    inc bx
    mov dziesietnie[bx], "."
    fld dziesiec
    fxch ;st(0)=liczba, st(1)=10.0

ptl_ulamk:
    fist temp ;\
    fild temp ; > odjecie czesci calkowitej
    fsub st(1), st(0) ;/
    fstp st(0)

    inc bx ;index tablicy
    fmul st(0), st(1)
    fist temp ;\
    mov edx, temp ; \ kolejna cyfra ulamkowa
    add dl, "0" ; /
    mov dziesietnie[bx], dl ;/
   
    ftst ;porownuje st(0) z zerem
    fstsw ax ;stan koprocesora do ax
    sahf ;flagi <-- ah <-- koprocesor
    jnz ptl_ulamk ;jeszcze nie skonwertowal calej liczby

    inc bx
    mov dziesietnie[bx], 13 ;przygotowanie
    inc bx
    mov dziesietnie[bx], 10
    inc bx
    mov dziesietnie[bx], "$"
   
    mov dx, OFFSET dziesietnie ;i wypisanie
    mov ah, 09h
    int 21h

    fstp st(0)
    fstp st(0)

    popf
    popad
    ret

wyp_float ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

poczatek:
    push SEG dane
    pop ds

    finit
    fld wsp_b ;zaladowanie na wierzcholek stosu
    fld st(0) ;duplikacja b na stosie
    fmul st(0), st(0)
   
    fld cztery ;\
    fmul wsp_a ; \ d = b^2-4ac
    fmul wsp_c ; /
    fsub st(1), st(0) ;/

    fstp st(0) ;b^2 juz nie jest potrzebne
    ftst ;porownuje st(0) z zerem
    fstsw ax ;stan koprocesora do ax
    sahf ;flagi <-- ah <-- koprocesor
    jae d_nieujemna ;d >= 0
    jb d_ujemna ;d < 0

d_ujemna:
    mov dx, OFFSET d_uj_napis
    mov ah, 09h
    int 21h
    jmp koniec

d_nieujemna:
    fsqrt ;st(0) = sqrt(st(0))
    fxch ;st(0) <--> st(1)
    fchs ;st(0) = -st(0)
    fld dwa ;zaladowanie 2.0 na stos
    fmul wsp_a ;st(0) = 2a
   
    fld st(1) ;-b na wierzcholek stosu
    fsub st(0), st(3) ;st(0) = -b - sqrt(d)
    fdiv st(0), st(1) ;st(0) = (-b - sqrt(d)) / 2a
    fstp x1 ;wynik do pamieci
   
    mov edx, 0
    mov dx, OFFSET x1
    call wyp_float
    mov dziesietnie[0], "+"
   
    je jeden_wynik ;znaczniki jeszcze pamieta
   
    fstp st(3) ;wierzcholek stosu przesuwa na jego koniec
    fadd st(0), st(1) ;-b + sqrt(d)
    fdiv st(0), st(2) ;/2a
    fstp x2 ;wynik do pamieci

    mov edx, 0
    mov dx, OFFSET x2
    call wyp_float
   
    mov dx, OFFSET dwa_wyn_napis
    mov ah, 09h
    int 21h
    jmp koniec

jeden_wynik:
    mov dx, OFFSET jed_wyn_napis
    mov ah, 09h
    int 21h

koniec:
    mov ax, 4c00h
    int 21h

pisz   proc
   mov   ah,09h
   int 21h
   ret
pisz   endp

program ENDS
stos_ SEGMENT stack
    db 256 dup (?)
stos_ ENDS

END poczatek

where is error?

PBrennick

You have created an uninitialized variable AND a label with the same name. You cannot do that.

Quote
    .
    .
    .
;zmienne do wypisywania liczb
    cyfry dw ?
    temp dd ?
    .
    .
    .
wczytaj proc
   pop   adres
   mov   ebx, 0
cyfry:   
   mov   ah,1
   int   21h
    .
    .
    .

Should be very easy for you to fix.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

dawidekz

#26
I fixed the problem quickly.. thank you.
but i've next problem...

I added 2 files in zip archive . The source "ROWN" possesses defined  A, B and C and work. In the source "ROWNANIE", I added lines to reading A, B (C been defined ). The programme asks about A and B but nothing happens after this. Where I make error?

PBrennick can you help me?

[attachment deleted by admin]

dawidekz

soucrce rownanie:

.486
dane SEGMENT use16
    wsp_a dd   ?,'$'
    wsp_b dd   ?,'$'
    wsp_c dd -15.0
Nap1   DB   "Podaj A ",'$'
Nap2   DB   "Podaj B ",'$'
crlf   DB   0Dh,0ah,'$'
adres   DW   ?,'$'
    dwa dd 2.0
    cztery dd 4.0
    x1 dd ?
    x2 dd ?
    d_uj_napis db "Wyznacznik jest ujemny!", 13, 10, "$"
    jed_wyn_napis db "Obliczono jedyny pierwiastek", 13, 10, "$"
    dwa_wyn_napis db "Obliczono oba pierwiastki", 13, 10, "$"
;zmienne do wypisywania liczb
    cyfry dw ?
    temp dd ?
    dziesiec dd 10.0
    jeden dd 1.0
    ctrl_wrd dw ?
    dziesietnie db "+", 40 dup (" ")
;;;
dane ENDS

program SEGMENT use16
    assume cs:program, ds:dane
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;wypisuje liczbe 32-bitowa zmiennoprzecinkowa
;edx - offset liczby





;--------------------------------------
wyp_float PROC

    pushad
    pushf

   
   mov   wsp_b,0
   mov   wsp_a,0
   
   lea   dx,Nap1
   call   pisz
   
   call   wczytaj
   mov wsp_a,ebx
   
   lea   dx, crlf
   call   pisz
   
   lea   dx,Nap2
   call   pisz

   call   wczytaj
   mov wsp_b,ebx

   lea   dx, crlf
   call   pisz
   

pocz_wyp:
    fstcw ctrl_wrd
    bts ctrl_wrd, 10 ;ustawia 10. bit
    btr ctrl_wrd, 11 ;zeruje 10. bit
    fldcw ctrl_wrd ;ustawia zaokraglanie w dol

    fld jeden
    fld dziesiec
    fyl2x ;st(0) = lg2 (10)
    fld jeden
    fld DWORD PTR [edx] ;laduje liczbe na stos

;trzeba cos zrobic z ujemna
    ftst ;porownuje st(0) z zerem
    fstsw ax ;stan koprocesora do ax
    sahf ;flagi <-- ah <-- koprocesor

    ja nieujemna
    mov dziesietnie[0], "-"
    fchs ;zamiana znaku

nieujemna:
    fyl2x
    fdiv st(0), st(1) ;cyfry czesci calkowitej
    fist cyfry ;teraz juz gotowa wartosc calkowita
    fstp st(0) ;\
    fstp st(0) ; > wyczyszczenie stosu
    fld DWORD PTR [edx] ;/ i zaladowanie naszej liczby
   
    cmp dziesietnie[0], "-"
    jne nieujemna2
    fchs

nieujemna2:
    inc cyfry ;lepiej tu "zaokraglic" w gore, bo w dol
    mov cx, cyfry ;laduje licznik petli
    cmp cx, 0 ;jesli liczba < 1
    ja calk ;nie przeprowadza tej petli
    mov dziesietnie[0], "0"
    jmp ulamk

calk:
    fist temp ;czesc calkowita naszej liczby
    mov eax, DWORD PTR temp
    mov edi, 10 ;podstawa dziesietna

ptl_calk:
    mov edx, 0
    div edi
    mov bx, cx
    add dl, "0" ;zamiana na ASCII
    mov dziesietnie[bx], dl ;kolejna cyfra calkowita
    loop ptl_calk

ulamk:
    mov bx, cyfry
    inc bx
    mov dziesietnie[bx], "."
    fld dziesiec
    fxch ;st(0)=liczba, st(1)=10.0

ptl_ulamk:
    fist temp ;\
    fild temp ; > odjecie czesci calkowitej
    fsub st(1), st(0) ;/
    fstp st(0)

    inc bx ;index tablicy
    fmul st(0), st(1)
    fist temp ;\
    mov edx, temp ; \ kolejna cyfra ulamkowa
    add dl, "0" ; /
    mov dziesietnie[bx], dl ;/
   
    ftst ;porownuje st(0) z zerem
    fstsw ax ;stan koprocesora do ax
    sahf ;flagi <-- ah <-- koprocesor
    jnz ptl_ulamk ;jeszcze nie skonwertowal calej liczby

    inc bx
    mov dziesietnie[bx], 13 ;przygotowanie
    inc bx
    mov dziesietnie[bx], 10
    inc bx
    mov dziesietnie[bx], "$"
   
    mov dx, OFFSET dziesietnie ;i wypisanie
    mov ah, 09h
    int 21h

    fstp st(0)
    fstp st(0)

    popf
    popad
    ret

wyp_float ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

poczatek:

    push SEG dane
    pop ds

    finit
    fld wsp_b ;zaladowanie na wierzcholek stosu
    fld st(0) ;duplikacja b na stosie
    fmul st(0), st(0)
   
    fld cztery ;\
    fmul wsp_a ; \ d = b^2-4ac
    fmul wsp_c ; /
    fsub st(1), st(0) ;/

    fstp st(0) ;b^2 juz nie jest potrzebne
    ftst ;porownuje st(0) z zerem
    fstsw ax ;stan koprocesora do ax
    sahf ;flagi <-- ah <-- koprocesor
    jae d_nieujemna ;d >= 0
    jb d_ujemna ;d < 0

d_ujemna:
    mov dx, OFFSET d_uj_napis
    mov ah, 09h
    int 21h
    jmp koniec

d_nieujemna:
    fsqrt ;st(0) = sqrt(st(0))
    fxch ;st(0) <--> st(1)
    fchs ;st(0) = -st(0)
    fld dwa ;zaladowanie 2.0 na stos
    fmul wsp_a ;st(0) = 2a
   
    fld st(1) ;-b na wierzcholek stosu
    fsub st(0), st(3) ;st(0) = -b - sqrt(d)
    fdiv st(0), st(1) ;st(0) = (-b - sqrt(d)) / 2a
    fstp x1 ;wynik do pamieci
   
    mov edx, 0
    mov dx, OFFSET x1
    call wyp_float
    mov dziesietnie[0], "+"
   
    je jeden_wynik ;znaczniki jeszcze pamieta
   
    fstp st(3) ;wierzcholek stosu przesuwa na jego koniec
    fadd st(0), st(1) ;-b + sqrt(d)
    fdiv st(0), st(2) ;/2a
    fstp x2 ;wynik do pamieci

    mov edx, 0
    mov dx, OFFSET x2
    call wyp_float
   
    mov dx, OFFSET dwa_wyn_napis
    mov ah, 09h
    int 21h
    jmp koniec

jeden_wynik:
    mov dx, OFFSET jed_wyn_napis
    mov ah, 09h
    int 21h

koniec:
    mov ax, 4c00h
    int 21h

wczytaj proc
   pop   adres
   mov   ebx, 0
cyfry1:   
   mov   ah,1
   int   21h
   
   cmp   al,0dh
   je   dalej
   
   mov   edx,ebx
   add   ebx,edx
   xor   ah,ah
   sub   al,30h
   add   ebx,eax
   jmp   cyfry1   
   
dalej:
      

   push   adres
   ret
wczytaj   endp

pisz   proc
   mov   ah,09h
   int 21h
   ret
pisz   endp


program ENDS
stos_ SEGMENT stack
    db 256 dup (?)
stos_ ENDS

END poczatek

The programme asks A and B, but later, He does not make calculations,I tries various combinations, but this does not give anything

cookj

Just for fun and gratification I decided to write the program
using Raymonds QuadRoots procedure and the resdlg2 program
from the example directory in masm32.

I must be real tired because I run into an odd situation.

Here is the procedure heading:

QuadRoots proc public a:DWORD, b:DWORD, c:DWORD
; to compute the roots of the quadratic equation ax^2+bx+c=0

The problem is it does not assemble correctly unless the
c cariable is changed to c1 or something else other then c.

The errors are syntax error :c and unmatched block nesting
QuadRoots.

If I changed the var to c1 it assembles perfectly.

I have a sinking feeling that I am missing something obvious.

How about a hint please from all of you experts out there.

Thanks


John
 

sluggy

Accidental reply/repost removed at cookj's request :)