News:

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

Another code trouble

Started by etow, January 21, 2008, 07:30:56 PM

Previous topic - Next topic

etow

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

evlncrn8

.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

jdoe

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



MichaelW

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


eschew obfuscation

jdoe

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.


RuiLoureiro

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

etow

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

donkey

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.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

etow