0% found this document useful (0 votes)
13 views3 pages

Upload Cs 401 Ass 2

Uploaded by

mubashirejaz589
Copyright
© © All Rights Reserved
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
0% found this document useful (0 votes)
13 views3 pages

Upload Cs 401 Ass 2

Uploaded by

mubashirejaz589
Copyright
© © All Rights Reserved
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/ 3

ID=BC230218902

Computer Architecture and Assembly Language Programming Practical

(CS401P)

Assignment No. 2

Solution:

Code:

[org 0x0100] ; Program starts at offset 0x0100

jmp start ; Jump to start of program

st db 2, 3, 0, 2, 1, 8, 9, 0, 2

sum db 0 ; Memory location for storing sum of digits

res db 0 ; Result to store 0 (not divisible by 3) or 1 (divisible by 3)

start:

; Initialize sum to 0

xor ax, ax ; Clear AX register (used for summing)

lea si, [st] ; Load address of the student ID array into SI

; Add the digits from the array to AL (AX will hold the sum)

add al, [si] ; Add first digit (1)

inc si ; Move to next digit

add al, [si] ; Add second digit (2)

inc si ; Move to next digit

add al, [si] ; Add third digit (3)


inc si ; Move to next digit

add al, [si] ; Add fourth digit (4)

inc si ; Move to next digit

add al, [si] ; Add fifth digit (5)

inc si ; Move to next digit

add al, [si] ; Add sixth digit (6)

inc si ; Move to next digit

add al, [si] ; Add seventh digit (7)

inc si ; Move to next digit

add al, [si] ; Add eighth digit (8)

inc si ; Move to next digit

add al, [si] ; Add ninth digit (9)

; Store the sum 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 divisible by 3

xor dx, dx ; Clear DX (used for remainder check)

mov cx, 3 ; Set divisor to 3

div cx ; Divide AX (sum) by 3; result in AX, remainder in DX

; If remainder (DX) is 0, it is divisible by 3

cmp dx, 0 ; Compare remainder (DX) with 0

jz divisible_by_3 ; If remainder is 0, jump to divisible_by_3

; If not divisible by 3, store 0 in DX

mov dx, 0

jmp done

divisible_by_3:
; If divisible by 3, store 1 in DX

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

Screenshot

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy