cs401 assignment 2 sol
cs401 assignment 2 sol
Student Id:BC220412988
Write a program that will sum your VU Student ID (excluding the first two alphabets)
and then determine if the result is even or not.
Details:
I Store your Student ID, excluding the first two alphabets, in an array. For example,
if your Student ID is BC123456789 then create an array that will have 1, 2, 3, 4, 5, 6, 7,
8, 9 as its elements.
II When calculating the sum, there is no need to use counter register. You can
directly perform calculations by accessing elements from array and adding them in the
accumulator register.
III When determining if the resultant sum is even, use appropriate bitwise operator
and jump instructions.
Screenshot Requirements:
Provide AFD screenshot after you have successfully run your code.
In the screenshot:
; Task: Store Student ID digits, calculate sum, and check if even or odd
start:
; Initialize sum to 0
sum_digits:
; Add current digit to sum (AL register is used here, which is 8-bit)
add al, [si] ; Add the current digit from studentID array to AL
mov [sum], al ; Store the sum in the sum variable (Memory Area 1)
test al, 1 ; Test if the least significant bit is set (odd/even check)
mov dx, 0
jmp done
even:
mov dx, 1
done:
Screenshot: