;********************************************************************************************** ;* * ;* LAB6-2.ASM - Assembler Laboratory ZMiTAC * ;* * ;* Sample program that converts lowercase to uppercase when key pressed * ;* * ;********************************************************************************************** .8086 .MODEL SMALL .STACK 100h .CODE ;********************************************************************************************** ;* Variables * ;********************************************************************************************** old_proc dd 0 ; address of original interrupt handler dot_flag db 0 ; dot flag ;********************************************************************************************** ;* 09h interrupt handler * ;********************************************************************************************** segment_kb EQU 40h ; beggining of keyboard data segment wsk_kb EQU 1Ch ; offset of pointer to keyboard buffer kb_buf_begin EQU 80h ; offset of address of begining of the buffer kb_buf_end EQU 82h ; offset of address of end of the buffer keys PROC FAR ;---------------------------------------------------------------------------------------------- ; Calling of original interrupt handler ;---------------------------------------------------------------------------------------------- int 60h ;---------------------------------------------------------------------------------------------- ; Prepare registers ;---------------------------------------------------------------------------------------------- push ax ; push registers on the stack push bx push dx push ds mov ax,segment_kb ; address of keyboard data segment to DS mov ds,ax ;---------------------------------------------------------------------------------------------- ; Read the character and check ASCII code ;---------------------------------------------------------------------------------------------- mov bx,ds:[wsk_kb] ; actual pointer to BX mov ax,ds:[kb_buf_begin] ; buffer beggining to AX cmp bx,ax ; is the beggining of the buffer ? jne mid_buf mov bx,ds:[kb_buf_end] ; last character is at the end of the buffer mid_buf: mov ax,ds:[bx-2] ; read last character cmp al,'.' ; compare with dot je dot_found ; if dot cmp al,'Z' ; compare with 'Z' ja check_lowercase ; if above check lowercase cmp al,'A' ; compare with 'A' jb keys_end ; end if less mov dot_flag,0 ; uppercase - clear flag jmp keys_end ; return check_lowercase: cmp al,'z' ; compare with 'z' ja keys_end ; end if above cmp al,'a' ; compare with 'a' jb keys_end ; end if less cmp dot_flag,0 ; was dot pressed? je keys_end ; end if not ;---------------------------------------------------------------------------------------------- ; Change lowercase to uppercase ;---------------------------------------------------------------------------------------------- sub al,'a'-'A' ; sub difference between cases mov ds:[bx-2],ax mov dot_flag,0 ; uppercase - clear flag jmp keys_end ; return dot_found: mov dot_flag,1 ; set flag jmp keys_end ; return ;---------------------------------------------------------------------------------------------- ; Pop registers and return from interrupt ;---------------------------------------------------------------------------------------------- keys_end: pop ds pop dx pop bx pop ax iret keys ENDP ;********************************************************************************************** ;* Main program * ;********************************************************************************************** ;---------------------------------------------------------------------------------------------- ; Get interrupt ;---------------------------------------------------------------------------------------------- start: mov ah,35h ; function 35h - read handler address mov al,09h ; of interrupt 09h int 21h mov word ptr old_proc,bx ; store 32-bit address mov word ptr old_proc+2,es ; of original interrupt handler push cs pop ds ; handler code segment to DS mov dx,offset keys ; offset of handler address to DX mov ah,25h ; function 25h - set new handler mov al,09h ; of interrupt 09h int 21h mov dx,word ptr old_proc+2 mov ds,dx mov dx,word ptr old_proc mov ah,25h ; function 25h - set new adress mov al,60h ; of original interrupt handler int 21h ; 60h instead of 09h ;---------------------------------------------------------------------------------------------- ; Main loop ;---------------------------------------------------------------------------------------------- looping:mov ah,08h ; function 08h - read character int 21h ; ASCII code is returned in AL cmp al,1Bh ; ESC je ending ; if ESC end of the loop mov dl,al ; not ESC - move char to DL mov ah,02h ; function 02h - display character int 21h ; ASCII code of char in DL jmp looping ;------------------------------------------------------------------------- ; Odtworzenie adresu pierwotnej procedury obslugi przerwania ;------------------------------------------------------------------------- ending: mov dx,word ptr old_proc+2 mov ds,dx mov dx,word ptr old_proc mov ah,25h ; function 25h - set old handler mov al,09h ; of interrupt 09h int 21h mov ah,4Ch ; end of the program int 21h END start