Advertisement
madopew

4_3

Mar 28th, 2020
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     org 100h
  2.  
  3.     ESC_ equ 01bh ;ascii code of escape
  4.     BELL_ equ 7 ;ascii code of ring
  5.     Q_SS_ equ 10h ;scancode of q
  6.     W_SS_ equ 11h ;scancode of w
  7.     E_SS_ equ 12h ;scancode of e
  8.     R_SS_ equ 13h ;scancode of r
  9.  
  10. start_:
  11.     mov ah, 09h ;output - helloStr
  12.     mov dx, helloStr_
  13.     int 21h
  14. main_:
  15.     mov ah, 00h ;no echo input with waiting - output ah-scancode, al-ascii code
  16.     int 16h
  17.     cmp al, ESC_ ;was it escape?
  18.     jne other_ ;if no go to other_
  19.     jmp exit_ ;if yes exit
  20. other_:
  21.     cmp ah, Q_SS_ ;if scancode is less than Q it's incorrect, jump to err_
  22.     jb err_ ;jump if below
  23.     cmp ah, R_SS_ ;if scancode is greater than R it's incorrect, jump to err_
  24.     ja err_ ;jump if above
  25.     push ds ;save data segment
  26.     mov bx, 40h ;mov 40h to bx
  27.     mov ds, bx ;mov 40h to ds (you cannot use immediate value here)
  28.     mov bx, 17h ;mov 17h to bx
  29.     mov al, byte [bx] ;keyboard flags are at the address 40h:17h
  30.     and al, 02h ;second bit is shift flag
  31.     pop ds ;retrieve data segment
  32.     cmp al, 02h ;is shift pressed?
  33.     jne err_ ;if no jump to err_
  34.     mov bx, shiftStr_ ;if yes mov address of first symbol of "SHIFT+0" to bx
  35.     add bx, 6 ;offset to "0" in "SHIFT+0"
  36.     cmp ah, Q_SS_ ;was the letter Q?
  37.     je shift_q_ ;if yes jump to shift_q_
  38.     cmp ah, W_SS_ ;etc.....
  39.     je shift_w_
  40.     cmp ah, E_SS_
  41.     je shift_e_
  42.     cmp ah, R_SS_
  43.     je shift_r_
  44. err_:
  45.     mov ah, 02h ;play ring
  46.     mov dl, BELL_
  47.     int 21h
  48.     jmp main_ ;go back to start
  49. displ_comb_:
  50.     mov ah, 09h ;set text property of next...
  51.     mov cx, 7 ;...7 characters (next 7 characters will have color set in bl)
  52.     int 10h
  53.     mov dx, shiftStr_ ;output that string
  54.     int 21h
  55.     jmp main_
  56. shift_q_:
  57.     mov byte [bx], 'Q' ;in bx address of "0", change it to correct letter
  58.     xor bh, bh ;clear bh
  59.     mov bl, 1fh ;set color
  60.     jmp displ_comb_ ;jump to displ_comb_
  61. shift_w_:
  62.     mov byte [bx], 'W'
  63.     xor bh, bh
  64.     mov bl, 20h
  65.     jmp displ_comb_
  66. shift_e_:
  67.     mov byte [bx], 'E'
  68.     xor bh, bh
  69.     mov bl, 0f4h
  70.     jmp displ_comb_
  71. shift_r_:
  72.     mov byte [bx], 'R'
  73.     xor bh, bh
  74.     mov bl, 06h
  75.     jmp displ_comb_
  76. exit_:
  77.     mov ah, 09h ;output - byeStr
  78.     mov dx, byeStr
  79.     int 21h
  80.     mov ah, 07h ;wait for input
  81.     int 21h
  82.     ret
  83. helloStr_ db "This program changes text properties", $0d, $0a, "You can exit on ESC", $0d, $0a, "Try to input SHIFT + Q, W, E, R:", $0d, $0a, "$"
  84. byeStr db 0dh, 0ah, "The program has now terminated. Press anything to continue...$"
  85. shiftStr_ db "SHIFT+0 $"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement