overview intro to project 2 - serial i/o – rs232, usb assembly language programming using the lc-3...

18
Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

Post on 21-Dec-2015

226 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

Overview

• Intro to Project 2 - Serial I/O – RS232, USB

• Assembly Language Programming

• Using the LC-3 Simulator

Page 2: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

Serial Connection

Page 3: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

RS232

Signals:

Null Modem Connections using control signals (handshaking):

Connects:

DTE (Data Terminal Equipment or Computer) to

DCE (Data Communications Equipment).

Page 4: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

RS232

Signals:

Carrier Detect (CD) Incoming signal from a modem

Data Set Ready (DSR) Incoming handshaking signal controlled by DCE

Received Data (RD) Incoming Data (from a DCE to a DTE)

Request To Send (RTS) Outgoing flow control signal controlled by DTE

Transmitted Data (TD) Outgoing Data (from a DTE to a DCE)

Clear To Send (CTS) Incoming flow control signal controlled by DCE

Data Terminal Ready (DTR) Outgoing handshaking signal controlled by DTE

Ring Indicator (RI) Incoming signal from a modem

Signal Ground Common reference voltage

Page 5: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

RS232

“Faked” Loop back Connections:

Full handshaking (again):

Page 6: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

RS232

Minimum Connection – No handshaking:

Page 7: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

RS232

RS232 Cable and Lab Hookup:

Page 8: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

RS232

Serial Bit Transmission:

Baud rate: Max speed of transmission of bits:

Typically 110, 300, 1200, 2400, 4800, 9600, 19200 bits/sec

Start bit:

A first bit always of the same polarity for equipment to sync on

Data Bits:

The useful data follows the start bit:

Typically 5, 6, 7, or 8 bits

Parity Bit:

Even Parity, Odd Parity, Mark parity, No Parity

Stop Bits:

The trailing bits after the data and parity to ensure time to “catch” data

Typically 1, 1.5, or 2 bits

Page 9: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

RS232

For Project 2 you will:

• Create a stream of ASCII characters,

• Observe the transmission of the pulse stream,

• Change the parameters of the transmission, and

• Explain all aspects of the transmission.

Page 10: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

RS232

import java.io.*;import javax.comm.*;

public class SimpleWrite{ public static void main(String[] args) throws Exception { OutputStream outputStream; outputStream = get_the_serial_port(); byte[] data = {'a'}; for (int i = 0; i < 1000; i++) { outputStream.write(data); System.out.println ("i = " + i); Thread.sleep(1000); // milliseconds } }

public static OutputStream get_the_serial_port() throws Exception { CommPortIdentifier portId; portId = CommPortIdentifier.getPortIdentifier("COM1"); SerialPort serialPort; serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000); serialPort.setSerialPortParams(9600, // change baud rate here. SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); return serialPort.getOutputStream(); }}

Java Program to transmit Character stream

Page 11: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

LC-3 Assembly Language Syntax

• Each line of a program is one of the following:– an instruction– an assember directive (or pseudo-op)– a comment

• Whitespace (between symbols) and case are ignored.• Comments (beginning with “;”) are also ignored.

• An instruction has the following format:

LABEL OPCODE OPERANDS ;COMMENTS

optional mandatory

Page 12: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

An Assembly Language Program

;; Program to multiply a number by the constant 6;

.ORIG x3050LD R1, SIXLD R2, NUMBERAND R3, R3, #0 ; Clear R3. It will

; contain the product.; The inner loop;AGAIN ADD R3, R3, R2

ADD R1, R1, #-1 ; R1 keeps track ofBRp AGAIN ; the iteration.

;HALT

;NUMBER .BLKW 1SIX .FILL x0006;

.END

Page 13: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

Assembler Directives

• Pseudo-operations– do not refer to operations executed by program– used by assembler– look like instruction, but “opcode” starts with dot

Opcode Operand Meaning.ORIG address starting address of program

.END end of program

.BLKW n allocate n words of storage

.FILL n allocate one word, initialize with value n

.STRINGZ n-character string

allocate n+1 locations, initialize w/characters and null terminator

Page 14: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

Trap Codes

• LC-3 assembler provides “pseudo-instructions” foreach trap code, so you don’t have to remember them.

Code Equivalent Description

HALT TRAP x25 Halt execution and print message to console.

IN TRAP x23 Print prompt on console,read (and echo) one character from keybd.Character stored in R0[7:0].

OUT TRAP x21 Write one character (in R0[7:0]) to console.

GETC TRAP x20 Read one character from keyboard.Character stored in R0[7:0].

PUTS TRAP x22 Write null-terminated string to console.Address of string is in R0.

Page 15: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

LC-3 Editor / Simulator

Go to Authors Web page (http://www.mhhe.com/patt2 )

Download LC-3 (LC301.exe)

LC-3 Edit

LC-3 Simulate

Review “Guide to Using the Windows Version of the LC-3 Simulator and LC-3 Edit”

Page 16: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

Sample Program

• Count the occurrences of a character in a file.Remember this?

Count = 0(R2 = 0)

Ptr = 1st file character(R3 = M[x3012])

Input charfrom keybd

(TRAP x23)

Done?(R1 ?= EOT)

Load char from file(R1 = M[R3])

Match?(R1 ?= R0)

Incr Count(R2 = R2 + 1)

Load next char from file(R3 = R3 + 1, R1 = M[R3])

Convert count toASCII character

(R0 = x30, R0 = R2 + R0)

Print count(TRAP x21)

HALT(TRAP x25)

NO

NO

YES

YES

Page 17: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

Count the occurrences of a character in a file (1 0f 2).

;; Program to count occurrences of a character in a file.; Character to be input from the keyboard.; Result to be displayed on the monitor.; Program only works if no more than 9 occurrences are found.; ;; Initialization;

.ORIG x3000AND R2, R2, #0 ; R2 is counter, initially 0LD R3, PTR ; R3 is pointer to character fileGETC ; R0 gets input characterLDR R1, R3, #0 ; R1 gets first character from file

;; Test character for end of file;TEST ADD R4, R1, #-4 ; Test for EOT (ASCII x04)

BRz OUTPUT ; If done, prepare the output;; Test character for match. If a match, increment count.;

NOT R1, R1ADD R1, R1, R0 ; If match, R1 = xFFFFNOT R1, R1 ; If match, R1 = x0000BRnp GETCHAR ; If no match, do not incrementADD R2, R2, #1

;; Get next character from file.;GETCHAR ADD R3, R3, #1 ; Point to next character.

LDR R1, R3, #0 ; R1 gets next char to testBRnzp TEST

Page 18: Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator

Count the occurrences of a character in a file (2 of 2).

;; Output the count.;OUTPUT LD R0, ASCII ; Load the ASCII template

ADD R0, R0, R2 ; Covert binary count to ASCIIOUT ; ASCII code in R0 is displayed.HALT ; Halt machine

;; Storage for pointer and ASCII template;ASCII .FILL x0030 ; ASCII offsetPTR .FILL x4000 ; PTR to character file

.END