News:

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

Main Menu

I Have A Question

Started by ayao, March 18, 2014, 07:33:18 PM

Previous topic - Next topic

ayao


Hello  I got My Code Working But i do have some mirror error  about the output and also i wanted to know which is the remainder or the quotient is eax or edx this two seems to confused me alot.

this the original OUPUT:

Number 3 & 8 : 0.375 Number 5 & 6 : 0.833

but my OUPUT IS THIS :
Number 3 & 8 : 375  Number 5 &6 : 833 ; how do i show the zero or show 0.375
.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

.data
   
    Message3 db "Enter Number 3 & 8: ", 0
    Message5 db "Enter Number 5 & 6: ", 0

    Message13 db " Number 3 & 8 div: ", 0
    Message15 db " Number 5 & 6 div: ", 0

.data?
    Number5 dword ?
    Number6 dword ?
    Number9 dword ?
    Number10 dword ?
    UserInput5 db 10 DUP(?)
    UserInput6 db 10 DUP(?)
    UserInput9 db 10 DUP(?)
    UserInput10 db 10 DUP(?)
    DivString db 20 DUP(?)
    DivideString db 20 DUP(?)
    NumDiv dword ?
    NumDivide dword ?

.code

start:

        ; Take the user inputs first
       
        invoke StdOut, addr Message3
        invoke StdIn, addr UserInput5, 10   
        invoke StdIn, addr UserInput6, 10
     

        invoke StdOut, addr Message5
        invoke StdIn, addr UserInput9, 10
        invoke StdIn, addr UserInput10, 10
       

        ; Remove the CRLF


        invoke StripLF, addr UserInput5
        invoke StripLF, addr UserInput6
       
        invoke StripLF, addr UserInput9
        invoke StripLF, addr UserInput10
     

        ; convert them to numbers from strings

        ; first user input

        invoke atodw, addr UserInput5
        mov Number5, eax
   
        invoke atodw, addr UserInput9
        mov Number9, eax
        ; second user input
       
   
       
        invoke atodw, addr UserInput6
        mov Number6, eax
       
        invoke atodw, addr UserInput10
        mov Number10, eax
       
        ; divided the numbers

        xor edx,edx
        mov eax,Number5
        mov ebx, Number6
        idiv ebx
        push ebx
        push edx
        pop edx
        mov eax,edx
        mov ebx,1000
        mul ebx
        xor ebx,ebx
        pop ebx
        div ebx
        mov NumDiv,eax

        xor edx,edx
        mov eax,Number9
        mov ebx, Number10
        idiv ebx
        push ebx
        push edx
        pop edx
        mov eax,edx
        mov ebx,1000
        mul ebx
        xor ebx,ebx
        pop ebx
        div ebx
        mov NumDivide,eax

       

        ; convert the sum and sub to strings and display it

        invoke dwtoa, NumDiv, addr DivString
        invoke dwtoa, NumDivide,  addr DivideString

       
        ; Print the sum and sub on the screen

       
        invoke StdOut, addr Message13
  invoke StdOut, addr DivString
       
        invoke StdOut, addr Message15
  invoke StdOut, addr DivideString

        invoke ExitProcess, NULL
       
end start

jj2007

- Move to the .data section:
    Div0String   db "0."
    DivString db 20 DUP(?)
    Div1String   db "0."
    DivideString db 20 DUP(?)

- change as follows:
        invoke StdOut, addr Message13
     invoke StdOut, addr Div0String
       
        invoke StdOut, addr Message15
     invoke StdOut, addr Div1String
:P

In case that your results are bigger than 1.000, you need to look into lstrcpy and lstrcat