-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab4.Asm
118 lines (102 loc) · 2.41 KB
/
lab4.Asm
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
; Template for console application
.586
.MODEL flat, stdcall
OPTION CASEMAP:NONE
Include kernel32.inc
Include masm32.inc
IncludeLib kernel32.lib
IncludeLib masm32.lib
.CONST
MsgExit DB 10,13,"Press Enter to Exit",10,13,0
.DATA
MsgInp db "Input array with spaces: ",10,13,0
MsgOrg db "Original array: ",0
MsgRes db 10,13,"Result array: ",0
space db " "
.DATA?
inbuf DB 100 DUP (?)
arr_str DB 200 dup (?)
len_str dd ?
arr dd 28 dup (?)
len dd ?
res db 10 dup (?)
.CODE
Start:
Invoke StdOut,ADDR MsgInp
Invoke StdIn,ADDR arr_str,LengthOf arr_str
sub eax, 2
mov len_str, eax
Invoke StripLF,ADDR arr_str
cld
lea edi, arr_str
mov ecx, len_str
mov ebx, 0
CycleS:
push ecx
Invoke atol, edi
mov arr[ebx*4], eax
inc ebx
pop ecx
mov al, space
repne scasb
je CycleS
mov len, ebx
Invoke StdOut,ADDR MsgOrg
mov esi, 0
OutpOrg:
Invoke dwtoa, arr[esi*4], ADDR res
Invoke StdOut, ADDR res
Invoke StdOut, ADDR space
inc esi
cmp esi, len
jl OutpOrg
mov esi, 0
mov edi, 0
Cycle:
cmp arr[esi*4],0
jl Nego
jg Pos
jmp Next
Nego:
mov ebx, edi
inc edi
cmp esi, ebx
je Next
jmp Cont
Pos:
cmp esi, edi
je Next
mov ebx, edi
inc ebx
Cont:
mov ecx, esi
;Start Shift
mov eax, arr[ecx*4]
push eax
CycleSh:
dec ecx
mov eax, arr[ecx*4]
mov arr[ecx*4 + 4], eax
cmp ecx, ebx
jg CycleSh
pop eax
mov arr[ecx*4], eax
;End Shift
Next:
inc esi
cmp esi, len
jl Cycle
Invoke StdOut,ADDR MsgRes
mov esi, 0
OutpRes:
Invoke dwtoa, arr[esi*4], ADDR res
Invoke StdOut, ADDR res
Invoke StdOut, ADDR space
inc esi
cmp esi, len
jl OutpRes
XOR EAX,EAX
Invoke StdOut,ADDR MsgExit
Invoke StdIn,ADDR inbuf,LengthOf inbuf
Invoke ExitProcess,0
End Start