KEMBAR78
Cs401 Assignment 11 Spring 2025 | PDF
0% found this document useful (0 votes)
27 views2 pages

Cs401 Assignment 11 Spring 2025

The document contains an assembly language program for CS401 Assignment 1 that calculates the sum of a predefined array of digits and computes the difference between the sum and each digit. It initializes data segments, performs summation in a loop, and then calculates the differences in a second loop. The program terminates gracefully after execution.

Uploaded by

nehanazish81
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)
27 views2 pages

Cs401 Assignment 11 Spring 2025

The document contains an assembly language program for CS401 Assignment 1 that calculates the sum of a predefined array of digits and computes the difference between the sum and each digit. It initializes data segments, performs summation in a loop, and then calculates the differences in a second loop. The program terminates gracefully after execution.

Uploaded by

nehanazish81
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/ 2

Cs401 Assignment1

Cs230427787
Solution:
.model small

.stack 100h

.data

vuid_digits db 2, 3, 0, 4, 2, 7, 7, 8, 7 ; Array of digits from


"230427787"

sum_result db 0 ; To store the sum of digits

result_array db 9 dup(?) ; To store (sum - digit) for each


digit

.code

main:

mov ax, @data

mov ds, ax

; Initialize registers

xor cx, cx ; cx will count number of digits (9 in this case)

xor si, si ; index for input array

xor al, al ; AL will hold the sum of digits

sum_loop:

mov bl, vuid_digits[si]

add al, bl ; Add digit to sum

inc si

inc cx

cmp cx, 9

jne sum_loop
mov sum_result, al ; Store the sum of digits

; Second loop to compute sum - digit for each and store

xor cx, cx ; Reset digit counter

xor si, si ; Reset index for vuid_digits

xor di, di ; Index for result_array

mov bl, sum_result ; Load sum into bl

sub_loop:

mov al, bl ; Copy sum to AL

sub al, vuid_digits[si] ; Subtract current digit

mov result_array[di], al ; Store result

inc si

inc di

inc cx

cmp cx, 9

jne sub_loop

; Terminate program

mov ah, 4ch

int 21h

end main

You might also like