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
masm32 is a 32-bit package
you are writing a 16-bit program
http://www.masm32.com/board/index.php?topic=15297.msg124957#msg124957
here is some code to get user input as a string, rather than characters
http://www.masm32.com/board/index.php?topic=12054.msg91936#msg91936
I trying to get 2 integer input from user.. n print the addtion..can u help me ??
do you want to write 16-bit or 32-bit ?
32-bit..... can help me?? what the different v 16 bits?? i jz nid the output...
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
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:
i don't normally use QEditor
but - let me see if i can do it :P
Thanks lots for helping.. or wat u using?? mayb i can try?? u using cmd?? :dazzled:
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 ...
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.
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
Hmm... I've got 4.0g.
send me a screen-shot, please :'(
i don't see "Project" anywhere - lol
Can I upload and embed images directly? For now I'll upload it with my post.
EDIT: I'm testing an embed...
(http://s14.postimage.org/its06y5z5/QEditor_Project_Menu.png)
thanks - you can remove it, now :U
i was missing the INI and QSC files :P
big difference - lol
now - if i can just get right-click/copy and right-click/paste down to 2 steps :P
Ryan - i have been using ImageShack for an image host
but - they won't host animated GIF's anymore
so - i just now signed up for PhotoBucket - let's see how it goes...
there is an icon above the smileys
or, you can add tags...
[img][/img]
Yeah. I saw the img tags. I've just never gotten into using an image hosting account. Maybe it's time I jump on the bandwagon :lol
Dedndave.. thanksss.. i done d ADDITION method.. if now i wan to switch to DIVISION method.. izit onli change the ADD to DIV??
no - DIV is a bit different :P
to understand how DIV works, it is easiest to first understand MUL
when you multiply two 32-bit values, you may get a result that is as large as 64 bits
when we use the MUL instruction, the operand is multiplied by the contents of EAX
when you are done, the result is in EDX:EAX - forming a single 64-bit number
mov eax,4000000000
mov ecx,3000000000
mul ecx
;EDX:EAX = 3000000000 x 4000000000 = 12000000000000000000 = 0A688906BD8B00000h
;EDX = 0A688906Bh (high 32 bits) and EAX = 0D8B00000h (low 32 bits)
DIV works just the opposite of MUL
when you divide by a 32-bit operand, EDX:EAX are treated as a single 64-bit number
mov edx,0A688906Bh
mov eax,0D8B00000h
mov ecx,3000000000
div ecx
;EAX = quotient = 4000000000
;EDX = remainder which, in this case, happens to be 0
so - if you are going to divide a 32-bit value by another 32-bit value, you need to set EDX to 0, first
mov eax,13
mov edx,0 ;set the high dword to 0
mov ecx,3
div ecx
;EAX = 4 (quotient)
;EDX = 1 (remainder)
Negative numbers can produce nice effects:
mov eax, -100
mov ecx, 10
cdq
div ecx
Multiplication n division same method??
Quote from: dedndave on May 12, 2012, 05:48:20 PM
to understand how DIV works, it is easiest to first understand MUL
if you learn about MUL first, learning about DIV will be easier
include \masm32\include\masm32rt.inc
.data?
var1 dd ?
var2 dd ?
.code
start:
mov var1,sval(input(" Dividend: "))
mov var2,sval(input(" Divisor: "))
mov eax,var1
mov edx,0
div var2
push edx
push eax
print chr$(13,10," Quotient = ")
pop eax
print ustr$(eax),13,10
print chr$("Remainder = ")
pop edx
print ustr$(edx),13,10
inkey
exit
end start
don't try to divide by 0 ! :red
Quote from: dedndave on May 13, 2012, 03:57:39 AM
don't try to divide by 0 ! :red
Try!
include \masm32\MasmBasic\MasmBasic.inc ; download (http://www.masm32.com/board/index.php?topic=12460)
Init tc
inc MbFlags[4]
.Repeat
push Val(Input$("\tDividend: ", "1000"))
mov ecx, Val(Input$("\tDivisor: ", "0"))
pop eax
cdq
Try
div ecx
Catch only
invoke RaiseException, 195948557, EXCEPTION_NONCONTINUABLE, 0, 0
Finally
Inkey Str$("The result is %i. One more (n)?", eax)
.Until eax=="n"
Exit
TryCatchEnd
end start
P.S.: Attached exe works only from the commandline :wink
How about multiplication??
Quote from: minsiong on May 13, 2012, 06:55:19 AM
How about multiplication??
You should read \masm32\help\opcodes.chm, especially
div
idiv
mul
imul
a little mod to avoid divisor = 0 :bg
include \masm32\include\masm32rt.inc
.data?
var1 dd ?
var2 dd ?
.code
start:
mov var1,sval(input(" Dividend: "))
retry:
mov var2,sval(input(" Divisor: "))
cmp var2,0
jz retry
mov eax,var1
mov edx,0
div var2
push edx
push eax
print chr$(13,10," Quotient = ")
pop eax
print ustr$(eax),13,10
print chr$("Remainder = ")
pop edx
print ustr$(edx),13,10
inkey
exit
end start
for MUL...
no need to retry for 0
change the prompt text's - EDX will have the high dword, not the remainder - for many numbers, just show EAX
remove the "mov edx,0" line
change DIV to MUL
nice Jochen :bg
Dividend: 1000
Divisor: 0
Exception (line ??):
Code 0BADF00D
EIP 7C812AFB
Quote from: jj2007 on May 13, 2012, 06:49:20 AM
Try!
(need to add printing of CR+LF after "Y" answer on the question "One more (n)?")
Dividend: 1000
Divisor: 10
The result is 100. One more (n)?
Dividend: 1000
Divisor: -1
The result is 0. One more (n)?
Dividend: 1000
Divisor: 1000
The result is 1. One more (n)?
Dividend: 1000
Divisor: 0
Exception (line ??):
Code 0BADF00D
EIP 7C81EB33
Jochen, MasmBasic source looks cool :U
Quote from: Antariy on May 13, 2012, 02:23:53 PM
Jochen, MasmBasic source looks cool :U
Thanks :bg
Actually, I was surprised how easy it was to implement Try/Catch. Especially since the two macros don't insert any code, he he :toothy
Quote from: jj2007 on May 13, 2012, 03:11:22 PM
Actually, I was surprised how easy it was to implement Try/Catch. Especially since the two macros don't insert any code, he he :toothy
SetUnhandledExceptionFilter? :bg
Quote from: Antariy on May 13, 2012, 09:19:29 PM
SetUnhandledExceptionFilter? :bg
see MbTryCatch in \masm32\MasmBasic\MasmBasic.inc :bg