Download aLec02 - The University of Texas at Austin

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to Embedded Microcomputer Systems
Lecture 2.1
Appendix 1. Embedded system development using TExaS
A1.1. Introduction to TExaS
TExaS supports all five phases of software development:
• defining the microcomputer type and memory configuration,
• writing the program source code using an editor,
• assembling source code and loading object code into memory,
• interfacing external components,
• debugging the program by running it on the interactive simulator.
Observation: Hiding windows will improve the simulation speed.
Checkpoint A1.1: What is an assembly source code?
Program file (*.rtf) source code.
TheLog.rtf
logs information
TheList.rtf the assembly listing
TheCRT.rtf
the input/output data of a CRT terminal
Microcomputer file (*.uc) internal microcomputer
I/O Device file (*.io) external I/O devices
switches, LEDs, LCDs, keyboard, the CRT, motors, IR and sensors.
Stack file (*.stk) holds temporary information
Scope file (*.scp) used for debugging
Plot file (*.plt) display graphical information
Checkpoint A1.2: An oscilloscope graphically displays information about an electronic
circuit. Which parameter is displayed on the y-axis and which parameter is displayed on
the x-axis.
Checkpoint A1.3: How does a logic analyzer differ from an oscilloscope?
Checkpoint A1.4: What is object code?
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.2
A1.2. Major components of TExaS
editor
assembler
source code to object code
instruction set simulator
bus cycle activity and the extensive error checking
I/O port simulator
external device simulator
unique aspect of this simulator is the error checking.
• execution of an illegal instruction,
• read/write to an undefined address,
• stack underflow (a read/write from unimplemented memory),
• write to ROM, EPROM, EEPROM,
• read from unprogrammed ROM, EPROM, EEPROM,
• read from RAM that has not yet been written to,
• read from an unimplemented I/O port.
Inputs
Processing
Outputs
+5V
+5V
220
microcomputer
7406
PC3
+5V
PB3
10k
+5V
220
7406
PC2
PB2
+5V
10k
+5V
220
7406
10k
+5V
PC1
+5V
PB1
220
7406
PC0
PB0
10k
Figure A1.7. Simple microcomputer system with four inputs and four outputs.
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.3
A1.3. Developing assembly software
modifying an existing example
readme.txt
start from scratch
Top down embedded system design
first draw a data flow graph
choose inputs, outputs
choose data structures
define major hardware/software modular blocks
estimate calculations/sec, memory size
choose a processor family
next draw a call graph showing the control linkage
design at a very high level using pseudo code
design at a lower level using a high level language like C
convert the software by hand into assembly
simulate prototype
test and redesign algorithms
choose a specific microcontroller
build and test actual prototype
A1.3.2. Modifying an existing assembly language program
find and open an existing system.
reconfigure the processor and external I/O ports
write assembly code
configuring the simulation modes
running and debugging
Online homework submission
You can work together in groups of any size, but everyone enters a separate online solution.
STEP 1: Log into the Homework Service at the URL https://hw.utexas.edu/
Unique number: 16165
There is no keypad, but please spell your name exactly how the university officially knows you.
STEP 2:
Download: Students' Instructions
Download: First Homework
STEP 3: Work one homework question. Log in again and submit its answer before next class period.
STEP 4: Continue submitting answers until due time.
STEP 5: Download the solutions after due time.
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.4
Architecture defines how the various computer components are connected.
The 6812 has a von Neumann architecture
processor
bus interface unit
registers
EAR
CCR
A:B
X
Y
SP
PC
control
address
data
control unit ALU
IR
Figure 3.7. four basic components of the 6812 processor.
7
0
S XH I NZ V C
8
15
Register A
Register B
CC 8 bit condition code
D
two 8 bit accumulators
X
16 bit index register
Y
16 bit index register
SP 16 bit stack pointer
PC 16 bit program counter
Figure 3.8. The 6812 has 6 registers.
2. Information.
Chapter 2 objectives are:
• how numbers are stored on the computer,
• how characters are represented,
• precision, basis, hexadecimal, big and little endian,
• arithmetic and logic operations,
• condition code bits,
• convert character strings and binary numbers,
• fixed-point and floating point numbers.
Precision is the number of distinct or different values.
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.5
The last column in both tables are rough approximations, and the ranges are given for unsigned
decimal numbers.
binary
bits
8
10
12
16
20
24
30
bytes
exact range
1
exact
alternatives
256
1024
4096
65536
1,048,576
16,777,216
1,073,741,824
approximate decimal
digits
≈ 2½
≈3
≈ 3¾
≈ 4¾
≈6
≈ 7½
≈9
0 to 255
0 to 1023
0 to 4095
2
0 to 65535
0 to 1,048,575
3
0 to 16,777,215
0 to
1,073,741,823
32
4
0 to
4,294,967,296 ≈ 9¾
4,294,967,295
n
[[n/8]] 0 to 2n
2n
≈ n*log10(2)
Table 2.1. Relationships between various representations of precision.
Table 2.2. represents THE DEFINITION of decimal digits. The specification of decimal digits
goes 4, 4½, 4¾, 5, with no other possibilities in between. The numbers 4.3 and 4⅛ are not valid
representations of decimal digits.
decimal digits
exact range
exact
alternatives
3
0 to 999
1,000
3½
0 to 1999
2,000
3¾
0 to 3999
4,000
4
0 to 9999
10,000
4½
0 to 19,999
20,000
4¾
0 to 39,999
40,000
5
0 to 99,999
100,000
5½
0 to 199,999
200,000
5¾
0 to 399,999
400,000
6
0 to 999,999
1,000,000
6½
0 to 199,999
2,000,000
6¾
0 to 3,999,999
4,000,000
N
N
0 to 10 -1
10N
N½
0 to 2*10N-1
2*10N
N¾
0 to 4*10N-1
4*10N
Table 2.2. Standard definition of decimal digits.
approximate bits
≈ 10
≈ 11
≈ 12
≈ 13
≈ 14
≈ 15
≈ 17
≈ 18
≈ 19
≈ 20
≈ 21
≈ 22
≈ N*log2(10)
≈ N*log2(10)+1
≈ N*log2(10)+2
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.6
2.1. Hexadecimal representation
base 16
convenient to represent binary information
Hex Digit
Decimal Value
0
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
A or a
10
B or b
11
C or c
12
D or d
13
E or e
14
F or f
15
Table 2.3. Definition of hexadecimal representation.
environment
binary
hex
Freescale
%01111010
$7A
Intel and TI
01111010B
7AH
C language
0x7A
Table 2.4. Comparison of various formats.
Binary Value
%0000
%0001
%0010
%0011
%0100
%0101
%0110
%0111
%1000
%1001
%1010
%1011
%1100
%1101
%1110
%1111
decimal
122
122
122
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.7
Easy to convert from binary to hexadecimal:
binary
%11011001111101
nibbles
0011 0110 0111 1101
hexadecimal
$367D
Figure 2.1. Example conversion
Checkpoint 2.4: Convert the binary number %01000101 to hexadecimal.
Checkpoint 2.5: Convert the binary number %110010101011 to hexadecimal.
to convert from hexadecimal to binary we can:
1) convert each hexadecimal digit
into its corresponding 4-bit binary nibble,
2) combine the nibbles into a single binary number.
hexadecimal
nibbles
binary
$1B3F
0001 1011 0011 1111
%0001101100111111
Figure 2.2. Example conversion from hex to binary.
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.8
2.3. 8-bit numbers
2.3.1. 8-bit unsigned numbers
b7
b6
b5
b4
b3
b2
b1
b0
Figure 2.4. 8-bit binary format.
the value of the number is
N = 128•b7 +64•b6 +32•b5 +16•b4 +8•b3 +4•b2 +2•b1 +b0
Notice that the significance of bit n is 2n.
There are 256 different unsigned 8-bit numbers.
binary
hex
%00000000
$00
%01000001
$41
%00010110
$16
%10000111
$87
%11111111
$FF
Table 2.5. Examples
Calculation
64+1
16+4+2
128+4+2+1
128+64+32+16+8+4+2+1
decimal
0
65
22
135
255
Checkpoint 2.10: Convert the binary number %10010010 to unsigned decimal.
Checkpoint 2.11: Convert the hex number $A2 to unsigned decimal.
The basis of a number system
a subset from which linear combinations of the basis elements can be used to construct
the entire set.
{1, 2, 4, 8, 16, 32, 64, 128}
The values of a binary number system can only be 0 or 1.
(0,1,0,0,0,1,0,1)(128,64,32,16,8,4,2,1)
Mark W. Welker (From Jonathan W. Valvano)
For example, 69 is
Introduction to Embedded Microcomputer Systems
Lecture 2.9
Number
Basis
Need it?
202
128
yes
74
64
yes
10
32
no
10
16
no
10
8
yes
2
4
no
2
2
yes
0
1
no
Table 2.6. Example conversion.
bit
bit 7=1
bit 6=1
bit 5=0
bit 4=0
bit 3=1
bit 2=0
bit 1=1
bit 0=0
Operation
subtract 202-128
subtract 74-64
none
none
subtract 10-8
none
subtract 2-2
none
1100,1010 is $CA
2.3.2. 8-bit signed numbers
b7
b6
b5
b4
b3
b2
b1
b0
Figure 2.4. two’s complement number system
N= -128•b7+64•b6 +32•b5 +16•b4 +8•b3 +4•b2 +2•b1 +b0
There are 256 different signed 8-bit numbers.
binary
hex
Calculation
%00000000
$00
%01000001
$41
64+1
%00010110
$16
16+4+2
%10000111
$87
-128+4+2+1
%11111111
$FF
-128+64+32+16+8+4+2+1
Table 2.7. Example conversions
dec
0
65
22
-121
-1
For the signed 8-bit number system the basis is
{1, 2, 4, 8, 16, 32, 64, -128}
Observation: The most significant bit in a two’s complement signed number will specify
the sign.
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.10
%11111111 could represent either 255 or -1.
You keep track of the number format.
The computer can not determine if signed or unsigned.
signed or unsigned by the assembly instructions you select
e.g., mul versus smul
Number
Basis
Need it
-100
-128
yes
28
64
no
28
32
no
28
16
yes
12
8
yes
4
4
yes
0
2
no
0
1
no
Table 2.8. Example conversion
bit
bit 7=1
bit 6=0
bit 5=0
bit 4=1
bit 3=1
bit 2=1
bit 1=0
bit 0=0
Operation
subtract -100 - -128
none
none
subtract 28-16
subtract 12-8
subtract 4-4
none
none
Observation: To take the negative of a two’s complement signed number we first
complement (flip) all the bits, then add 1.
A second way to convert negative numbers into binary is to first convert them into
unsigned binary, then do a two’s complement negate.
A third way to convert negative numbers into binary is to first add 256 to the number,
then convert the unsigned result to binary using the unsigned method.
Common Error: An error will occur if you use signed operations on unsigned numbers,
or use unsigned operations on signed numbers.
Maintenance Tip: To improve the clarity of our software, always specify the format of
your data (signed versus unsigned) when defining or accessing the data.
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.11
2.3.3. Character information
American Standard Code for Information Interchange (ASCII) code.
BITS 4 to 6
0
1
2
3
0 NUL DLE SP
0
B 1 SOH DC1 :
1
I 2 STX DC2 !
2
T 3 ETX DC3 #
3
S 4 EOT DC4 $
4
5 ENQ NAK %
5
0 6 ACK SYN &
6
7 BEL ETB '
7
T 8 BS CAN (
8
O 9 HT EM
)
9
A LF SUB *
:
3 B VT ESC +
;
C FF FS
,
<
D CR GS
=
E SO RS
.
>
F S1 US
/
?
Table 2.11. Standard 7-bit ASCII.
4
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
5
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
6
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
7
p
q
r
s
t
u
v
w
x
y
z
{
;
}
~
DEL
2.4.1. 16-bit unsigned numbers
A word or double byte contains 16 bits
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4
b3 b2 b1 b0
Figure 2.5. 16-bit binary format.
N = 32768•b15 + 16384•b14 + 8192•b13 + 4096•b12
+ 2048•b11 + 1024•b10 + 512•b9 + 256•b8
+ 128•b7 + 64•b6 + 32•b5 + 16•b4 + 8•b3 + 4•b2
+ 2•b1 + b0
For the unsigned 16-bit number system the basis is
{1, 2, 4, 8, 16, 32, 64, 128,
256, 512, 1024, 2048, 4096, 8192, 16384, 32768}
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.12
2.4.2. 16-bit signed numbers
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4
b3 b2 b1 b0
Figure 2.5. 16-bit binary format.
N = -32768•b15 + 16384•b14 + 8192•b13 + 4096•b12
+ 2048•b11 + 1024•b10 + 512•b9 + 256•b8
+ 128•b7 + 64•b6 + 32•b5 + 16•b4 + 8•b3 + 4•b2
+ 2•b1 + b0
For the signed 16-bit number system the basis is
{1, 2, 4, 8, 16, 32, 64, 128,
256, 512, 1024, 2048, 4096, 8192, 16384, -32768}
Common Error: An error will occur if you use 16-bit operations on 8-bit numbers, or use
8-bit operations on 16-bit numbers.
Maintenance Tip: To improve the clarity of your software, always specify the precision
of your data when defining or accessing the data.
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.13
2.4.3. Big and little endian
address contents
address contents
$0050 $03
$0050
$E8
$0051 $E8
$0051
$03
Big Endian
Little Endian
Figure 2.6. Example of big and little endian formats
address contents
address contents
$0050 $12
$0051 $34
$0052 $56
$0053 $78
Big Endian
$0050 $78
$0051 $56
$0052 $34
$0053 $12
Little Endian
Figure 2.7. Example of big and little endian formats
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.14
2.5. Programming numbers in assembly language
w is signed 8-bit -128 to +127
or unsigned 8-bit 0 to 255
n is signed 8-bit -128 to +127
u is unsigned 8-bit 0 to 255
W is signed 16-bit -32787 to +32767
or unsigned 16-bit 0 to 65535
N is signed 16-bit -32787 to +32767
U is unsigned 16-bit 0 to 65535
=[addr] 8-bit read from addr
={addr} 16-bit read from addr
[addr]= 8-bit write to addr
{addr}= 16-bit write to addr
ldaa #w
ldaa u
ldaa U
staa u
staa U
bra
RegA=w
RegA=[u]
RegA=[U]
[u]=RegA
[U]=RegA
U
PC=U
6811/6812
RAM
processor
Reg A
ROM
Reg PC
I/O port
Figure 2.10. The ldaa Data instruction loads
6811/6812
RAM
processor
Reg A
ROM
Reg PC
I/O port
Figure 2.11. The staa PORTB instruction stores
Mark W. Welker (From Jonathan W. Valvano)
Introduction to Embedded Microcomputer Systems
Lecture 2.15
Checkpoint 2.30: Write assembly code that copies the data from memory location 10 to
memory location 20.
Checkpoint 2.31: Write assembly code that writes the binary %11000111 to Port B.
Mark W. Welker (From Jonathan W. Valvano)