-
Notifications
You must be signed in to change notification settings - Fork 0
/
Addition_by_taking_inputs.txt
71 lines (59 loc) · 1.23 KB
/
Addition_by_taking_inputs.txt
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
section .data
prompt db 'Enter the first single-digit number: ', 0
prompt2 db 'Enter the second single-digit number: ', 0
result_msg db 'The sum is: ', 0
newline db 10, 0
section .bss
num1 resb 1
num2 resb 1
sum resb 1
section .text
global _start
_start:
; Display the prompt and read the first number
mov eax, 4
mov ebx, 1
mov ecx, prompt
mov edx, 32
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, num1
mov edx, 1
int 0x80
; Display the second prompt and read the second number
mov eax, 4
mov ebx, 1
mov ecx, prompt2
mov edx, 35
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, num2
mov edx, 1
int 0x80
; Convert ASCII digits to integers
mov al, [num1]
sub al, '0'
mov bl, [num2]
sub bl, '0'
; Add the numbers
add al, bl
; Convert the result back to ASCII
add al, '0'
; Display the result
mov eax, 4
mov ebx, 1
mov ecx, result_msg
mov edx, 13
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, sum
mov [ecx], al
mov edx, 1
int 0x80
; Exit the program
mov eax, 1
mov ebx, 0
int 0x80