×
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
Start with basic image processing concepts like color spaces and transformations. Practice simple OpenCV examples to build confidence before tackling complex tasks.
News
In 2024, the release of the 'AsyncIO Toolkit' has made asynchronous programming in Python more efficient. Similarly, 'React Quantum' introduces quantum computing concepts to JavaScript, expanding learning opportunities for students.

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.