The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: etow on January 21, 2008, 07:30:56 PM

Title: Another code trouble
Post by: etow on January 21, 2008, 07:30:56 PM
Hi

I have the following code that I try to compile but got errors in it:

---------------------------------------------------------------------------------------

.686 ; create 32 bit code
    Option CaseMap :none                    ; case sensitive

Include   \masm32\macros\macros.asm       ; MASM support macros

  ; -----------------------------------------------------------------
  ; include files that have MASM format prototypes for function calls
  ; -----------------------------------------------------------------
Include   \masm32\include\masm32rt.inc

  ; ------------------------------------------------
  ; Library files that have definitions for function
  ; exports and tested reliable prebuilt code.
  ; ------------------------------------------------
IncludeLib   \masm32\lib\msvcrt.lib

.Code

start:
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
   Call Main
   inkey        ; pause the screen while waiting for user to press any key
                ; to continue
    exit
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Main Proc
   Local Number:DWord
   Local Remainder:DWord
   Local Quotient:DWord
   Local Factor:DWord
    ;--------------------------------------------
    ; Ecx =  a number to store Quotient
    ; Edx = a temporary variable

    Mov Number, 12
    print str$(Number)
    print chr$(" = ")
    Mov Factor, 2

    .While Factor <= Number
          Mov Eax, Factor
         Div Number               ; Quotient = Number / Factor
         Mov Quotient, Eax
         ;---------------
          Mov Eax, Factor
          Mul Quotient
          Mov Edx, Eax            ; Edx = (Quotient * Factor)

         Sub Edx, Number         ; Number = Number - Edx
         Mov Remainder, Edx      ; Remainder = Edx
       .If Remainder == 0
         print chr$(" * ")
         print str$(Factor)
         Mov Ecx, Quotient       ; Ecx = Quotient
         Mov Number, Ecx         ; Number = Ecx
         ;----------------
          Mov Eax, Factor
         Div Number
         Mov Quotient, Eax       ; Quotient = Number /Factor
         ;----------------
          Mov Eax, Factor
          Mul Quotient
          Mov Edx, Eax            ; Edx = (Quotient * Factor)

         Sub Edx, Number         ; Number = Number - Edx
         Mov Remainder, Edx      ; Remainder = Edx
       .Else
          Add Factor, 1          ; Factor = Factor + 1
       .EndIf
    .EndW

    print chr$(13, 10)        ; a return key space will be outputted to the screen

    Ret
Main EndP

End start

------------------------------------------------------------

The errors are the following:

============== proj2 - Debug ==============

Assembling: Module1
\masm32\include\masm32rt.inc(33) : warning A4011: multiple .MODEL directives found : .MODEL ignored
------------------------------------------
WARNING Duplicate include file windows.inc
------------------------------------------
-----------------------------------------
WARNING Duplicate include file user32.inc
-----------------------------------------
-----------------------------------------
WARNING Duplicate include file kernel32.inc
-----------------------------------------
Module1.asm(71) : error A2070: invalid instruction operands

Errors ocurred.
------------------------------------------------------------------------------------

Please I need help

Thanks
Title: Re: Another code trouble
Post by: evlncrn8 on January 21, 2008, 07:49:11 PM
.686 ; create 32 bit code
    Option CaseMap :none                    ; case sensitive

you didnt set the model...

for example...

.686p
.model flat, STDCALL
.mmx

option casemap :none   ; case sensitive
option dotname
Title: Re: Another code trouble
Post by: jdoe on January 21, 2008, 08:18:40 PM
etow,

In the examples folder of MASM32, look how each source begins.

This should be at the top of the source before INCLUDE and INCLUDELIB...


.386
.model flat,stdcall
option casemap:none


If you're not familiar with it and in the meantime you get used to it, you can just put the line below at the top of the source and you won't get errors like that.


include \masm32\include\masm32rt.inc

.Code

start:

-----

End start


Title: Re: Another code trouble
Post by: MichaelW on January 21, 2008, 08:27:25 PM
etow,

Take a look at masm32\include\masm32rt.inc to see what it includes. Assuming that you want to use a .686 processor directive, the basic structure of your program could be something like this:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
    .686
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data

    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


Title: Re: Another code trouble
Post by: jdoe on January 21, 2008, 08:31:32 PM
Quote from: etow on January 21, 2008, 07:30:56 PM
.While Factor <= Number
-----------------------------------------
Module1.asm(71) : error A2070: invalid instruction operands

etow,

Before you ask  :P

You can't compare two memory with each other and this is the error at line 71.
Use a register to store one and then you'll be able to compare.

Title: Re: Another code trouble
Post by: RuiLoureiro on January 21, 2008, 09:47:53 PM
Quote from: etow on January 21, 2008, 07:30:56 PM

       .While Factor <= Number
          Mov        Eax, Factor
          Div          Number               ; Quotient = Number / Factor
          Mov         Quotient,  Eax
         ;----------------------------------
          Mov Eax, Factor
          Mul Quotient
          Mov Edx, Eax            ; Edx = (Quotient * Factor)
   

Hi etow,
            your code have one problem: *** Div   Number ***   divide   EDX:EAX  by  the dword ***Number ***  and puts the quotient into EAX and the remainder in EDX. Whats the value of EDX at the start ?
Rui
Title: Re: Another code trouble
Post by: etow on January 22, 2008, 01:36:03 AM
hi

What is the model dot abbrevation for Pentium 4 HT processor?  It is 3.4 GHz fast
evlncrn8 mentioned about which model I should specify if I use .686 in the top of my declaration of my ASM file.

Need help please.

Thanks
Title: Re: Another code trouble
Post by: donkey on January 22, 2008, 02:22:53 AM
The Pentium 4 is a P6 architecture processor so it would be .686, Hyper-threading and speed have no effect at all on the instruction set.
Title: Re: Another code trouble
Post by: etow on January 23, 2008, 02:55:55 AM
Thanks Donkey