You are on page 1of 7

CS401 Assignment no 1 solution

Rashid Ahmad
BC210208554
Note:
Dear sir my laptop is not working for 2 weeks. So please be kind with me. I know how I managed to make
this assignment. Please don’t degrade me

Question no 1:

Write an assembly language program to store your Roll Number (Number part only) and
calculate their sum. Print a message on the screen that shows that the received number is
even or odd.
Answer:

org 100h ;Set the origin to 0x100

section.data

roll num mc'2,2,0,2,0,7,4,3,1 ; Roll number

roll_len equ $-roll num ;Length of the roll number string

section.text

global_start

_start

mov si, 0 ; Initialize

index mov cx, 0 ; Initialize sum

mov di. 0 ; initialize flag for even/odd

sum_loop:

mov al, byte[roll num+si] ; Load the byte from roll num string

sub al, 48 ; convert ASC11 digit to decimal


add cx, ax ; add the digit to te sum

inc si ;Increment index

cmp si, roll_len ; check if end of string

org 100h ;Set the origin to 0x100

section.data

roll num mc'2,2,0,2,0,7,4,3,1 ; Roll number

roll_len equ $-roll num ;Length of the roll number string

section.text

global_start

_start

mov si, 0 ; Initialize

index mov cx, 0 ; Initialize sum

mov di. 0 ; initialize flag for even/odd

sum_loop:

mov al, byte[roll num+si] ; Load the byte from roll num string

sub al, 48 ; convert ASC11 digit to decimal

add cx, ax ; add the digit to te sum

inc si ;Increment index

cmp si, roll_len ; check if end of string

mov ah,9h ;set the function code for print string lea

dx.[even_msg] ; load the address of the even messsage

int 21h ; call the DoS interruot

end program;

mov ah,4Ch ; set the function code for exit


xor al, al ; setthe exit code to 0

int 12h ; call the DoS interruot

section_data

odd_msg mc 'The received number is odd.' , 0Dh, 0Ah, '$' ; Message for odd number

even_msg mc 'The received number is odd.' , 0Dh, 0Ah, '$' ; Message for even number

Question no 2:

Find the offset address where Physical address is 4A37Bh and the segment address is
40FFh.

Answer:
The formula to calculate the offset address is:

Offset Address = (Segment Address × 16) + Physical Address

Let's calculate it:

Segment Address: 40FFh

Physical Address: 4A37Bh

Converting the Segment Address to

decimal: 40FFh= 16639

Converting the Physical Address to decimal:

4A37Bh=303995

Now, we can use the formula to find the offset address:

Offset Address = (16639 × 16) + 303995

Offset Address = 266224 +303995


Offset Address=570219

You might also like