Header Ads

Write an assembly language program that performs following operations: • Prints your name on the 1st row screen • Prints your VUID on the 2nd row of screen • If Right shift is pressed, it prints your VUID in the ascending order on the 3rd row of screen, OR If Left shift is pressed, it prints your VUID in the descending order on the 3rd row of screen,

Write an assembly language program that performs following operations:

Prints your name on the 1st row screen

Prints your VUID on the 2nd row of screen

If Right shift is pressed, it prints your VUID in the ascending order on the 3rd row of screen, 

OR

If Left shift is pressed, it prints your VUID in the descending order on the 3rd row of screen, 

Solution:

; Data segment

section .data

    name db 'Your Name', 0

    vuid db 'Your VUID', 0

    shift_msg db 'Shift:', 0

    asc_msg db 'VUID SORTED : ', 0

    desc_msg db 'VUID SORTED : ', 0


; Text segment

section .text

    global _start

    _start:

        ; Print name on the 1st row

        mov edx, 1

        mov ecx, name

        mov ebx, 1

        mov eax, 4

        int 0x80


        ; Print VUID on the 2nd row

        mov edx, 1

        mov ecx, vuid

        mov ebx, 1

        mov eax, 4

        int 0x80


        ; Check if Right shift is pressed

        mov eax, 0x80

        mov ebx, 0

        int 0x16

        cmp ah, 0x2a  ; Right shift key code

        jne check_left_shift


        ; Print ascending order on the 3rd row

        mov edx, 1

        mov ecx, asc_msg

        mov ebx, 1

        mov eax, 4

        int 0x80


        ; Right shift is pressed, print VUID in ascending order

        mov edi, 1   ; Start at 1

        mov esi, 9   ; End at 9


        ascending_loop:

            mov eax, edi

            add eax, '0'

            mov [esp], eax  ; Store digit in the stack

            mov edx, 1

            mov ecx, esp

            mov ebx, 1

            mov eax, 4

            int 0x80


            inc edi

            cmp edi, esi

            jle ascending_loop


        jmp end_program


    check_left_shift:

        ; Check if Left shift is pressed

        mov eax, 0x80

        mov ebx, 0

        int 0x16

        cmp ah, 0x36  ; Left shift key code

        jne end_program


        ; Print descending order on the 3rd row

        mov edx, 1

        mov ecx, desc_msg

        mov ebx, 1

        mov eax, 4

        int 0x80


        ; Left shift is pressed, print VUID in descending order

        mov edi, 9   ; Start at 9

        mov esi, 1   ; End at 1


        descending_loop:

            mov eax, edi

            add eax, '0'

            mov [esp], eax  ; Store digit in the stack

            mov edx, 1

            mov ecx, esp

            mov ebx, 1

            mov eax, 4

            int 0x80


            dec edi

            cmp edi, esi

            jge descending_loop


    end_program:

        ; Exit the program

        mov eax, 1

        xor ebx, ebx

        int 0x80


No comments

Powered by Blogger.