Advertisement
DanikKUL

transfer a byte to com port (14h)

Feb 19th, 2023
2,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .stack 100h
  3.  
  4. .data
  5.  
  6. writeerr db "Error: can't send byte",0Dh,0Ah,'$'
  7. readerr db "Error: can't read byte",0Dh,0Ah,'$'
  8.            
  9. .code
  10.  
  11. jmp start
  12.  
  13. initialize proc
  14.    xor ax,ax
  15.    mov al,10100011b ; 8 bits in symbol ; 1 stop bit ; no parity ; 2400 bod
  16.    mov dx,0 ; COM1 address 0000h
  17.    int 14h
  18.    ret            
  19. initialize endp
  20.  
  21. sendByte proc
  22.    mov al,'D' ; byte to send
  23.    mov ah,1 ; write function 01h of 14h
  24.    mov dx,0 ; COM1 address 0000h
  25.    int 14h
  26.    test al,80h ; catch error
  27.    jnz writeError
  28.    ret
  29. sendByte endp
  30.  
  31. writeError proc
  32.    mov ah,9
  33.    mov dx,offset writeerr
  34.    add dx,2
  35.    int 21h
  36.    ret
  37. writeError endp
  38.  
  39. readByte proc
  40.     mov ah,2 ; read function 02h of 14h
  41.     mov dx,1 ; COM2 address 0001h
  42.     int 14h
  43.     test al,80h ; catch error
  44.     jnz readError
  45.     ret
  46. readByte endp
  47.  
  48. readError proc
  49.    mov ah,9
  50.    mov dx,offset readerr
  51.    add dx,2
  52.    int 21h
  53.    ret
  54. readError endp
  55.  
  56. print proc
  57.    mov ah,02h
  58.    mov dl,al ; moving read byte from al to dl
  59.    int 21h
  60.    ret
  61. print endp
  62.  
  63. exit proc
  64.     mov ax,4C00h
  65.     int 21h
  66.     ret
  67. exit endp
  68.  
  69. start:
  70.  
  71.    call initialize ; Initializing COM Port for writing
  72.    call sendByte ; Send byte
  73.    call readByte ; Read byte
  74.    call print ; Write a byte to stdout
  75.    call exit
  76.  
  77. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement