×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Binary search in a sorted array using CUSP assembly assignment help

July 11, 2024
Rehana Magnus
Rehana Magnus
🇨🇦 Canada
Assembly Language
Rehana Magnus, PhD in Computer Science from the esteemed Acadia Institute of Technology, Canada. With 6 years of experience, specializes in assembly language programming. Proficient in low-level coding, optimizing performance, and enhancing system functionality.
Key Topics
  • Searching a Number in an Array Address
Tip of the day
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

The assignment deals with searching a number in a sorted array using CUSP assembly. The program takes a number to search from a determined address in memory and an array that starts at a predetermined address in memory. The program uses binary search to search the number in the array. The search result is saved in the accumulator. In the following code, our providers of CUSP assembly assignment help demonstrate binary search to show you the quality of the work we do.

Searching a Number in an Array Address

Binary search in a sorted array using CUSP assembly assignment help

CUSP Assembly Code for Binary Search .EQU NUMBER, $100 .EQU N, $101 .EQU SORTED, $102 .EQU @,$000 ; program start address LDS# $E00 ; initialize stack to $E00 BinSearch: LDA# 0 ; start left index in 0 STA LEFT ; update variable LDA N ; load number of elements in acc SBA# 1 ; start right index in n-1 = 5 STA RIGHT ; update variable Search: LDA LEFT ; load LEFT index value in ACC CMA RIGHT ; see if LEFT <=RIGHT JGT fail ; if not, end search, we didn't find the number ADA RIGHT ; Add LEFT+RIGHT SHRA ; divide by 2 using a shift right to get the middle TAX ; save middle index in X LDA NUMBER ; load number to search in ACC CMA+ SORTED ; compare number with SORTED[middle] JEQ found ; if they are equal, we found it JLT setright ; if the number is < middle, adjust right index setleft: ; else, number > middle, adjust left index ADX# 1 ; calculate middle+1 STX LEFT ; set LEFT = middle+1 JMP Search ; search again setright: SBX# 1 ; calculate middle-1 STX RIGHT ; set RIGHT = middle-1 JMP Search ; search again found: LDA# 1 ; set acc to 1 to indicate found JMP done ; terminate program fail: LDA# 0 ; set acc to 0 to indicate not found done: HLT ; Variables for the search: LEFT: .WORD 0 RIGHT: .WORD 5 .END

Related Samples

Explore our free assembly language assignment samples showcasing practical solutions and coding techniques. These examples illustrate various assembly language concepts and programming challenges, offering valuable insights and guidance for your assignments and projects.