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

## 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    ```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 ```