We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
CS401
ASSIGNMENT 2 BC220410978
Code
[org 0x0100] ; Program starts at offset 0x0100
jmp start ; Jump to start of program ; Task: Store Student ID digits, calculate sum, and check if even or odd st db 2, 2, 0, 4, 1, 0, 9, 7, 8 ; Student ID digits excluding "BC" (1-9) sum db 0 ; Memory location for storing sum of digits res db 0 ; Result to store 0 (odd) or 1 (even) start: ; Initialize sum to 0 xor ax, ax ; Clear AX (used for summing) lea si, [st] ; Corrected: Load address of the studentID array into SI mov cx, 9 ; We have 9 digits in the student ID (1-9) 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 inc si ; Move to the next digit in the array loop sum_digits ; Repeat until all digits are summed ; Store the result in 'sum' (the sum of digits in AL) mov [sum], al ; Store the sum in the sum variable (Memory Area 1) ; Check if the sum is even or odd using bitwise AND test al, 1 ; Test if the least significant bit is set (odd/even check) jz even ; If zero, the sum is even, jump to even label ; If odd, store 0 in DX (odd) mov dx, 0 jmp done even: ; If even, store 1 in DX (even) mov dx, 1 done: ; Exit program (return control to DOS) mov ax, 4C00h ; DOS interrupt to terminate program int 21h ; Call DOS interrupt to exit the program Sample Output