INPUT OUTPUT INSTRUCTIONS Computer Engineering Department IN OUT

  • Slides: 16
Download presentation
INPUT OUTPUT INSTRUCTIONS Computer Engineering Department

INPUT OUTPUT INSTRUCTIONS Computer Engineering Department

IN / OUT Instructions § OUT : Instruction transfer information to an Output device.

IN / OUT Instructions § OUT : Instruction transfer information to an Output device. § IN : Instruction read information from an Input device. § Both (IN & OUT) instruction transfer data between I/O devices and microprocessor accumulator (AL, or AX). § The I/O address is stored in register DX as 16 -bit I/O address or in the byte (P 8) immediately following the op-code as an 8 bit I/O address. § Intel calls the 8 -bits from (p 8) a fixed address. § The 16 -bit I/O address in DX is called a variable address.

Input / Output (I/O) Ports § The 8 -bit fixed port number (P 8)

Input / Output (I/O) Ports § The 8 -bit fixed port number (P 8) appears on address bus connections A 0 -A 15 with bits A 8 -A 15 equal to (00 FFh – 0000 h). The 16 -bit variable port number (DX) appears on address connections A 0 -A 15 (0000 h – FFFF h). § Emulator dose not reproduce any original I/O Ports of IBM PC, instead it has virtual devises that can be accessed by IN / OUT instructions. Devices are variable from “Virtual Devices” menu of the Emulator.

IN/OUT– Port (110 & 112) § simple. exe is a virtual device that have

IN/OUT– Port (110 & 112) § simple. exe is a virtual device that have two ports. § Port 110 deals with 8 -bits & port 112 deals with 16 -bit #START=SIMPLE. EXE# IN AL, 110 MOV BL, AL IN AX, 112 MOV DX, AX OUT 110, AL MOV AX, 0110 h OUT 112, AX HLT Insert 01 H into 110 port, 2345 H into 112 port. § You can Run Simple. exe manually (Virtual Device Menu Simple. exe)

Printer – Port (130 D) § This virtual device use to print character on

Printer – Port (130 D) § This virtual device use to print character on the screen, it convert the value that inserted into ASCII value and print it, use 8 -bit only. #start=printer. exe# MOV AL, 'A' OUT 130 D, AL ; PRINT A ON TH SCREEN MOV AL, 'H' OUT 130 D, AL MOV AL, 4 DH OUT 130 D, AL MOV AL, 'E' OUT 130 D, AL MOV AL, 44 H OUT 130 D, AL HLT

Thermometer - Port (125 & 127) §

Thermometer - Port (125 & 127) §

Thermometer - Port (125 & 127) #START=THERMOMETER. EXE# START: IN AL, 125 ; TEMPERATURE

Thermometer - Port (125 & 127) #START=THERMOMETER. EXE# START: IN AL, 125 ; TEMPERATURE VALUE CMP AL, 25 ; COMPARE WITH LOW DEG. JL LOW CMP AL, 55 ; COMPARE WITH HIGH DEG. JLE OK JG HIGH ; ***** LOW: MOV AL, 1 OUT 127, AL JMP OK ; ***** HIGH: MOV AL, 0 OUT 127, AL ; ***** OK: JMP START

Traffic lights – Port 4 § The traffic lights are control by sending data

Traffic lights – Port 4 § The traffic lights are control by sending data to I/O port-4. § There are 12 lamps: 4 Green, 4 Yellow, 4 Red. § You can set the state of each lamp by setting its bit: 1 = The lamp is turned on 0 = The lamp is turned off Only 12 low bit of a word are used (0 -11), last bits (12 -15) are unused.

Traffic lights – Port 4 § For example: MOV AX, 0000 0010 1111 0100

Traffic lights – Port 4 § For example: MOV AX, 0000 0010 1111 0100 |b OUT 4, AX § First operand is a word into AX that is written to the port-4, It must be an immediate byte value (0… 255), or DX register. Second operand must be AX or AL only. § You can read data from port using (IN) instruction. IN AX, 4

Traffic lights – Port 4 § This program control the traffic of a four-direction

Traffic lights – Port 4 § This program control the traffic of a four-direction road junction in the order West (W), North (N), East (E), & South (S) by the use of the traffic lights virtual device port 4. South Hexa. Value 024 C |h 024 A |h 0261 |h 0251 |h 0309 |h 0289 |h 0849 |h 0449 |h East North West G Y R B A 9 8 7 6 5 4 3 2 1 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 1

Traffic lights – Port 4 #start=Traffic_Lights. exe# ; THE PROGRAM START: AGAIN: MOV AX,

Traffic lights – Port 4 #start=Traffic_Lights. exe# ; THE PROGRAM START: AGAIN: MOV AX, 024 CH OUT 4, AX MOV AX, 024 AH OUT 4, AX MOV AX, 0261 H OUT 4, AX MOV AX, 0251 H OUT 4, AX MOV AX, 0309 H OUT MOV OUT JMP 4, AX AX, 0289 H 4, AX AX, 0849 H 4, AX AX, 0449 H 4, AX AGAIN

Stepper Motor – Port 7 § An electrical motor that can be precisely controlled

Stepper Motor – Port 7 § An electrical motor that can be precisely controlled by singles from a computer (I/O port 7). § The motor turn through a precise angle. § By verifying the rate at which signal pulses are produced, the motor can be run at different speeds or turned through an exact angle and then stopped. § This is a basic 3 -phase stepper motor, it has 3 magnets controlled by bits (0, 1, 2) other bits (3 … 7) are unused. § When magnet is working becomes red. § The arrow in the left upper corner shows the direction of the last motor move. § The green line is to see that it is really rotating.

Stepper Motor – Port 7 #start=stepper_motor. exe# MOV CX, 2 again: MOV AL, 00000001

Stepper Motor – Port 7 #start=stepper_motor. exe# MOV CX, 2 again: MOV AL, 00000001 OUT 7, AL MOV AL, 00000011 OUT 7, AL MOV AL, 00000110 OUT 7, AL MOV AL, 00000101 1, 3, 6, 5 Left to Right OUT 7, AL 1, 5, 6, 3 Right To Left Loop again HLT § If required you can read the data from port using IN instruction, for example, IN 7, AL

Stepper Motor – Port 7 #start=stepper_motor. exe# MOV CX, 4 again: MOV AL, 00000001

Stepper Motor – Port 7 #start=stepper_motor. exe# MOV CX, 4 again: MOV AL, 00000001 OUT 7, AL MOV AL, 00000110 OUT 7, AL MOV AL, 00000011 OUT 7, AL Loop again HLT 1, 3, 6, 5 Left to Right 1, 5, 6, 3 Right To Left

Home Work Ø Write a program that control on the follow of traffic so

Home Work Ø Write a program that control on the follow of traffic so that East and North work together, East and South work together. Ø Write a program that control on the Thermometer using heater and thermometer (between 0° to 80°). ØWrite a program to print N-characters on the screen, these characters must be your full name. Ø Write a program that control on the Stepper Motor 1 Full Clockwise, and 1 Full C-clockwise in one program.