Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

BC200413993

Muhammad Liaqat
CS401:Computer Architecture and Assembly Language Programming
Assignment No. 02

Question No 01

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 3 rd row of screen,
OR
If Left shift is pressed, it prints your VUID in the descending order on the 3 rd row of screen,

ASSEMBLY CODE
code:

[org 0x0100]

jmp start

section .data

name db 'Bisma mushtaq', 0

vuid db 'VUID: 210409123', 0

vuid_asc db 'VUID sorted: 0210409123', 0

vuid_desc db 'VUID sorted:3210904120', 0

current_values db vuid - vuid ; initially display vuid

start:

mov ah, 0x0e

mov al, 0

int 0x10

mov si, name

call print_string_color

; print VUID on the 2nd row of the screen

mov ah, 0x0e ; BIOS teletype function


mov al, 0x0d ; carriage return

int 0x10

mov al, 0x0a ; line feed

int 0x10

mov si, current_values

call print_string_color

; keyboard interrupt service routine

mov ax, 0

mov es, ax ; point es to IVT base

cli ; disable interrupts

mov word [es:9*4], kbisr ; store offset at n*4

mov [es:9*4+2], cs ; store segment at n*4+2

sti ; enable interrupts

; wait for Esc key to be pressed

l1:

mov ah, 0 ; service 0 – get keystroke

int 0x16 ; call BIOS keyboard service

cmp al, 27 ; is the Esc key pressed

jne l1 ; if no, check for next key

mov ax, 0x4c00 ; terminate program

int 0x21

kbisr:

push ax

push es

mov ax, 0xb800

mov es, ax ; point es to video memory

in al, 0x60 ; read a char from keyboard port

cmp al, 0x2a ; is the key left shift

jne .nextcmp ; no, try next comparison

mov al, 0x0a ; line feed

mov si, name

call print_string_color
; print 'VUID' on the 2nd row of the screen

mov ah, 0x0e ; BIOS teletype function

mov al, 0x0d ; carriage return

int 0x10

mov al, 0x0a ; line feed

int 0x10

mov si, vuid

call print_string_color

; print 'VUID ASC' on the 3rd row of the screen

mov ah, 0x0e ; BIOS teletype function

mov al, 0x0d ; carriage return

int 0x10

mov al, 0x0a ; line feed

int 0x10

mov si, vuid_asc

call print_string_color

jmp .nomatch ; leave interrupt routine

.nextcmp:

cmp al, 0x36 ; is the key right shift

jne .nomatch ; no, leave interrupt routine

mov si, name

call print_string_color

mov ah, 0x0e ; BIOS teletype function

mov al, 0x0d ; carriage return

int 0x10

mov al, 0x0a ; line feed

int 0x10

mov si, vuid

call print_string_color
mov ah, 0x0e ; BIOS teletype function

mov al, 0x0d ; carriage return

int 0x10

mov al, 0x0a ; line feed

int 0x10

mov si, vuid_desc

call print_string_color

.nomatch:

mov al, 0x20

out 0x20, al ; send EOI to PIC

pop es

pop ax

iret

.done:

ret

.show_desc_values:

mov si, vuid_desc ; switch to desc values

jmp .done

.show_asc_values:

mov si, vuid_asc ; switch to asc values

jmp .done

print_string_color:

lodsb ; load a byte from si into al

cmp al, 0 ; check for null terminator

je .done

mov ah, 0x0e ; BIOS teletype function

mov bh, 0 ; display page

int 0x10 ; call BIOS video service

jmp print_string_color
.done:

Ret

You might also like