input and output using 8086 assembly language

9
Input and Output Input and Output Using 8086 Assembly Using 8086 Assembly Language Language Assembly Language Programming Assembly Language Programming

Upload: winifred-sarsfield

Post on 31-Dec-2015

45 views

Category:

Documents


0 download

DESCRIPTION

Input and Output Using 8086 Assembly Language. Assembly Language Programming. Interrupts. The interrupt instruction is used to cause a software interrupt An interrupt interrupts the current program and executes a subroutine, eventually returning control to the original program - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Input and Output Using 8086 Assembly Language

Input and Output Using Input and Output Using 8086 Assembly Language8086 Assembly Language

Assembly Language ProgrammingAssembly Language Programming

Page 2: Input and Output Using 8086 Assembly Language

InterruptsInterrupts

The interrupt instruction is used to cause a The interrupt instruction is used to cause a software interruptsoftware interrupt– An interrupt interrupts the current program An interrupt interrupts the current program

and executes a subroutine, eventually and executes a subroutine, eventually returning control to the original programreturning control to the original program

– Interrupts may be caused by hardware or Interrupts may be caused by hardware or softwaresoftware

int int interrupt_numberinterrupt_number ;software interrupt ;software interrupt

Page 3: Input and Output Using 8086 Assembly Language

Output to MonitorOutput to Monitor

DOS Interrupts : interrupt 21hDOS Interrupts : interrupt 21h– This interrupt invokes one of many support This interrupt invokes one of many support

routines provided by DOSroutines provided by DOS– The DOS function is selected via AHThe DOS function is selected via AH– Other registers may serve as argumentsOther registers may serve as arguments

AH = 2, DL = ASCII of character to outputAH = 2, DL = ASCII of character to output– Character is displayed at the current cursor Character is displayed at the current cursor

position, the cursor is advanced, AL = DLposition, the cursor is advanced, AL = DL

Page 4: Input and Output Using 8086 Assembly Language

Output a StringOutput a String

Interrupt 21h, function 09hInterrupt 21h, function 09h– DX = offset to the string (in data segment)DX = offset to the string (in data segment)– The string is terminated with the '$' characterThe string is terminated with the '$' character

To place the address of a variable in DX, To place the address of a variable in DX, use one of the followinguse one of the following– lea lea DX,theString ;load effective addressDX,theString ;load effective address– movmov DX, offset theString ;immediate dataDX, offset theString ;immediate data

Page 5: Input and Output Using 8086 Assembly Language

Input a CharacterInput a Character

Interrupt 21h, function 01hInterrupt 21h, function 01h

Filtered input with echoFiltered input with echo– This function returns the next character in the This function returns the next character in the

keyboard buffer (waiting if necessary)keyboard buffer (waiting if necessary)– The character is echoed to the screen The character is echoed to the screen – AL will contain the ASCII code of the non-AL will contain the ASCII code of the non-

control charactercontrol characterAL=0 if a control character was enteredAL=0 if a control character was entered

Page 6: Input and Output Using 8086 Assembly Language

Additional Input FunctionsAdditional Input Functions

06h : Direct input, no waiting06h : Direct input, no waiting

07h : Direct input, no Ctrl-Break07h : Direct input, no Ctrl-Break

08h - Direct input with Ctrl-Break08h - Direct input with Ctrl-Break

0Ah - Buffered input0Ah - Buffered input

0Bh - Get input status0Bh - Get input status

0Ch - Clear input buffer, invoke input function0Ch - Clear input buffer, invoke input function

3Fh - Read from file or device3Fh - Read from file or device

Page 7: Input and Output Using 8086 Assembly Language

Direct Input FunctionsDirect Input Functions

No filteringNo filtering

No on-screen echoNo on-screen echo

Function 6Function 6– requires DL = 0FFhrequires DL = 0FFh– Does not wait for a Does not wait for a

character to be inputcharacter to be input– ZF set if no character ZF set if no character

is waitingis waiting

Function 7Function 7– Ctrl-Break while Ctrl-Break while

waiting for input will waiting for input will not terminate programnot terminate program

Function 8Function 8– Ctrl-Break will cancel Ctrl-Break will cancel

the input request and the input request and terminate the programterminate the program

Page 8: Input and Output Using 8086 Assembly Language

Buffered InputBuffered Input

A buffer of up to 255 characters is usedA buffer of up to 255 characters is used

Backspace can be used to delete Backspace can be used to delete characterscharacters

Other control keys are filteredOther control keys are filtered

Characters are echoedCharacters are echoed

Enter key terminates the input phaseEnter key terminates the input phase– DX must contain the offset to a buffer areaDX must contain the offset to a buffer area

buffer db m, ?, m dup (?)buffer db m, ?, m dup (?)

Page 9: Input and Output Using 8086 Assembly Language

Get Input StatusGet Input Status

AL is set to 0FFh if a character is waiting AL is set to 0FFh if a character is waiting in the keyboard buffer, AL = 0 otherwisein the keyboard buffer, AL = 0 otherwise

The keyboard buffer is a 15-character The keyboard buffer is a 15-character queue holding keystrokes not yet queue holding keystrokes not yet processed by an applicationprocessed by an application– DOS manages this via hardware interruptsDOS manages this via hardware interrupts– A "beep" indicates the buffer is fullA "beep" indicates the buffer is full

additional keystrokes are ignored when fulladditional keystrokes are ignored when full