News:

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

Can help me solve this ques?? Error A2022...

Started by nick, May 11, 2012, 02:43:16 PM

Previous topic - Next topic

nick

Hii.. i m trying to get 2 input number from user.. den print d sum of 2 num.. dis is my coding... it state that line 29,38,52 have error A2022:instruction operand muz b same size. and line 16 error A2004:symbol type comflict... can anyone help me write d correct coding.. thanks a lot...

include \masm32\include\masm32rt.inc

.data
output1     db 'Please Enter 1st num: $',0
output2     db 'Please Enter 2nd num: $',0
num1        db ?
num2        db ?
output3     db ?

.code

main PROC
mov ax,@data
mov ds,ax

call AddNumbers

mov ax, 4c00h
int 21h
main ENDP


AddNumbers PROC
;get num1
    mov ah, 09h
    mov dx, offset output1
    int 21h
   
    mov ah, 1h
    int 21h
    mov num1, al
   
;get num2
    mov ah, 09h
    mov dx, offset output2
    int 21h
   
    mov ah, 1h
    int 21h
    mov num2, al

;add [numbers]
    mov al, num1
    add al, num2
    mov output3, al
   
;output result
    mov ah, 09h
    mov dx, offset output3
    int 21h

    ret

AddNumbers endp

END main

END start


dedndave


nick

I trying to get 2 integer input from user.. n print the addtion..can u help me ??

dedndave


nick

32-bit..... can help me?? what the different v 16 bits?? i jz nid the output...

dedndave

there is a lot of difference
the code you show above is 16-bit

for 32-bit, you can use masm32 library functions and do this in a snap   :P

http://www.masm32.com/board/index.php?topic=17614.msg148280#msg148280

assemble as a console app:
        include \masm32\include\masm32rt.inc

        .data?

var1    dd ?
var2    dd ?

        .code

start:  mov     var1,sval(input("First Number: "))
        mov     var2,sval(input("Second Number: "))

        mov     eax,var1
        add     eax,var2

        print   ustr$(eax),13,10

        inkey
        exit

        end     start

nick

Dedndave, 1 more thing .. izit using the masm qeditor to write dis code??dis is my step to compile n run.. can u help check whether anything wrong...

1)type the code
2)save the file
3)Choose PROJECT > CONSOLE & ASSEMBLY LINK
4)type in 'filename.asm'..check whether there is error
5)if no error.. click the RUN image...
6)type in DIR
7)type in 'filename.exe'..

is there any step miss?? thanks a lot :clap:

dedndave

i don't normally use QEditor
but - let me see if i can do it   :P

nick

Thanks lots for helping.. or wat u using?? mayb i can try?? u using cmd?? :dazzled:

dedndave

i use NotePad or NotePad++

1) open QEditor
2) type in the source text (i used copy/paste)
3) File - Save As - name the file and pick the folder
4) in QEditor, open the command prompt (use icon or File - Cmd Prompt)
     it should open in the same folder where you saved the file
5) at the prompt, type: buildc filename
     then press Enter - this should assemble the file
6) at the prompt, type: filename
     then press Enter - this should run the program

if that does not work, it may be that you do not have C:\Masm32\Bin in the PATH

now - there is a small problem with the code i posted above
the sval macro (or the input macro) does not like being on the same line as the "start:" label
so - to fix that.....
       include \masm32\include\masm32rt.inc

       .data?

var1    dd ?
var2    dd ?

       .code

start:
       mov     var1,sval(input("First Number: "))
       mov     var2,sval(input("Second Number: "))

       mov     eax,var1
       add     eax,var2

       print   ustr$(eax),13,10

       inkey
       exit

       end     start


First Number: 123
Second Number: 456
579
Press any key to continue ...

Ryan

I'm new at MASM too, but I think I can offer a quicker solution to running your program.

I'm not sure why you would have to type in the file name of the asm file.  My version of QEditor handles the name automatically.  You may want to check the code for the menus (Ctrl+Shift+M).

Once there the &Project menu is first in the listing.  Below it are the items in the menu.

&Console Assemble && Link,\MASM32\BIN\Buildc.bat "{b}"


One of the items should look like that. {b} represents the name of the file.

To run the program, it should be the last item in the Project menu.  You can check that the "{b}.exe" is included with Run Program.

dedndave

i don't find a "Project" menu - or a build menu - lol

i do all this stuff with a batch file   :P

i know there is a way to use scripts with QEditor - but i haven't really played with it

Ryan


dedndave

send me a screen-shot, please   :'(
i don't see "Project" anywhere - lol