cpu 8086 org 0x3000 ;Store a keycode ;Read a keypress mov ah, 0x0 int 0x16 ;Store the keycode mov [scan], ah mov [ascii], al ;Print the prefix mov si, prefix mov ah, 0x0 int 0x21 ;Convert the keycode to a hex string ;Convert the scancode mov al, [scan] mov di, keycode call byte2hex ;Convert the ascii value mov al, [ascii] mov di, keycode add di, 0x2 call byte2hex ;Print the keycode mov si, keycode mov ah, 0x2 int 0x21 ;Return int 0x20 ;Data prefix db "0x", 0x0 scan db 0x0 ascii db 0x0 keycode times 0x5 db 0x0 ;*** ;Convert the value of a byte to a hex string byte2hex: ;Store AX, BX, CX, and SI in the stack push ax push bx push cx push si ;Setup ;Move the byte to AH mov ah, al ;Set SI to the hex digit key mov si, key ;Set a counter for the two hex digits mov cx, 0x2 ;Convert the byte ;Read a nibble loop: times 0x4 rol ax, 0x1 mov bx, ax ;Convert the nibble to a hex digit and bx, 0xf mov bl, [si + bx] ;Store the hex digit mov [di], bl ;Convert the next nibble inc di dec cx jnz loop ;Load SI, CX, BX, and AX from the stack pop si pop cx pop bx pop ax ;Return ret ;Data key db "0123456789abcdef"