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

Verify A UPC Code To Check The Check Digit In ARM Assembly Language Using Keil Assignment Solution

July 06, 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
  • Instructions
  • Requirements and Specifications
Tip of the day
Use the REPL (Read-Eval-Print Loop) to test your code interactively, and practice writing concise, readable expressions to harness Scala’s powerful syntax effectively.
News
In 2024, JavaScript's Redux saw updates for efficient state management, and Tailwind CSS gained traction for responsive design. Meanwhile, C++ libraries like Boost.

Instructions

Objective

Write an ARM assignment program to verify a UPC code to check the check digit in ARM assembly language using Keil assignment solution.

Requirements and Specifications

Most goods sold in U.S. and Canadian stores are marked with a Universal Product Code (UPC). The meanings of the digits underneath the bar code (from left to right) are: First digit: type of item, The first group of five digits: manufacturer, The second group of five digits: product, and Final digit: check digit, used to help identify an error in the preceding digits. To compute the check digit, a) Add the first, third, fifth, seventh, ninth, and eleventh digits b) Add the second, fourth, sixth, eighth, and tenth digits c) Multiply the first sum by 3 and add it to the second sum d) The check digit is the digit which, when added to the above sum, produces a sum that is multiple of 10 Example for UPC 0 13800 15073 8: First sum: 0 + 3 + 0 + 1 + 0 + 3 = 7 Second sum: 1 + 8 + 0 + 5 + 7 = 21 Multiplying the first sum by 3 and adding the second yields 42 The check digit is 8, as 42 + 8 = 50 (multiple of 10). To verify the check digit, you do the first 3 steps above from a) to c) and then add the sum to the check digit. Finally, you check if the result is multiple of 10 or not. Write an ARM assembly program to verify whether a string of 12 ASCII encoded digits stored in memory is a valid UPC or not. If valid, you should store 1 in r0, if not, you should store 2 in r0. Your code should be highly optimized. Use as few instructions as possible (as little as 19 assembly instructions only, NOT including any assembly directives or data definitions)!!. Define in your assembly program the 12 digits UPC string as follow: UPC DCB "013800150738" ;correct UPC string To test your program, you can use the following UPCs: UPC2 DCB "060383755577" ;correct UPC string UPC3 DCB "065633454712" ;correct UPC string You can also get more UPC codes from your kitchen items. For an incorrect UPC, you can change any digit in a correct UPC to generate an incorrect UPC.

Screenshots of output

Verify UPC code to check digit in ARM assembly language using Keil
Verify UPC code to check digit in ARM assembly language using Keil 1
Verify UPC code to check digit in ARM assembly language using Keil 2
Verify UPC code to check digit in ARM assembly language using Keil 3

Source Code

UPC_LEN EQU 12 ; length of UPC code ASCII_0 EQU 0x30 ; ascii value for '0' AREA question1, CODE EXPORT __main ALIGN ENTRY __main PROC ; load UPC string to test LDR R1, =UPC ; load start address of upc to verify MOV R0, #1 ; assume number is valid by default ; Calculate the sum of 3 times the odd positions plus ; even positions including the last digit (check digit) ADD R2, R1, #UPC_LEN ; position of end of upc MOV R3, #0 ; sum, start in zero sumloop LDRB R4, [R1], #1 ; load digit from upc string and increment position SUB R4, R4, #ASCII_0 ; convert from ascii to decimal ADD R4, R4, R4, LSL#1 ; multiply by 3 using a shift and a sum ADD R3, R3, R4 ; add to sum LDRB R4, [R1], #1 ; load next digit from upc string SUB R4, R4, #ASCII_0 ; convert from ascii to decimal ADD R3, R3, R4 ; add value to sum CMP R1, R2 ; see if we reached the end of upc BLT sumloop ; if not, repeat loop to add next values ; verify that the result is divisible by 10 ; obtain the remainder of result by 10 using repeated subtractions div10 SUBS R3, R3, #10 ; subtract 10 from value to emulate division BEQ verified ; if zero, number is divisible by 10 and upc is valid BGT div10 ; if >0, repeat loop to subtract again MOV R0, #2 ; if we end here is not a valid upc (remainder is not zero) verified ; At this point, R0 will be 1 for a valid UPC and 2 otherwise B verified ; infinite loop to end program ENDP ALIGN AREA TestData, DATA, READONLY UPC DCB "013800150738" ;correct UPC string UPC2 DCB "060383755577" ;correct UPC string UPC3 DCB "065633454712" ;correct UPC string UPC4 DCB "013400150738" ;incorrect UPC string UPC5 DCB "060383758577" ;incorrect UPC string UPC6 DCB "065633954719" ;incorrect UPC string END

Related Samples

Explore our collection of free assembly language assignment samples. Gain insights into efficient coding techniques and intricate program structures. Access these resources to enhance your understanding and excel in assembly language programming effortlessly.