-
Notifications
You must be signed in to change notification settings - Fork 0
/
mul (4).s
133 lines (107 loc) · 1.75 KB
/
mul (4).s
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
SYSEXIT = 1
SYSREAD = 3
SYSWRITE = 4
STDIN = 0
STDOUT = 1
EXIT_SUCCESS = 0
MULTIPLICAND=8
MULTIPLIER=8
FINAL=512
LAST_LOOP=1
.align 64
.macro exit code
movl $SYSEXIT, %eax
movl \code, %ebx
int $0x80
.endm
.macro write str, len
movl $SYSWRITE, %eax
movl $STDOUT, %ebx
movl \str, %ecx
movl \len, %edx
int $0x80
.endm
.data
number1:
.space MULTIPLICAND
number2:
.space MULTIPLIER
return:
.zero FINAL
.text
.global _start
_start:
read:
movl $SYSREAD, %eax
movl $STDIN, %ebx
movl $number1, %ecx
movl $MULTIPLICAND, %edx
int $0x80
movl $SYSREAD, %eax
movl $STDIN, %ebx
movl $number2, %ecx
movl $MULTIPLIER, %edx
int $0x80
cmpl $0, %eax
je ex
movl $-1, %edi #licznik mnoznej number1
movl $0, %ebx #rejestr na przechowywanie przeniesienia z eax
multiplicand: #petla mnoznej
incl %edi #petla mnoznej
cmpl $(MULTIPLICAND/4), %edi
jge ex
movl %edi, %esi #petla mnoznika
movl $0, %ebp #licznik do pobierania kolejnych cyfr mnoznika
movl number1(,%edi,4), %ecx
clc
pushf
multiplier: #petla mnoznika
cmpl $(MULTIPLICAND/4),%ebp
jge multiplicand
movl number2(,%ebp,4), %eax
mul %ecx
cmpl $LAST_LOOP, %ebp
jge test # musi byc nie tylko ostatnia petla mnoznej ale i mnoznika
sum_up:
popf
adcl %eax, return(,%esi,4)
pushf
incl %esi
cmp $1, %ebx
je set_CF
clc
jmp add
add:
addl %edx, return(,%esi,4)
jc save_CF
movl $0, %ebx
jmp dalej
dalej:
incl %ebp
jmp multiplier
test:
cmpl $LAST_LOOP, %edi
jge last_one
jmp sum_up
set_CF:
stc
jmp add
save_CF:
movl $1, %ebx
jmp dalej
last_one: #ostatnia petla mnoznej gdyby na ostatnim dodawaniu wyszlo przenisienie
addl %eax, return(,%esi,4)
incl %esi
cmpl $1, %ebx
je with_flag
adcl %edx, return(,%esi,4)
adcl $0, return(,%esi,4)
jmp ex
with_flag:
stc
adcl %edx, return(,%esi,4)
adcl $0,return (,%esi,4)
jmp ex
ex:
write $return, $32
exit $0