-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssignment01.asm
More file actions
74 lines (56 loc) · 2.23 KB
/
Copy pathAssignment01.asm
File metadata and controls
74 lines (56 loc) · 2.23 KB
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
; ---------- QUESTION ----------
; Write an x86/64 ALP to accept five 64 bit hexadecimal numbers from the user and store them in an array and display the accepted numbers.
; ---------- DATA ----------
section .data
hello: db "Enter 5 hexadecimal digits: ", 0xA ; Message for user input
len: equ $-hello ; Length of the message
idk: db "The 5 numbers are: ", 0xA ; Message for displaying the numbers
len2: equ $-idk ; Length of the message
cnt1: db 05h ; Counter for input loop
cnt2: db 05h ; Counter for output loop
; ---------- BSS ----------
section .bss
arr resb 85 ; Buffer to store the input digits
; ---------- TEXT ----------
section .text
global _start
_start:
; Print "Enter 5 hexadecimal digits: " message
mov rax, 01
mov rdi, 01
mov rsi, hello
mov rdx, len
syscall
mov r8, arr ; Set r8 to point to the start of the buffer
l1:
; Read 17 characters (16 digits + newline) from stdin into the buffer
mov rax, 00
mov rdi, 00
mov rsi, r8
mov rdx, 17
syscall
add r8, 17 ; Move to the next set of characters in the buffer
dec byte[cnt1] ; Decrement the counter
JNZ l1 ; Jump to l1 if counter is not zero
; Print "The 5 numbers are: " message
mov rax, 01
mov rdi, 01
mov rsi, idk
mov rdx, len2
syscall
mov r8, arr ; Set r8 to point to the start of the buffer
l2:
; Print 17 characters (16 digits + newline) from the buffer to stdout
mov rax, 01
mov rdi, 01
mov rsi, r8
mov rdx, 17
syscall
add r8, 17 ; Move to the next set of characters in the buffer
dec byte[cnt2] ; Decrement the counter
JNZ l2 ; Jump to l2 if counter is not zero
; Exit the program
mov rax, 60 ; System call number for exit
mov rdi, 00 ; Exit status
syscall
ret ; Return from the _start function