-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmp.asm
138 lines (114 loc) · 2.44 KB
/
cmp.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
; 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
msg1 db "
ebx > eax", 0xa
msg2 db "ebx < eax", 0xa
MsgLen equ $-msg2 ;The length of the message
num1 dd ''
num2 dd ''
num3 dd ''
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
nop
mov eax, [num1]
mov ebx, [num2]
cmp ebx, eax ; test to see if ebx > eax
jge greater ; jump to "greatest" if true
mov edx, MsgLen ; msg length
mov ecx, msg2
mov ebx, 1 ; stdout
mov eax, 4 ; write
int 0x80
mov eax, 1 ;exit
int 0x80
greater:
mov edx, MsgLen
mov ecx, msg1
mov ebx, 1 ; stdout
mov eax, 4 ; write
int 0x80
mov eax, 1 ;exit
int 0x80