Skip to content

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

License

Notifications You must be signed in to change notification settings

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🖥️ 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.


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

GitHub Issues

If you find any bugs, have suggestions, or face issues:

  • Open an Issue in the Issues Tab to discuss them.
  • Submit a Pull Request to propose fixes or improvements.
  • Review Pull Requests from other contributors to help maintain the project's quality and progress.

This project thrives on community collaboration! Members are encouraged to take the initiative, support one another, and actively engage in all aspects of the project. Whether it’s debugging, fixing issues, or brainstorming new ideas, your contributions are what keep this project moving forward.

With modern AI tools like ChatGPT, solving challenges and contributing effectively is easier than ever. Let’s work together to make this project the best it can be! 🚀

License

MIT

Copyright (c) 2018-present, harismuneer


Waving hand Hey there, I'm Haris Muneer 👨🏻‍💻

Total Github Stars Total Github Followers


  • 🕸️ Founder of Cyfy Labs: At Cyfy Labs, we provide advanced social media scraping tools to help businesses, researchers, and marketers extract actionable data from platforms like Facebook, Instagram, and X (formerly Twitter). Our tools support lead generation, sentiment analysis, market research, and various other use cases. To learn more, visit: www.cyfylabs.com

  • 🌟 Open Source Advocate: I’m passionate about making tech accessible. I’ve open-sourced several projects that you can explore on my GitHub profile and on the Open Source Software PK page.

  • 📫 How to Reach Me: You can learn more about my skills/work at LinkedIn. You can also reach out via email for collaboration or inquiries. For Cyfy Labs related queries, please reach out through the company website.


🤝 Follow my journey