Академический Документы
Профессиональный Документы
Культура Документы
Register Contents
AH 00h
AL Character to be output
DX Printer number 00 to 02h
Returned
AH Printer 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 )
Register Contents
AH 02h
DX printer number 00 to 02h
Returned
AH Printer status
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
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
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
Returned
AH Port status listed in table
AL Modem status listed in table
Bit Baud rate Bit Parity Bit Stop bits Bit Character
765 43 2 10 Length
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
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
Returned
AH Port status shown earlier
A DTE will not transmit until the DSR and CTS input hand shaking signals
from a DCE unit are enabled
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
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
Returned
AL Serial data character
AH Port status shown earlier
Returned
AX Port and Modem status shown earlier
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
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
Code ends
ORG - originate
Used to place code or data at exact offset addresses 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
Byte 8 1 ------ B
Word 16 2 1 W
Dword 32 4 2 D
Qword 64 8 4 Q
Tbyte 80 10 5 T
Coname DB 5Ah
DX nn dup yy
nn no of x things to duplicate
yy the value of each x quantity
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
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.
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
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
.CODE
Example:
MAIN ENDP
CODE-SEG ENDS
END MAIN