harismuneer / Bit-Manipulation-and-Subroutines-8086_Assembly

🖥️ Interesting solved problems demonstrating the concepts of Bit Manipulation and Subroutines (Functions) in 8086 Assembly Language.

Home Page:https://github.com/harismuneer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🖥️ Bit Manipulation and Subroutines -8086 Assembly

views Open Source Love svg1 GitHub Forks GitHub Issues contributions welcome

I solved all these questions and shared the solutions here so that you can have a strong grip on these concepts with ready to run interesting solved problems.

Reference Book

The questions are taken from the book Assembly Language Programming by Belal Hashmi and Junaid Haroon

Its an excellent book for understanding the language and concepts of 8086 Assembly. It starts from the very basics and then takes you to advanced concepts in an efficient manner. Highly Recommended!

How to Run

1- Download this code and move the 'assembly_code' folder to C: directory.

2- Install DOSBOX from this link: Download DOSBOX Emulator

3- After complete installation, go to DOSBOX installation directory and run "DOSBox 0.74 Options.bat". This will save you from the pain of searching the configuration file yourself and will open that file for you. Copy these lines at the end of that file:

mount c: c:\assembly_code 
c:

4- Now to run any question (say named 'chp4_03.asm'), run DOSBOX 0.74 and type

nasm chp4_03.asm -o chp4_03.com  

To run the code, type:

chp4_03.com

To examine step by step working of the code, type

afd chp4_03.com

Problems Solved

Question 1: (Exercise of Chp 4 - Bit Manipulation)

  • Q-1. Write a program to swap every pair of bits in the AX register.
  • Q-3. Write a program to swap the nibbles in each byte of the AX register.
  • Q-4. Calculate the number of one bits in BX and complement an equal number of least significant bits in AX.
  • Q-5. Write a program to multiply two 32bit numbers and store the answer in a 64bit location.
  • Q-6. Declare a 32byte buffer containing random data. Consider for this problem that the bits in these 32 bytes are numbered from 0 to 255. Declare another byte that contains the starting bit number. Write a program to copy the byte starting at this starting bit number in the AX register. Be careful that the starting bit number may not be a multiple of 8 and therefore the bits of the desired byte will be split into two bytes.
  • Q-7. AX contains a number between 0-15. Write code to complement the corresponding bit in BX. For example if AX contains 6; complement the 6th bit of BX.
  • Q-8. AX contains a non-zero number. Count the number of ones in it and store the result back in AX. Repeat the process on the result (AX) until AX contains one. Calculate in BX the number of iterations it took to make AX one.

Question 2: (Exercise of Chp 5 - Subroutines)

  • Q-3. Write a recursive function to calculate the Fibonacci of a number. The number is passed as a parameter via the stack and the calculated Fibonacci number is returned in the AX register. A local variable should be used to store the return value from the first recursive call. Fibonacci function is defined as follows: Fibonacci(0) = 0 Fibonacci(1) = 1 Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2)
  • Q-4. Write the above Fibonacci function iteratively.
  • Q-5. Write a function switch_stack meant to change the current stack and will be called as below. The function should destroy no registers. push word [new_stack_segment] push word [new_stack_offset] call switch_stack
  • Q-8. Make an array of 0x80 bytes and treat it as one of 0x400 bits. Write a function myalloc that takes one argument, the number of bits. It p, and returns in AX the index of the first bit. Write another function myfree that takes two arguments, index of a bit in the array, and the number of bits. It makes that many consecutive bits zero, whatever their previous values are, starting from the index in the first argument.


Hey there, I'm Haris Ultimate Facebook Scraper (UFS) - Maker of Things

Creator of Ultimate Facebook Scraper (one of the best software to collect Facebook data for research & analysis)


🌐 Connect

🤝 Consulting / Coaching

Stuck with some problem? Need help in solution development, guidance, training or capacity building? I am a Full Stack Engineer turned Project Manager with years of technical and leadership experience in a diverse range of technologies and domains. Let me know what problem you are facing at haris.muneer5@gmail.com and we can schedule a consultation meeting to help you get through it.

👨‍💻 Technical Skills & Expertise

  • Development of Web Applications, Mobile Applications, and Desktop Applications
  • Development of Machine Learning/Deep Learning models, and deployment
  • Web Scraping, Browser Automation, Python Scripting

❤️ Support / Donations

If you or your company use any of my projects, like what I’m doing or have benefited from my projects in any way then kindly consider backing my efforts.

For donations, you can follow these simple steps:

1) Free signup at TransferWise using this link: https://transferwise.com/invite/u/harism95. (Signing up through this link will save you from any transcation fee on the donation)

2) Select the amount e.g (15$) and choose the receiving/recipient's currency to be PKR. It supports multiple payment options (credit card, debit card, wire transfer etc)

3) Then it will show my info as the recipient, select it. If my name isn't shown, then type my email haris.muneer5@gmail.com in recipients.

4) Choose the reason for transfer to the one that suits you the most (in this case it could be 'General expenses') and in the reference section, you can mention 'Support'

If you face any issue in sending donation then feel free to get in touch with me at haris.muneer5@gmail.com

Thank you for your contribution!

Author

You can get in touch with me on my LinkedIn Profile: LinkedIn Link

You can also follow my GitHub Profile to stay updated about my latest projects: GitHub Follow

If you liked the repo then kindly support it by giving it a star ⭐ and share in your circles so more people can benefit from the effort.

Contributions Welcome

forthebadge

If you find any bug in the code or have any improvements in mind then feel free to generate a pull request.

Issues

GitHub Issues

If you face any issue, you can create a new issue in the Issues Tab and I will be glad to help you out.

License

MIT

Copyright (c) 2018-present, harismuneer