Pages

CS401P ASSIGNMENT NO. 2 SPRING 2023 || 100% RIGHT SOLUTION || ASSEMBLY LANGUAGE PROGRAMMING || BY VuTech

CS401P ASSIGNMENT NO. 2 SPRING 2023 || 100% RIGHT SOLUTION || ASSEMBLY LANGUAGE PROGRAMMING || BY VuTech

CS401P ASSIGNMENT NO. 2 SPRING 2023 || 100% RIGHT SOLUTION || ASSEMBLY LANGUAGE PROGRAMMING || BY VuTech

Visit Website For More Solutions
www.vutechofficial.blogspot.com

KINDLY, DON’T COPY PASTE

QUESTION NO. 1

Write an assembly language program which will first take VU ID as input and then set background and foreground color of each character differently.

- Before printing the screen must be cleared.

- First VU ID will be taken as input from user.

- Then print VU ID on the screen with different foreground and background color for each character.

- For example if VU ID is bc12345678 then the ID will be printed as follows:

bc12345678

Solution:

section .data

    vu_id_msg db 'Enter VU ID:', 0

    vu_id_prompt db 'VU ID: ', 0

    vu_id_buffer times 12 db 0 ; Buffer to store the VU ID

    vu_id_length equ 12 ; Length of the VU ID

    bg_colors db 0Ah, 01h, 02h, 03h, 04h, 05h, 06h, 07h, 08h, 09h ; Array of background color codes

    fg_colors db 01h, 02h, 03h, 04h, 05h, 06h, 07h, 08h, 09h, 0Ah ; Array of foreground color codes

section .text

    global _start

_start:

    ; Clear the screen

    mov ah, 0h ; Function 0h - Clear screen

    int 10h    ; Call BIOS video services

    ; Display "Enter VU ID:" message

    mov ah, 09h ; Function 09h - Print string

    mov dx, vu_id_msg

    int 21h     ; Call DOS interrupt

    ; Read VU ID from user

    mov ah, 0Ah ; Function 0Ah - Read string

    mov dx, vu_id_buffer

    mov cx, vu_id_length

    int 21h     ; Call DOS interrupt

    ; Display "VU ID: " prompt

    mov ah, 09h ; Function 09h - Print string

    mov dx, vu_id_prompt

    int 21h     ; Call DOS interrupt

    ; Set up registers for looping through the VU ID

    mov esi, vu_id_buffer ; Source index points to the VU ID buffer

    mov ecx, vu_id_length ; Counter for the number of characters in VU ID

    ; Loop through each character of VU ID and set colors

    vu_id_loop:

        lodsb        ; Load the next character from the VU ID buffer

        mov ah, 09h  ; Function 09h - Print character with attribute

        mov al, byte[esi-1]  ; Load the character itself

        mov bh, byte[bg_colors+ecx-1]  ; Background color

        mov bl, byte[fg_colors+ecx-1]  ; Foreground color

        int 10h      ; Call BIOS video services

        loop vu_id_loop ; Continue looping until all characters are processed

    ; Exit the program

    mov ah, 4Ch ; Function 4Ch - Program termination

    mov al, 00h ; Return code 0

    int 21h     ; Call DOS interrupt




KINDLY, DON’T COPY PASTE
SUBSCRIBE, SHARE, LIKE AND COMMENTS FOR MORE UPDATES
SEND WHATSAPP OR E-MAIL FOR ANY QUERY
0325-6644800
kamranhameedvu@gmail.com
Visit Website For More Solutions
www.vutechofficial.blogspot.com