-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmpTest.asm
153 lines (123 loc) · 2.7 KB
/
cmpTest.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
; Assemble as: nasm -f elf -g readwrite.asm
; Link as: ld -m elf_i386 -o readwrite readwrite.o
section .data ;Data segment
prompt db 'Enter a number: '
StrLen equ $-prompt
DispNum db 'You entered: '
DispNumLen equ $-DispNum
msg db "The largest digit is: "
len equ $- msg
num1 dd ''
num2 dd ''
num3 dd ''
num4 dd ''
newLine db 0xa
NewLen equ $- newLine
section .bss ;Uninitialized data
num resb 5
section .text ;Code Segment
global _start
_start:
;1
;Prompt User
mov eax, 4
mov ebx, 1 ; descriptor value for stdout
mov ecx, prompt
mov edx, StrLen
int 80h
;Read and store the user input
mov eax, 3
mov ebx, 0 ; descriptor value for stdin
mov ecx, num1
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Prompt for a number
mov eax, 4
mov ebx, 1
mov ecx, DispNum
mov edx, DispNumLen
int 80h
;Output the number entered
mov eax, 4
mov ebx, 1
mov ecx, num1
mov edx, 5
int 80h
;2
;Prompt User
mov eax, 4
mov ebx, 1 ; descriptor value for stdout
mov ecx, prompt
mov edx, StrLen
int 80h
;Read and store the user input
mov eax, 3
mov ebx, 0 ; descriptor value for stdin
mov ecx, num2
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Prompt for a number
mov eax, 4
mov ebx, 1
mov ecx, DispNum
mov edx, DispNumLen
int 80h
;Output the number entered
mov eax, 4
mov ebx, 1
mov ecx, num2
mov edx, 5
int 80h
;3
;Prompt User
mov eax, 4
mov ebx, 1 ; descriptor value for stdout
mov ecx, prompt
mov edx, StrLen
int 80h
;Read and store the user input
mov eax, 3
mov ebx, 0 ; descriptor value for stdin
mov ecx, num3
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Prompt for a number
mov eax, 4
mov ebx, 1
mov ecx, DispNum
mov edx, DispNumLen
int 80h
;Output the number entered
mov eax, 4
mov ebx, 1
mov ecx, num3
mov edx, 5
int 80h
mov ecx, [num1]
cmp ecx, [num2]
jg check_third_num
mov ecx, [num3]
check_third_num:
cmp ecx, [num3]
jg
mov ecx, [num3]
; Exit code
mov [num4], ecx
mov ecx,msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx,num4
mov edx, 2
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
; print newline
mov edx, NewLen ; msg length
mov ecx, newLine
mov ebx, 1 ; stdout
mov eax, 4 ; write
int 0x80
mov eax, 1 ; exit
int 80h