Sie sind auf Seite 1von 16

BIOS AND DOS PRINTER INT SERVICES

BIOS PRINTER CONTROL INT TYPE 17 h

Function 00h output a character to the printer

Register Contents
AH 00h
AL Character to be output
DX Printer number 00 to 02h
Returned
AH Printer status

Printer numbers 00 to 02h  LPT1 to LPT3

Bit of AH Printer port status

76543210
----------1 No response from port ( time-out )
---------x unused
-------x unused
------1 /error signal low ( pin 15 )
----1 selected signal high ( pin 13 )
--1 paper out signal high ( pin 12 )
-1 /acknowledge signal low ( pin 10 )
1 Busy signal low ( pin 11 )

Function 02h Read printer post status

Register Contents
AH 02h
DX printer number 00 to 02h
Returned
AH Printer status

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 1


Dnk kumar
Function 01h Reset printer
Function 01h will send a reset sequence ( not recognized by all printers ) of
character 08h and 0Ch to the port and return the printer port status in AH

Printing a Message
Code segment
Mov SP, 1000h ; set the stack
LEA BX, Msg1 ; point to start of message
Next:
Mov AH, 00h ; print character
Mov AL, [BX] ; get character to AL
CMP AL, ‘~’ ; quit if at end of message
JE Donit ; exit to DOS at end
Mov DX, 0000h ; use LPT1
INT 17h ; just do it
INC BX ; point to next character
JMP next ; go until done
Donit:
Mov AX, 4C00h ; exit back to DOS
INT 21h ; return to DOS
Msg1 : DB ‘hello’, 0Dh,0Ah, ‘~’ ; message with CR, LF
Code ends

; Code that gets the status of the printer port


Code segment
Next:
Mov SP, 1000h ; set the stack
Mov AH,00h ; get status
Mov DX, 0000h ; printer LPT1
INT 17h ; BIOS printer post status
JMP next ; get status repeatedly
Code ends

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 2


Dnk kumar
DOS PRINTER SERVICES

DOS INTERRUPT 21h FUNCTION 05h WRITE BYTE TO PRINTER

Register Contents
AH 05h
DL byte to be written to printer port

STDPRN – LPT1
No printer status data is returned by this function. Function will wait until
an acknowledge is received from printer before returning resulting in ‘hang’
if printer is not working or switched off

INT 21h Function 40h Write to file

Register Contents
AH 40h
BX 04h ( permanent printer handle )
CX Number of bytes to print
DS:DX Pointer to bytes to be printed
Returned
CF Cleared if no errors
AX Number of bytes written, or errors

Code segment
Mov SP, 1000h ; set the stack
Mov DX, Start ; point to start of message
Mov CX, Length ; length of message
Mov BX, 0004h ; file handle for printer
Mov AH, 40h ; print message
INT 21h ; interrupt to DOS
Mov AX, 4C00h ; return to DOS
INT 21h
Start: DB ‘hello’,0Dh,0Ah
Finish: NOP
Length: equ finish – start
Code ends

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 3


Dnk kumar
Note : DS must be same as CS
DS would have to be set equal to CS before printing the message for .exe
type assembly

BIOS SERIAL DATA TRANSMISSION INT SERVICES

BIOS ASYCHRONOUS SERIAL DATA INT 14h

Function 00h Initialize the Serial Port

Register Contents Function

AH 00h select function 00h, initialize port


AL ( see table) select serial data modes
DX 0000h – 0003h select COM1 to COM4

Returned
AH Port status listed in table
AL Modem status listed in table

AL Register Bit Settings for Serial Transmission

Bit Baud rate Bit Parity Bit Stop bits Bit Character
765 43 2 10 Length

000 9,110 00 None 0 1 00 7 bits


001 9,150 01 Odd 1 2 10 8 bits
010 9,300 10 None
011 9,600 11 Even
100 1,120
101 2,400
110 4,800
111 9,600

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 4


Dnk kumar
Return Contents of AH Serial Port Data Status

Bit 76543210
xxxxxxx1 Received Data Present
xxxxxx1x Overflow Error
xxxxx1xx Parity Error
xxxx1xxx Framing Error
xxx1xxxx Break Detected
xx1xxxxx Transmitter Holding Register Empty
x1xxxxxx Transmitter Shift Register Empty
1xxxxxxx Time-out

Return Contents of AL Modem ( Serial Port Control ) Status

Bit 76543210
xxxxxxx1 Change in CTS status
xxxxxx1x Change in DSR status
xxxxx1xx Trailing edge of RI signal
xxxx1xxx Change in CD signal
xxx1xxxx CTS enabled
xx1xxxxx DSR enabled
x1xxxxxx RI enabled
1xxxxxxx CD enabled

Function 01h write a character to the serial port

Register Content Function

AH 01h Select write to serial port function


AL Character Character to be transmitted by serial port
DX 0000h – 0003h Select COM1 ( 000Dh ) to COM4 ( 0003h )

Returned
AH Port status shown earlier

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 5


Dnk kumar
DTE TO DTE SERIAL DATA TRANSMISSION

A DTE will not transmit until the DSR and CTS input hand shaking signals
from a DCE unit are enabled

DTE number one DTE number two

Pins Signals Pins Signals

2 RXD 3 TXD
3 TXD 2 RXD
4 DTR 6 DSR
5 GND 5 GND
6 DSR 4 DTR
7 RTS 8 CTS
8 CTS 7 RTS

WITHOUT HANDSHAKING SIGNALS

DTE number one DTE number two

Pin Signal Pin Signal

2 RXD  3 TXD
3 TXD  2 RXD
4 to 6 DTN TO DSR 4 to 6 DTN TO DSR
5 GND  5 GND
7 to 8 RTS TO CTS 7 to 8 RTS TO CTS

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 6


Dnk kumar
Function 02h Read a character from the Serial Port
Register Contents Function

AH 02h Select read from Serial Port function


DX 0000h – 0003h COM1 – to – COM4 port

Returned
AL Serial data character
AH Port status shown earlier

Serial Port must have been initialized using 00h

Function 03h Determine Serial Port Status

Register Contents Function


AH 03h select port status function
DX 0000h – 0003h COM1 – COM4 port

Returned
AX Port and Modem status shown earlier

A LOOP CHECK PROGRAM

25 PIN SERIAL PORT CONNECTOR


Connect Pin To Pin
20 DTR 6 DSR
4 RTS 5 CTS
2 TXD 3 RXD

9 PIN SERIAL PORT CONNECTOR


Connect Pin To Pin
4 DTR 6 DSR
7 RTS 8 CTS
3 TXD 2 RXD

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 7


Dnk kumar
Program checks serial port COM2 by sending and receiving a character using
a loop check serial connector

Code segment
Mov SP, 1000h ; set the stack
Mov AX, 00C3h ; initialize to 4800, no parity 8 bit
Mov DX, 0001h ; use COM2
INT 14h ; COM2 initialized
Lup:
Mov AH, 01h ; send an ’A’
Mov AL, ‘A’
INT 14h ; am A is transmitted
Mov AH, 03h ; get port status
INT 14h ; AH = 61h : data reading Xmit reg. Empty

Mov AH, 02h ; read the character


INT 14h ; get the A character
JMP Lup ; go again ?
Code ends

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 8


Dnk kumar
Communication character Receive Program

Code segment
Mov SP, 1000h ; set the stack
Mov AX, 00C3h ; initialize to 4800 no parity 8 bit
Mov DX, 0000h ; use COM1
INT 14h
Receive:
Mov AH, 03h ; get port status
; AH bit 0 = 1 if ready
INT 14h ; data waiting ?
RCR AH, 1 ; rotate AH bit 0 into the carry flag
JNC Receive ; poll until character is received ( CF = 1 )
Mov AH, 02h ;
INT 14h ; get the character

; rest of the program

Code ends

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 9


Dnk kumar
ASSEMBLER DIRECTIVES

ORG - originate
Used to place code or data at exact offset addresses from the start of the
segment

Example: Org 400h


Will place whatever comes next ( data or code ) exactly at offset address
400h from the start of the segment

An org directive is normally used to place the data area of memory well
above any program code memory that is in the code part of the same
segment. The assembler assembles the code segment first in lower segment
memory and provides space for the data memory at the org address
declared in the data segment,

Segment Directive

Data segment
Org 1000h
; variable names defined
data ends
code Segment
; constants equated to names
; program instructions
; constant data defined
code ends

Data Size Number Size Directives

Name Bits Bytes Words Directive

Byte 8 1 ------ B
Word 16 2 1 W
Dword 32 4 2 D
Qword 64 8 4 Q
Tbyte 80 10 5 T

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 10


Dnk kumar
Example: dec [400h]  decrement the byte at location 400h or word at
400, 401h

Dec b[400h] or dec [400h]b


Dec w[400h] or dec [400h]w

Define Data Directive


DB Bytes of data
DW words
DD double words
DQ quad words
DT ten bytes

Var name DB ? ( = leave space for a byte of data )

Coname DB 5Ah

Math Directive +,-,*,/

Org table + 0FFh ; Org the assemble at address table + 0FFh


Mov BX, 12 + 13 ; BX = 25 xd
Mov BX, 12 * 13 ; BX = 156 xd
Mov BX, 21/5 ; BX = 4 xd

Dup - Duplicate Directive

DX nn dup yy

nn  no of x things to duplicate
yy  the value of each x quantity

Example: DB 100h dup 33h


100h bytes of data each byte containing a 33h value

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 11


Dnk kumar
Equ - Directive

Equate a numeric ASCII or label to another

TEN EQU 10
NINE EQU 9

Align - Directive

- makes sure that the memory arrays are stored on word boundaries
- Align 2 places data on word boundaries
- Align 4 places data on double word boundaries

Example:
Lista DB 10 dup (?) ; reserve 10 bytes
Align 2 ; set word boundaries

This - Directive

This Byte
This word
This dword

In certain cases, data must be referred to as both a byte and a word. The
assembler can only assign either a byte or a word address to a label

DATA-SEG SEGMENT
ORG 100h
DATA1 EQU THIS BYTE
DATA2 DW ?
DATA-SEG ENDS
CODE-SEG SEGMENT ‘CODE’
ASSUME CS:CODE-SEG, DS:DATA-SEG
MOV BL, DATA1
MOV AX, DATA2
MOV BH, DATA1 + 1
CODE-SEG ENDS

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 12


Dnk kumar
Assume statement tells the assembler what names have been chosen for the
code, data ,extra and stack segment.

PROC & ENDP directives


- both directives require label
- Proc be followed by either NEAR or FAR
- NEAR in the same code segment as program
- FAR may reside any where in the memory
- NEAR – local
- FAR – global

ADDEM PROC FAR


ADD BX, CX
ADD BX, DX
MOV AX, BX
RET
ADDEM ENDP

Uses Directive
This directive indicates what registers are u sed by the procedure so the
assembler can automatically save them before the procedure begins and
restore before the procedure ends with the RET instructions.

ADDS PROC NEAR USES BX CX DX


ADD BX, AX
ADD CX, BX
ADD DX, CX
MOV AX, DX
RET
ADDS ENDP

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 13


Dnk kumar
MEMORY ORGANIZATION:
- The assembler uses two basic formats for developing software
- One method uses models and the other uses full segment definitions
- Memory Models for MASM as presented here differs from TASM models
- The models are easier to use, but the full segment definitions offer
better control
- Full Segment apply to all assemblers models

TINY - All data and code fit into one segment the code segment, the
Program originates at memory location 0100h

SMALL – All data fit into a single 64K byte data segment and all code fits
into another 64K segment code segment
All code cana be accessed with near jumps and calls

MEDIUM – Data - Single 64k


Code – More than one code segment

COMPACT – Code – Single 64k


Data – more than one segment

LARGE - both code and data - multiple

HUGE - Same as large but size > 64 k byte

FLAT - One segment with a maximum of 512M bytes to store data and
code ( not available for MASM v 5.10 )

Example:

.MODEL SMALL
.STACK 100h
.DATA

LISTA DB 100 Dup (?)


LISTB DB 100 Dup (?)

.CODE

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 14


Dnk kumar
HERE: MOV AX, @DATA ; LOAD ES, DS
MOV EX, AX
MOV DS, AX

CLD ; MOVE DATA


MOV SI, OFFSET LISTA
MOV DI, OFFSET LISTB
MOV CX, 100
REP MOVSB

.EXIT ; EXIT TO DOS


END HERE

Example:

STACK-SEG SEGMENT ‘STACK’


DW 100h Dup (?)
STACK-SEG ENDS

DATA-SEG SEGMENT ‘DATA’


LISTA DB 100 Dup (?)
LISTB DB 100 Dup (?)
DATA-SEG ENDS

CODE-SEG SEGMENT ‘CODE’


ASSUME CS:CODE-SEG, DS:DATA-SEG, SS:STACK-SEG
MAIN PROC FAR

MOV AX, DATA-SEG ;LOAD DS AND ES


MOV ES, AX
MOV DS, AX

CLD ; MOVE DATA


MOV SI, OFFSET LISTA
MOV DI, OFFSET LISTB
MOV CX, 100

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 15


Dnk kumar
REP MOVSB

MOV AH, 4Ch ; EXIT TO DOS


INT 21h

MAIN ENDP

CODE-SEG ENDS

END MAIN

INTERRUPTS – cont’d and ASSEMBLER DIRECTIVES 16


Dnk kumar

Das könnte Ihnen auch gefallen