0% found this document useful (0 votes)
14 views2 pages

Assembly Program for Counting Numbers

The document outlines an assignment for a Microprocessor Lab course at MES’s Wadia College of Engineering, focusing on writing an assembly language program to count positive and negative numbers in an array. It includes objectives, outcomes, prerequisites, hardware and software requirements, as well as a detailed algorithm for implementation. Additionally, it provides instructions for compiling and linking the assembly program using NASM and includes questions for further understanding of assembly language concepts.
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)
14 views2 pages

Assembly Program for Counting Numbers

The document outlines an assignment for a Microprocessor Lab course at MES’s Wadia College of Engineering, focusing on writing an assembly language program to count positive and negative numbers in an array. It includes objectives, outcomes, prerequisites, hardware and software requirements, as well as a detailed algorithm for implementation. Additionally, it provides instructions for compiling and linking the assembly program using NASM and includes questions for further understanding of assembly language concepts.
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

MES’s Wadia College of Engineering, Pune

SUBJECT: MICROPROCESSOR LAB (MPL)

NAME:

CLASS: SE COMP ROLL NO.:


SEMESTER: SEM-II YEAR: 2023-24

DATE OF PERFORMANCE: DATE OF SUBMISSION:

EXAMINED: Prof. G. B. Aochar

Assignment No-05
Title:- Count no. of positive and negative numbers
Assignment Name: - Write an ALP to count no. of positive and negative numbers from
the array.

Objective:-
● To understand the assembly language program
● To understand 64 bit interrupt.
Outcome:-
● Students will be able to write code for how to count positive and negative
number from array

● Students will be able to understand different assembly language instruction.

Prerequisite:-

System call of Unix for Assembly language Program.


Hardware Requirement-
Desktop PC
Software Requirement-
Ubuntu 14.04,
Assembler: NASM
version 2.10.07
Linker: ld

MPL Handouts Department of Computer Engg. 1


MES’s Wadia College of Engineering, Pune

Introduction:-
Write System Call

mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall

Read System Call

mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall

Compiling and Linking an Assembly Program in NASM


1. Type the above code using a text editor and save it as [Link].
2. Make sure that you are in the same directory as where you saved
[Link].
3. To assemble the program, type nasm -f elf64 [Link]
4. If there is any error, you will be prompted about that at this stage.
Otherwise an object file of your program named assignment1.o will be
created.
5. To link the object file and create an executable file named assignment1,
type ld -o assignment assignment1.o
6. Execute the program by typing ./assignment1

Algorithm:
1. Start
2. Initialize section .data
3. Define variable for array, pcount, ncount
4. Count Positive and negative number using BT command.
5. Display counts
6. Terminate program using system call
6. Stop
Conclusion:- Hence we implemented an ALP to count positive and negative
number from array and display count.
Questions:-
1. Explain BT,JS,loop instruction with Example?
2. Explain Paging in 80386?
3. Draw control registers of 80386

MPL Handouts Department of Computer Engg. 2

Common questions

Powered by AI

Control registers in the 80386 microprocessor primarily manage and control the execution context, processor operation, and system-wide configurations. These registers include Control Register 0 (CR0), which controls basic operations of the processor (e.g., enabling/disabling protected mode), and Control Register 3 (CR3), which handles paging, an essential aspect of virtual memory management that can impact system performance significantly by influencing how memory is accessed and organized. Effective management of these registers is crucial for optimizing performance and maintaining system stability .

Defining variables for arrays and counts in assembly language programs establishes specific memory locations for storing data and results, which is crucial for organizing and efficiently accessing information during execution. For tasks like counting positive and negative numbers, it allows the program to preserve the state between iterations, maintain running totals, and provide a clear structure to manipulate data with instructions like BT and JS, directly impacting program clarity and logic flow .

In systems like Ubuntu using NASM, the assembler plays the role of converting the human-readable assembly language code into machine code, generating an object file that contains this compiled code. The linker subsequently takes this object file, resolves symbolic references between files, and produces a final executable file by combining it with libraries and other object files required for execution. This process allows the assembly program to be executed on a system, transforming it efficiently into a runnable application .

The BT (Bit Test) instruction is used in assembly language programs to test a specific bit in a given register or memory location. In the context of counting numbers, it can be used to determine the sign of an integer by testing the most significant bit of the number; if the bit is set, the number is negative, otherwise it is positive. This allows the program to efficiently distinguish between positive and negative numbers in an array and increment the respective counts accordingly .

Learning different assembly language instructions is crucial for students as it enhances their understanding of how software interacts with hardware, deepens their grasp of computer architecture, and fosters skills in low-level programming which is vital for performance optimization and embedded systems development. It improves their debugging and analytical capabilities, allowing them to write more efficient programs and better understand complex systems, leading to improved overall programming skills .

Writing assembly language programs can be challenging due to the low-level nature of the language, requiring detailed understanding of hardware specifics and instruction sets. Challenges in counting positive and negative numbers include correctly handling signed integers, efficiently using processor instructions such as the BT and JS commands for control flow, and ensuring accurate counts. These can be addressed by thorough testing, step-by-step debugging to catch errors in logic and arithmetic, and employing system calls for input/output operations to handle user interactions effectively .

System calls are crucial in assembly language programs as they provide a mechanism for programs to request services from the operating system, such as input/output operations or memory management. In the context of counting positive and negative numbers from an array, system calls are used to handle reading from input and writing to output, enabling the program to interact with the user or file system. For instance, the provided system call examples ('mov rax,1; syscall' for write and 'mov rax,0; syscall' for read) are fundamental for these operations in Ubuntu using NASM .

Understanding paging in the 80386 processor allows programmers to efficiently manage virtual memory, which is critically important for writing code that utilizes memory resources optimally. Paging enables the processor to translate virtual addresses into physical addresses seamlessly, supporting the execution of larger programs than would fit in the physical RAM alone. This knowledge allows programmers to design systems that exploit memory hierarchy efficiently, minimize latency, and improve program execution speed and responsiveness .

The compilation and linking process in NASM involves converting written assembly code into machine code that the computer can execute. First, the assembly code is typed and saved using a text editor. Using NASM, the code is then assembled with the command 'nasm -f elf64', which generates an object file if free of errors. This object file, named '*.o', is then linked using a linker, such as 'ld', which combines the object file into a single executable file, ready for execution, by resolving all references and addressing within the code. This process ensures that the programmer's instructions are accurately represented as machine-readable instructions .

In assembly language programming, outputs such as the counts of positive and negative numbers are typically displayed using system calls that interact with the operating system's I/O facilities. Specifically, the 'mov rax,1; syscall' sequence is used to invoke the write system call, with appropriate registers set up to specify the output device (stderr or stdout), the message to be displayed, and its length. This approach allows the use of low-level I/O functions to output results directly to the screen .

You might also like