Assignment_5_MIC
Assignment_5_MIC
section .data
prompt db "Enter the numbers (end with 0): ", 0
prompt_len equ $ - prompt
msg_pos db "Count of Positive numbers: ", 0
msg_pos_len equ $ - msg_pos
msg_neg db "Count of Negative numbers: ", 0
msg_neg_len equ $ - msg_neg
newline db 10, 0
buffer db 10 ; Buffer to hold each number input as a string
section .bss
pcount resb 1 ; Count of positive numbers
ncount resb 1 ; Count of negative numbers
num resb 1 ; Temp storage for each number character
input resb 1 ; Variable to hold individual number input
section .text
global _start
_start:
; Initialize counts
mov byte [pcount], 0
mov byte [ncount], 0
; Print prompt
mov rax, 1
mov rdi, 1 ; file descriptor: stdout
mov rsi, prompt ; pointer to prompt
mov rdx, prompt_len; length of prompt
syscall
input_loop:
; Read number input
mov rdi, input ; buffer for input
call read_input
movzx rax, byte [input] ; Load the number (ASCII)
count_negative:
inc byte [ncount] ; Increment negative count
jmp input_loop ; Continue input loop
print_counts:
; Print count of positive numbers
mov rax, 1
mov rdi, 1
mov rsi, msg_pos
mov rdx, msg_pos_len
syscall
; Print newline
mov rax, 1
mov rdi, 1
mov rsi, newline
mov rdx, 1
syscall
.print_zero:
; Print '0' directly
mov byte [num], '0'
mov rax, 1
mov rdi, 1
mov rsi, num
mov rdx, 1
syscall
Ret
Output :