0% found this document useful (0 votes)
9 views5 pages

Assignment-5 MAM

The document outlines an assignment for a microprocessor and microcontroller course, where the task is to write assembly language code to identify and count positive and negative numbers from a predefined array. It details the data section, computation logic, and control flow of the program, including macros for efficiency and system calls for output. The provided code demonstrates the implementation of these functionalities, including the display of results for positive and negative counts.

Uploaded by

Arpit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Assignment-5 MAM

The document outlines an assignment for a microprocessor and microcontroller course, where the task is to write assembly language code to identify and count positive and negative numbers from a predefined array. It details the data section, computation logic, and control flow of the program, including macros for efficiency and system calls for output. The provided code demonstrates the implementation of these functionalities, including the display of results for positive and negative counts.

Uploaded by

Arpit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Bansilal Ramnath Agarwal Charitable Trust’s

VISHWAKARMA INSTITUTE OF TECHNOLOGY – PUNE

MICROPROCESSOR AND MICROCONTROLLER

Division A

Batch 3

GR-no 12310414

Roll no 24

Name Arpit Dalal

Assignment 1:

TITLE:- Write an ALP to find positive number and negative


numbers from the array of signed number stored in
memory and display magnitude of negative and positive
numbers
Description:-
1. Data Section:

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.

4. Macros for Efficiency:

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:

You might also like