Thanks for the reply
By nidud ,
; adding.asm
; assemble with: Asmc -pe adding.asm
;
include conio.inc
.code
main proc
local firstNumber, secondNumber, sumOfTwoNumbers;
_cputs("Enter two integers: ")
;; Two integers entered by user is stored using scanf() function
_cscanf("%d %d", &firstNumber, &secondNumber)
;; sum of two numbers in stored in variable sumOfTwoNumbers
mov eax,firstNumber
add eax,secondNumber
mov sumOfTwoNumbers,eax
;; Displays sum
_cprintf("\r\n%d + %d = %d\r\n", firstNumber, secondNumber, sumOfTwoNumbers)
xor eax,eax
ret
main endp
end main
; adding.asm
; assemble with: Asmc -pe adding.asm
;
.486
.model flat, c
option dllimport:<msvcrt>
printf proto :ptr, :vararg
scanf proto :ptr, :vararg
.code
main proc
local firstNumber, secondNumber, sumOfTwoNumbers;
printf("Enter two integers: ")
;; Two integers entered by user is stored using scanf() function
scanf("%d %d", &firstNumber, &secondNumber)
;; sum of two numbers in stored in variable sumOfTwoNumbers
mov eax,firstNumber
add eax,secondNumber
mov sumOfTwoNumbers,eax
;; Displays sum
printf("%d + %d = %d\n", firstNumber, secondNumber, sumOfTwoNumbers)
xor eax,eax
ret
main endp
end main
By jj2007 ,
include \masm32\MasmBasic\MasmBasic.inc ; download
SetGlobals firstNumber, secondNumber, sumOfTwoNumbers
Init
mov firstNumber, Val(Input$("First number:\t", "123"))
mov secondNumber, Val(Input$("Second number:\t", "321"))
add eax, firstNumber
mov sumOfTwoNumbers, eax
Inkey Str$("The sum of %i", firstNumber), Str$(" plus %i", secondNumber), Str$(" is %i", sumOfTwoNumbers)
EndOfCode
By hutch--
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
comment * -----------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
----------------------------------------------------- *
.data?
value dd ?
.data
item dd 0
.code
start:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
call main
inkey ; pause so you can see the result
exit
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
main proc
mov eax, 1234 ; put integer into eax
add eax, 5678 ; add integer to eax
print str$(eax),13,10 ; display the result
ret ; return to caller
main endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end start
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
comment * -----------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
----------------------------------------------------- *
AddemUp PROTO STDCALL :DWORD, :DWORD
.code
start:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
call main
inkey ; pause so you can see the result
exit
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
main proc
LOCAL num1 :DWORD
LOCAL num2 :DWORD
LOCAL pbuf :DWORD
LOCAL buff[128]:BYTE
push esi
; -----------
; load locals
; -----------
mov num1, 1234
mov num2, 5678
; -----------------
; call the add proc
; -----------------
push num2
push num1
call AddemUp
mov esi, eax
; -------------------------
; get output buffer address
; -------------------------
lea eax, buff
mov pbuf, eax
; --------------
; display result
; --------------
print cat$(pbuf,"The sum of ",str$(num1)," plus ",str$(num2)," = ",str$(esi),chr$(13,10))
pop esi
ret ; return to caller
main endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
AddemUp proc num1:DWORD,num2:DWORD
mov eax, [esp+4]
add eax, [esp+8]
ret
AddemUp endp
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end start
By zedd151 ,
ascii_adder proc src1:dword, src2:dword, dst:dword, lent:dword ;(src1, src2, dst are pointers to already allocated memory. lent is the length of the largest value to be summed)
local carrie:dword
push esi
push edi
push ebx
mov esi, src1
mov edi, src2
mov ebx, dst
mov ecx, lent
mov carrie, 0
top:
mov eax,0
mov al,byte ptr [esi+ecx-1]
mov dl,byte ptr [edi+ecx-1]
add al,dl
sub al, 30h
add eax, carrie
mov carrie, 0
cmp al, 39h
jbe @f
mov carrie, 1
sub al, 10
@@:
mov [ebx+ecx-1], al
dec ecx
cmp ecx, 0
jnz top
pop ebx
pop edi
pop esi
ret
ascii_adder endp
nidud's example is using C run time library , That one looks a bit easy to read and understand .
JJ2007's example is an emulation of basic written in MASM , can understand but still looks complicated
zedd151 's example is a bit hard to understand too at this level of understanding ,
hutch--'s example is MASM , looks the hardest to me ,
Only in the nidud's example the user is asked to enter numbers ?