forked from reg1reg1/Shellcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddTwoNumbers.asm
More file actions
78 lines (61 loc) · 1.58 KB
/
Copy pathAddTwoNumbers.asm
File metadata and controls
78 lines (61 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
.386
.model flat, stdcall
option casemap: none
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
Num1 dword 0
Num2 dword 0
NumSub dword 0
NumSum dword 0
MsgInp1 db "Enter first number",13,10,0
MsgInp2 db "Enter Second Number",13,10,0
DispSum db "The sum of the numbers",13,10,0
DispDiff db "The difference of the numbers",13,10,0
DispEnter db "The numbers entered are",13,10,0
Inp1 db 10 DUP(0)
Inp2 db 10 DUP(0)
SumString db 10 DUP(0)
SubString db 10 DUP(0)
.code
start:
;Support for invoke, which makes it simple to make system calls
; Without masm we need to fill up stack and eax registers
invoke StdOut, addr MsgInp1
invoke StdIn, addr Inp1, 10
invoke StdOut, addr MsgInp2
invoke StdIn, addr Inp2, 10
invoke StdOut, addr DispEnter
invoke StdOut, addr Inp1
invoke StdOut, addr Inp2
;Strip the input of newline characters
invoke StripLF, addr Inp1
invoke StripLF, addr Inp2
;Convert the strings to numbers
invoke atodw, addr Inp1
mov Num1,eax
invoke atodw, addr Inp2
mov Num2, eax
;Calculate Sum
mov eax,Num1
add eax,Num2
mov NumSum,eax
;Convert NumSum to String
invoke dwtoa, NumSum, addr SumString
;Calculate difference
mov eax,Num1
sub eax,Num2
mov NumSub,eax
;Convert NumSub to String
invoke dwtoa, NumSub, addr SubString
;Ready for printing
invoke StdOut, addr DispSum
invoke StdOut, addr SumString
invoke StdOut, addr DispDiff
invoke StdOut, addr SubString
;Exit
invoke ExitProcess,0
end start