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
UPC_LEN EQU 12 ; length of UPC codeASCII_0 EQU 0x30 ; ascii value for '0'AREA question1, CODEEXPORT __mainALIGNENTRY__main PROC; load UPC string to testLDR R1, =UPC ; load start address of upc to verifyMOV 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 upcMOV R3, #0 ; sum, start in zerosumloopLDRB R4, [R1], #1 ; load digit from upc string and increment positionSUB R4, R4, #ASCII_0 ; convert from ascii to decimalADD R4, R4, R4, LSL#1 ; multiply by 3 using a shift and a sumADD R3, R3, R4 ; add to sumLDRB R4, [R1], #1 ; load next digit from upc stringSUB R4, R4, #ASCII_0 ; convert from ascii to decimalADD R3, R3, R4 ; add value to sumCMP R1, R2 ; see if we reached the end of upcBLT 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 subtractionsdiv10SUBS R3, R3, #10 ; subtract 10 from value to emulate divisionBEQ verified ; if zero, number is divisible by 10 and upc is validBGT div10 ; if >0, repeat loop to subtract againMOV 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 otherwiseB verified ; infinite loop to end programENDPALIGNAREA TestData, DATA, READONLYUPC DCB "013800150738" ;correct UPC stringUPC2 DCB "060383755577" ;correct UPC stringUPC3 DCB "065633454712" ;correct UPC stringUPC4 DCB "013400150738" ;incorrect UPC stringUPC5 DCB "060383758577" ;incorrect UPC stringUPC6 DCB "065633954719" ;incorrect UPC stringEND