Getting Start ASM Program

Introduction

build by fasm, Platform is Win7 x64

scanf and printf used in asm

Codes as follows:

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
 format PE console
entry main

include 'include\win32a.inc'
include 'INCLUDE\MACRO\import32.inc'

section '.data' data readable writeable
msg db "hello world!, %s, %d",0
msg2 db "dachmx",0
p db "pause>nul"
formatin db "%d", 0
integer1: times 4 db 0

section '.code' code readable executable
main:
push ebp
mov ebp, esp
sub ebp,4

push integer1 ; address of integer1
push formatin ; arguments are right to left
call [scanf]

mov eax, dword[integer1]

sub eax, 3

mov dword[integer1], eax

sub dword[integer1], 10
loop forloop1
forloop1:
add dword[integer1], 20
cmp dword[integer1], 150


push dword[integer1]
push msg2
push msg
call [printf]


mov dword [esp],p
call [system]
mov dword [esp],0
call [exit]

section '.idata' import data readable

library msvcrt, 'msvcrt.dll'
import msvcrt,\
printf, 'printf',\
scanf, 'scanf',\
system,'system',\
exit,'exit'

ASM Condition codes

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
 format PE console
entry main

include 'include\win32a.inc'
include 'INCLUDE\MACRO\import32.inc'

section '.data' data readable writeable
msg db "hello world!, %s, %d",0
msg2 db "dachmx",0
p db "pause>nul"
formatin db "%d", 0
integer1: times 4 db 0

section '.code' code readable executable
main:
push ebp
mov ebp, esp
sub ebp,4

push integer1 ; address of integer1
push formatin ; arguments are right to left
call [scanf]

mov eax, dword[integer1]

sub eax, 3

sub dword[integer1], 10

mov dword[integer1], eax

cmp eax, 110
jmp forloop1

forloop1:
add dword[integer1], 20
cmp dword[integer1], 150


push dword[integer1]
push msg2
push msg
call [printf]


mov dword [esp],p
call [system]
mov dword [esp],0
call [exit]

section '.idata' import data readable

library msvcrt, 'msvcrt.dll'
import msvcrt,\
printf, 'printf',\
scanf, 'scanf',\
system,'system',\
exit,'exit'

ref

assembly_conditions