[go: up one dir, main page]

0% found this document useful (0 votes)
23 views4 pages

CS401 Assignment-2 Solution Spring 2025

This document contains an assembly language program designed to display a student VUID on a blue background. It includes subroutines for clearing the screen and printing a string at specified screen coordinates. The program is structured to run in a DOS environment and terminates properly after displaying the VUID.

Uploaded by

m.salman.f2005
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)
23 views4 pages

CS401 Assignment-2 Solution Spring 2025

This document contains an assembly language program designed to display a student VUID on a blue background. It includes subroutines for clearing the screen and printing a string at specified screen coordinates. The program is structured to run in a DOS environment and terminates properly after displaying the VUID.

Uploaded by

m.salman.f2005
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/ 4

CS401 Assignment-2 Solution Spring 2025:

; Assembly Language Program to Display VUID with Blue Background

; Student VUID: BC250212345 (Replace with your actual VUID)

[org 0x0100]

Jmp start

Message: db ‘BC250212345’ ; YOUR VUID TO BE PRINTED (Replace with your


VUID)

Length: dw 11 ; length of the message

; Modify clrscr subroutine to clear the screen with Blue background

Clrscr: push es

Push ax

Push di

Mov ax, 0xb800 ; video memory segment

Mov es, ax ; point es to video base

Mov di, 0 ; point di to top left column

Mov ax, 0x1720 ; blue background (17h) with space character (20h)

Nextloc:

Mov word [es:di], ax ; clear current position with blue background

Add di, 2 ; move to next screen location

Cmp di, 4000 ; has the whole screen cleared

Jne nextloc ; if no clear next position


Pop di

Pop ax

Pop es

Ret

; subroutine to print a string

; takes x position, y position, string attribute, address of string

; and its length as parameters

Printstr:

Push bp

Mov bp, sp

Push es

Push ax

Push cx

Push si

Push di

; Calculate screen position

; Screen position = (y * 80 + x) * 2

Mov ax, [bp+10] ; load y position

Mov cx, 80 ; 80 characters per line

Mul cx ; y * 80

Add ax, [bp+12] ; add x position

Shl ax, 1 ; multiply by 2 (each char takes 2 bytes)

Mov di, ax ; di = screen offset


Mov ax, 0xb800 ; video memory segment

Mov es, ax ; point es to video memory

Mov si, [bp+6] ; load address of string

Mov cx, [bp+4] ; load length of string

Mov ah, [bp+8] ; load attribute byte

Printloop:

Mov al, [si] ; load character from string

Mov [es:di], ax ; store character and attribute

Add si, 1 ; move to next character

Add di, 2 ; move to next screen position

Loop printloop ; repeat for all characters

Pop di

Pop si

Pop cx

Pop ax

Pop es

Pop bp

Ret 10 ; clean up stack (5 parameters * 2 bytes each)

;;; END of printstr CODE ;;;

Start:

Call clrscr ; call the modified clrscr subroutine


; Position VUID at bottom right corner

; Screen is 80x25, so bottom-right would be around column 69, row 24

; to fit an 11-character VUID

Mov ax, 69 ; PUT X POSITION VALUE TO PRINT VUID ON BOTTOM


RIGHT CORNER

Push ax ; push x position

Mov ax, 24 ; PUT Y POSITION VALUE TO PRINT VUID ON BOTTOM


RIGHT CORNER

Push ax ; push y position

Mov ax, 0x1F ; LAST NON-ZERO DIGIT OF YOUR VUID AS THE


ATTRIBUTE (white on blue)

Push ax ; push attribute (bright white text on blue background)

Mov ax, message ; load address of message

Push ax ; push address of message

Push word [length] ; push message length

Call printstr ; call the printstr subroutine

Mov ax, 0x4c00 ; terminate program

Int 0x21

You might also like