Assignment-5 MAM
Assignment-5 MAM
Division A
Batch 3
GR-no 12310414
Roll no 24
Assignment 1:
1. The program defines a data section that includes an array of signed numbers (values
db 20, 28, -30, 64, -50, -19, 67).
2. It also defines messages for displaying results and necessary formatting characters (such
as a newline and a space).
2. Computation of Positive and Negative Counts:
1. The compute_counts function iterates over the array and checks each number.
2. If the number is negative, it increments the negative counter (rdx).
3. Otherwise, it increments the positive counter (rbx).
3. Displaying Results:
1. The counts of positive and negative numbers are printed using system calls (syscall).
2. The show_number function converts the count into a printable ASCII format and
displays it.
1. print_msg macro is used for printing messages using the syscall instruction.
2. terminate macro gracefully exits the program.
5. Control Flow:
1. The program starts execution from _start, which calls compute_counts, displays
results, and terminates execution.
2. compute_counts processes the numbers in a loop, checking the sign of each number.
3. show_number converts the numerical value to ASCII for display.
Code:
section .bss
result resb 1
section .data
positive_msg db "Count of Positive Nos. :",
pos_len equ $-positive_msg
negative_msg db "Count of Negative Nos. :"
neg_len equ $-negative_msg
newline db "", 0ah
gap db " ",
values db 20,28,-30,64,-50,-19,67
%macro print_msg 2
mov rax, 1
mov rdi, 1
mov rsi, %1
mov rdx, %2
syscall
%endmacro
%macro terminate 0
mov rax, 60
xor rdi, rdi
syscall
%endmacro
section .text
global _start
_start:
call compute_counts
push rdx
print_msg positive_msg, pos_len
print_msg gap, 1
mov rax, rbx
call show_number
print_msg newline, 1
print_msg negative_msg, neg_len
print_msg gap, 1
pop rdx
mov rax, rdx
call show_number
terminate
compute_counts:
mov rcx, 7
mov rbx, 0
mov rdx, 0
mov rsi, values
loop_start:
mov al, 00
add al, [rsi]
js negative_inc
inc rbx
jmp continue_loop
negative_inc:
inc rdx
continue_loop:
inc rsi
dec rcx
jnz loop_start
ret
show_number:
mov rbx, 16
mov rcx, 1
mov rsi, result
convert:
xor rdx, rdx
div rbx
cmp dl, 9
jbe add_offset
add dl, 7h
add_offset:
add dl, 30h
mov [rsi], dl
dec rsi
dec rcx
jnz convert
mov rdx, 2
print_msg result, rdx
ret
Screenshots/Output: