hi every body

I'm begging with assembly and I try two sum two numbers but i cant
understand interruptions and generally Assembly so I learn asm with api

I wrote this if anybody correct me >>!!

.386
.model flat ,stdcall
OPTION CASEMAP:NONE

include kernel32.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
.DATA
MasgName db "Enter the NUmber   ",00ah,00dh 

.DATA?
num db 10 dup (?)

.code
start:

invoke StdOut ,addr MasgName
invoke StdIn ,addr num,10

invoke StdOut ,addr MasgName
mov ebx ,eax

invoke StdIn ,addr num,10
add eax,ebx

mov num,eax
invoke StdOut ,addr num
 
invoke StdIn ,addr num,10

invoke ExitProcess,0
end start

You're burying your code in macros making it unreadable.
The basic core of your task is the following

eax is one 32-bit number
ebx is another 32-bit number

add eax,ebx        ; eax=eax+ebx  
                ; Add with no carry two 32-bit values

At this point in your learning you can ignore the concept of interrrupts as from your applications code point of view it won't see the interrupt and will merely flow through the code following the instruction pointer.

thanks wildgoose

Ok ...let see
add eax,ebx ; eax=eax+ebx
; Add with no carry two 32-bit values

it's correct ......ok

but how i can move value in eax to num and print it in screen ?

You were using a macro before. And 32-bit tools.

You will need a integer to ASCII conversion, and an ASCII print function.
Or a function that accepts an integer and does the conversion and prints it.

In assembly language a register contains the value to print (or address of string buffer to print) and then prints it!

You were using mov num,eax
invoke StdOut ,addr num

What is the SDK for the 'invoke StdOut' say!' Does it print integers or ASCII text?


But my guess you were using it wrong. You were using a string print function.

GOOGLE says its a print text.
and your input is text as well!

Which means first you need to convert your ASCII input into a decimal value!

invoke StdIn ,addr num,10

So lets start there! You have a 10 character buffer

So when you entered digits such as 123
you have...
31h 32h 33h ,CR


You'll need to parse from ASCII into values.

They seem to have two macros you can use...

invoke StdIn,ADDR num,10
            ; returns length in eax ???
        mov BYTE PTR [num+eax], 0   <-- Set terminator
        invoke StripLF,ADDR num

So now you should have NULL terminated ASCII in buffer <num> without the trailing carriage return.

As a footnote, I hate heavy use of Macros in assembly language because they defeat the purpose of using assembly language in the first place. Code optimization!

Now you need to do ASCII to integer conversion!

Look at your masm32 install folder. There's a help folder with documents.

looks like they have other macros

invoke atodw, ADDR num

do your math

Then use the macro to convert back to string

invoke dwtoa, eax, ADDR num

then print the string using your STDOUT

thanks .....thanks .......thanks
you learn me a lot off thinks

the finale code is

.386
.model flat ,stdcall
OPTION CASEMAP:NONE

include kernel32.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
.DATA
MasgName db "Enter the NUmber   ",00ah,00dh 

.DATA?
num db 2 dup (?)

.code
start:

invoke StdOut ,addr MasgName
invoke StdIn ,addr num,10

invoke StdOut ,addr MasgName
invoke atodw , addr num
mov ebx ,eax

invoke StdIn ,addr num,10
invoke atodw , addr num
add eax,ebx

           
invoke dwtoa, eax,addr num
invoke StdOut ,addr num
invoke StdIn ,addr num,10

invoke ExitProcess,0
end start

but look at the result

Enter the NUmber
1
Enter the NUmber
2
5156

??????

You really need to find out what those macros are doing! I'm really not familiar with these macros and functions available through masm32, as I only use masm.exe for 80x86 work.

But this seems it should be about right.

invoke StdOut ,addr MasgName

   ; Get 1st number
invoke StdIn ,addr num,10
    ; eax = length
   mov byte ptr num[ eax ], 0     ; Set terminator
   invoke StripLF,ADDR num        invoke StdIn,ADDR num,10

; Now convert ASCIIz number to decimal
invoke atodw , addr num
  mov ebx, eax   ; Move number from eax to ebx

   ;_____________
invoke StdOut ,addr MasgName
   ; Get 2nd number
invoke StdIn ,addr num,10
    ; eax = length
   mov byte ptr num[ eax ], 0     ; Set terminator
   invoke StripLF,ADDR num        invoke StdIn,ADDR num,10

    ; Now convert ASCIIz number to decimal
    invoke atodw , addr num
            ; eax is 2nd number

add eax,ebx
           
invoke dwtoa, eax,addr num
invoke StdOut ,addr num

I use
mov [eax + num -2],0

for endl (end of line )

but doesn't work ...!

thanks it's work now

if you please explain The structure of the code

mov byte ptr num[ eax ], 0

First I have a question. Did your instructor tell you to use the API that comes with masm32 or do it yourself?

mov byte ptr num[eax],0

Memory access can be direct from memory

mov num,al     ; 8-bit
mov num,ax   ;16-bit
mov num,eax   ; 32-bit
mov num,rax   ; 64-bit

memory can use a register offset
mov num[ebx],ax        num+value in ebx is new memory location
mov num[ebx*4],ax    num+(value *4)   You can use a scalar

In your particular case
mov num[ eax ],0    <-- undefined
0 is an undertermined size so it needs a data type pointer
    byte ptr                byte index
    word ptr               word index
    dword ptr              dword index
    qword ptr              qword index
    oword ptr              oword index 
so...
mov byte ptr num[ eax ],0
...store a zero as a byte at location num+eax

Did your instructor tell you to use the API that comes with masm32 or do it yourself?

i didn't studied Assembly but I hear about assembly and I want to learn the assembly .I ask another forum how i can start with assembly they tell me to start with use API :(
I'm interested in system and virus protected
and I'm programmer c++,for that I want to learn Assembly

thanks for help me

Find a good book and start working the sample problems. You need to work your way up.
Having the ability to single step your code is best!
Since you have C++ how about starting with inline code!

I prefer an assembly file, but inline is much easier to work with initially!

There is an author I like that has two books about assembly language.
One is a more advanced book, "Vector Game Math Processors" which I really like. It came with a CD and is out of print but is still available from Amazon.
The other is very complete, is still in print "32/64-Bit 80x86 Assembly Language Architecture" and has downloadable code samples. It has mistakes as I understand the author was rushed but I still like the book.
The files download link...
http://www.jbpub.com/catalog/9781598220025/samples/
The samples are C code that has some inline but has external assembly files that it links with. The best of both worlds. Do your input/output in a higher level language such as C/C++ and call the assembly code directly to do the low level functions.

In your particular case, pick one, compile it and then run it. Set a breakpoint and then single-step following the code into the assembly function. You can use it as a testbench for learning your assembly. The single-stepping with disassembly view and register views turned on will allow you to see the registers and flags changing as the instructions are executed!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.