[org 0x0100] jmp start oldisr: dd 0 ; space for saving old isr origArray: dw 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 ; Original Array itr: dw 0 ; iteration number row: dw 0 ; next row location kbisr: push ax push bx push cx push es push si push di mov bx, [cs:row] mov ax, 0xb800 mov es, ax ; point es to video memory in al, 0x60 ; read character from keyboard port cmp al, 0x1F ; check if s is pressed je sort ; if yes then jump to sort nomatch: ; If s is not pressed pop di pop si pop es pop cx pop bx pop ax jmp far [cs:oldisr] ; call the original ISR exit: mov al, 0x20 out 0x20, al ; send EOI to PIC add bx, 160 mov [cs:row], bx pop di pop si pop es pop cx pop bx pop ax iret ; return from interrupt sort: mov si, origArray mov ax, [cs:itr] add si,ax ; si will now point to the next number to be sorted add ax, 2 ; cmp ax, 20 ; Check if 10 itration are completed or not jne swap ; If not, swap jmp exit swap: mov [cs:itr], ax ; store the next itration number mov ax,[cs:si] ; store first digit in ax mov cx, [cs:si+2] ; store second digit to cx cmp ax,cx ; compare both digits jna print1 ; If already sorted, just print mov [cs:si], cx ; else swap mov [cs:si+2], ax print1: mov si, origArray mov di,0 checkDigit: mov ax,[cs:si] add al, 0x30 mov ah, 0x07 cmp al,0x3A ; check if the digit is 10 jz print2 ; call to print 2-digit number printDigit: mov word[es:bx+di],ax ; print digit in ax add di,2 mov al,0x20 mov word[es:bx+di],ax ; print Space add si,2 add di,2 cmp di,40 ; check if loop was executed 10 times jna checkDigit jmp exit print2: mov word[es:bx+di],0x0731 ; print 1 add di,2 ; move to next location mov word[es:bx+di],0x0730 ; print 0 add di,2 mov al,0x20 mov word[es:bx+di],ax ; print Space add si,2 add di,2 cmp di,40 ; check if loop is executed 10 times jna checkDigit jmp exit printOrigArray: push ax push bx push cx push es push si push di mov bx, [cs:row] mov ax, 0xb800 mov es, ax ; point es to video memory mov si, origArray mov di,0 checkDigit1: mov ax,[cs:si] add al, 0x30 mov ah, 0x07 cmp al,0x3A jz print3 printDigit2: mov word[es:bx+di],ax ; print digit in ax add di,2 mov al,0x20 mov word[es:bx+di],ax ; print Space add si,2 add di,2 cmp di,40 jna checkDigit1 jmp exit1 print3: mov word[es:bx+di],0x0731 ; print 1 add di,2 ; move to next location mov word[es:bx+di],0x0730 ; print 0 add di,2 mov al,0x20 mov word[es:bx+di],ax ; print Space add si,2 add di,2 cmp di,40 jna checkDigit1 exit1: add bx, 160 mov [cs:row], bx pop di pop si pop es pop cx pop bx pop ax jmp temp start: mov ah , 0x00 mov al , 0x02 int 0x10 ; BIOS video interrupt xor ax, ax mov es, ax ; point es to IVT base mov ax, [es:9*4] mov [oldisr], ax ; save offset of old routine mov ax, [es:9*4+2] mov [oldisr+2], ax ; save segment of old routine 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 mov dx, start ; end of resident portion add dx, 15 ; round up to next para mov cl, 4 shr dx, cl ; number of paras jmp printOrigArray temp: mov ax, 0x3100 ; terminate and stay resident int 0x21