You are on page 1of 18

Introduction to Embedded Microcomputer Systems Lecture 3.

1
Jonathan W. Valvano

processor
registers
bus interface unit
EAR
ALU
control unit
CCR
A:B
X
Y
SP
PC
IR
control
address
data

Figure 3.7. four basic components of the 6812 processor.

CC
D
X
Y
SP
PC
8 bit condition code
two 8 bit accumulators
16 bit index register
16 bit index register
16 bit stack pointer
16 bit program counter
7 0
15
X H
Register A Register B
S I N Z V C
8

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.

Introduction to Embedded Microcomputer Systems Lecture 3.2
Jonathan W. Valvano
The last column in both tables are rough approximations, and
the ranges are given for unsigned decimal numbers.

binary
bits
bytes exact range exact
alternatives
approximate decimal
digits
8 1 0 to 255 256 2
10 0 to 1023 1024 3
12 0 to 4095 4096 3
16 2 0 to 65535 65536 4
20 0 to 1,048,575 1,048,576 6
24 3 0 to 16,777,215 16,777,216 7
30
0 to 1,073,741,823
1,073,741,824 9
32 4
0 to 4,294,967,295
4,294,967,296 9
n [[n/8]] 0 to 2
n
2
n
n*log
10
(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
approximate bits
3 0 to 999 1,000 10
3 0 to 1999 2,000 11
3 0 to 3999 4,000 12
4 0 to 9999 10,000 13
4 0 to 19,999 20,000 14
4 0 to 39,999 40,000 15
5 0 to 99,999 100,000 17
5 0 to 199,999 200,000 18
5 0 to 399,999 400,000 19
Introduction to Embedded Microcomputer Systems Lecture 3.3
Jonathan W. Valvano
6 0 to 999,999 1,000,000 20
6 0 to 199,999 2,000,000 21
6 0 to 3,999,999 4,000,000 22
N 0 to 10
N
-1 10
N
N*log
2
(10)
N 0 to 2*10
N
-1 2*10
N
N*log
2
(10)+1
N 0 to 4*10
N
-1 4*10
N
N*log
2
(10)+2
Table 2.2. Standard definition of decimal digits.

The formal definition of decimal digits is N decimal

2.1. Hexadecimal representation
base 16
convenient to represent binary information

Hex Digit Decimal Value Binary Value
0 0 %0000
1 1 %0001
2 2 %0010
3 3 %0011
4 4 %0100
5 5 %0101
6 6 %0110
7 7 %0111
8 8 %1000
9 9 %1001
A or a 10 %1010
B or b 11 %1011
C or c 12 %1100
D or d 13 %1101
E or e 14 %1110
Introduction to Embedded Microcomputer Systems Lecture 3.4
Jonathan W. Valvano
F or f 15 %1111
Table 2.3. Definition of hexadecimal representation.



environment binary hex decimal
Motorola %01111010 $7A 122
Intel and TI 01111010B 7AH 122
C language 0x7A 122
Table 2.4. Comparison of various formats.

Easy to convert from binary to hexadecimal:

binary
nibbles
hexadecimal
$367D
%11011001111101
0011 0110 0111 1101

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,
Introduction to Embedded Microcomputer Systems Lecture 3.5
Jonathan W. Valvano
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.

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 = 128b
7
+64b
6
+32b
5
+16b
4
+8b
3
+4b
2
+2b
1
+b
0


Notice that the significance of bit n is 2
n
.
There are 256 different unsigned 8-bit numbers.

binary hex Calculation decimal
%00000000 $00 0
%01000001 $41 64+1 65
%00010110 $16 16+4+2 22
%10000111 $87 128+4+2+1 135
%11111111 $FF 128+64+32+16+8+4+2+1 255
Table 2.5. Examples

Introduction to Embedded Microcomputer Systems Lecture 3.6
Jonathan W. Valvano
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. For
example, 69 is (0,1,0,0,0,1,0,1)(128,64,32,16,8,4,2,1)


Number Basis Need it? bit Operation
202 128 yes bit 7=1 subtract 202-128
74 64 yes bit 6=1 subtract 74-64
10 32 no bit 5=0 none
10 16 no bit 4=0 none
10 8 yes bit 3=1 subtract 10-8
2 4 no bit 2=0 none
2 2 yes bit 1=1 subtract 2-2
0 1 no bit 0=0 none
Table 2.6. Example conversion.
1100,1010 is $CA

2.3.2. 8-bit signed numbers

Introduction to Embedded Microcomputer Systems Lecture 3.7
Jonathan W. Valvano
b7 b6 b5 b4 b3 b2 b1 b0

Figure 2.4. twos complement number system

N= -128b
7
+64b
6
+32b
5
+16b
4
+8b
3
+4b
2
+2b
1
+b
0


There are 256 different signed 8-bit numbers.

binary hex Calculation dec
%00000000 $00 0
%01000001 $41 64+1 65
%00010110 $16 16+4+2 22
%10000111 $87 -128+4+2+1 -121
%11111111 $FF -128+64+32+16+8+4+2+1 -1
Table 2.7. Example conversions

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 twos
complement signed number will specify the sign.

%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 bit Operation
-100 -128 yes bit 7=1 subtract -100 - -128
Introduction to Embedded Microcomputer Systems Lecture 3.8
Jonathan W. Valvano
28 64 no bit 6=0 none
28 32 no bit 5=0 none
28 16 yes bit 4=1 subtract 28-16
12 8 yes bit 3=1 subtract 12-8
4 4 yes bit 2=1 subtract 4-4
0 2 no bit 1=0 none
0 1 no bit 0=0 none
Table 2.8. Example conversion

Observation: To take the negative of a twos 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 twos
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.


Introduction to Embedded Microcomputer Systems Lecture 3.9
Jonathan W. Valvano
2.3.3. Character information
American Standard Code for Information Interchange
(ASCII) code.

BITS 4 to 6
0 1 2 3 4 5 6 7
0 NUL DLE SP 0 @ P ` p
B 1 SOH DC1 : 1 A Q a q
I 2 STX DC2 ! 2 B R b r
T 3 ETX DC3 # 3 C S c s
S 4 EOT DC4 $ 4 D T d t
5 ENQ NAK % 5 E U e u
0 6 ACK SYN & 6 F V f v
7 BEL ETB ' 7 G W g w
T 8 BS CAN ( 8 H X h x
O 9 HT EM ) 9 I Y i y
A LF SUB * : J Z j z
3 B VT ESC + ; K [ k {
C FF FS , < L \ l ;
D CR GS - = M ] m }
E SO RS . > N ^ n ~
F S1 US / ? O _ o DEL
Table 2.11. Standard 7-bit ASCII.


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.
Introduction to Embedded Microcomputer Systems Lecture 3.10
Jonathan W. Valvano


N = 32768b
15
+ 16384b
14
+ 8192b
13
+ 4096b
12

+ 2048b
11
+ 1024b
10
+ 512b
9
+ 256b
8

+ 128b
7
+ 64b
6
+ 32b
5
+ 16b
4
+ 8b
3
+ 4b
2

+ 2b
1
+ b
0


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}


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 = -32768b
15
+ 16384b
14
+ 8192b
13
+ 4096b
12

+ 2048b
11
+ 1024b
10
+ 512b
9
+ 256b
8

+ 128b
7
+ 64b
6
+ 32b
5
+ 16b
4
+ 8b
3
+ 4b
2

+ 2b
1
+ b
0


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}

Introduction to Embedded Microcomputer Systems Lecture 3.11
Jonathan W. Valvano
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.


2.4.3. Big and little endian


address contents
$0050 $03
$0051 $E8
Big Endian
address contents
$0050 $E8
$0051 $03
Little Endian

Figure 2.6. Example of big and little endian formats



address contents
$0050 $12
$0051 $34
$0052 $56
$0053 $78
Big Endian
address contents
$0050 $78
$0051 $56
$0052 $34
$0053 $12
Little Endian

Figure 2.7. Example of big and little endian formats

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
Introduction to Embedded Microcomputer Systems Lecture 3.12
Jonathan W. Valvano
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 RegA=w
ldaa u RegA=[u]
ldaa U RegA=[U]
staa u [u]=RegA
staa U [U]=RegA
bra U PC=U


6811/6812
I/O port
RAM
ROM
processor
Reg A
Reg PC

Figure 2.10. The ldaa Data instruction loads


6811/6812
I/O port
RAM
ROM
processor
Reg A
Reg PC

Figure 2.11. The staa PORTB instruction stores
Introduction to Embedded Microcomputer Systems Lecture 3.13
Jonathan W. Valvano

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.



Appdx 1. Embedded system development using TExaS


$F000 CF0C00
$F003 180B800002
$F008 4D0080
$F00B CC115C
$F00E 7C0800
$F011 9600
$F013 847F
$F015 B1F028
$F018 26EE
$F01A FE0800
$F01D 09
$F01E 7E0800
$F021 26EE
$F023 4C0080
$F026 20E3
$F028 23
$FFFE F000
PORTA equ $0000
DDRA equ $0002
org $0800
cnt rmb 2
org $F000
main lds #$0C00
movb #$80,DDRA
off bclr PORTA,#$80
look ldd #4444
std cnt
loop ldaa PORTA
anda #$7F
cmpa key
bne off
ldx cnt
dex
stx cnt
bne loop
bset PORTA,#$80
bra look
key fcb %00100011
org $FFFE
fdb main
Source code
Assembler
Loader
Object code
processor
RAM
EPROM
I/O
Microcomputer
External circuits
and devices

Figure 4.1. Assembly language development process.



Introduction to Embedded Microcomputer Systems Lecture 3.14
Jonathan W. Valvano
$F000 CF0C00
$F003 180B800002
$F008 4D0080
$F00B CC115C
$F00E 7C0800
$F011 9600
$F013 847F
$F015 B1F028
$F018 26EE
$F01A FE0800
$F01D 09
$F01E 7E0800
$F021 26EE
$F023 4C0080
$F026 20E3
$F028 23
$FFFE F000
PORTA equ $0000
DDRA equ $0002
org $0800
cnt rmb 2
org $F000
main lds #$0C00
movb #$80,DDRA
off bclr PORTA,#$80
look ldd #4444
std cnt
loop ldaa PORTA
anda #$7F
cmpa key
bne off
ldx cnt
dex
stx cnt
bne loop
bset PORTA,#$80
bra look
key fcb %00100011
org $FFFE
fdb main
Source code
Assembler
Loader
Object code
processor
RAM
ROM
I/O
Simulated
Microcomputer
Simulated
External circuits
and devices
Editor
TExaS

Figure 4.2. Assembly language development using TExaS.



A1.5. Tutorial A1. Getting started
The purpose of this tutorial is to introduce the first time user to TExaS.
1) how to launch the simulator,
2) how to modify input switches,
3) how to edit, assemble, and run a 6812 program,
4) how to modify display format in the ViewBox,
5) how to move and resize windows,
6) how to get on-line help.

visualize four places information can be stored on a computer.
1) external switches are input devices that hold information,
2) registers are high-speed temporary storage inside the processor,
3) global variables can hold information that is easy to access,
4) external LEDs are output devices that hold information.

Action: Install and upgrade the TExaS application.
www.ece.utexas.edu/~valvano

Action: Copy the tutorial programs onto a hard drive.
copy the Mc6812T subdirectory from the CD onto a hard drive.
Introduction to Embedded Microcomputer Systems Lecture 3.15
Jonathan W. Valvano

Action: How to launch the TExaS application.

Figure A1.9. TExaS application icon.


Question A1.1. List the names of the six files that are now open.

Action: How to assemble a program.
Execute the command Assemble->Assemble,

Question A1.2. What happened to the colors of the Start, ExecuteOne, and
StepOver tools in the tool bar after the program was assembled? Why?

Action: How to modify input switches.

Question A1.3. Describe the relationship between the switch position (open or
closed) and
1) the voltage across the switch (probe near the switch)
2) the voltage at the output of the 74HC14 not gate
3) the digital value of the input port

Action: Observing the details of execution.
TheList.rtf will highlight the current instruction
details of the simulation are dumped into TheLog.rtf.

Question A1.4. Explain the behavior of each of the following modes.
Mode->FollowPC
Mode->CycleView
Mode->InstructionView
Mode->LogRecord

Introduction to Embedded Microcomputer Systems Lecture 3.16
Jonathan W. Valvano
Observation: The simulation speed (real human time to run your program)
is greatly improved by turning these four modes off.

Question A1.5. Use the help system to answer this question, Into which file are
the parameters specified by the Mode menu commands (e.g., FollowPC
CycleView InstructionView LogRecord) saved? In particular, which file do you
save when you want to remember these settings? To answer this question, execute
Help->HelpTopics, double-click Menus, then double-click Mode menu.

Action: Backdump.

Debugging Tip: Execute the Backdump command after your software
crashes.

Action: Setting breakpoints.
type the absolute address, and push the Add button.
type the symbolic name, and push the Add button.
left click in the TheList.rtf, then right click and hold.

Add a breakpoint on PORTC, and run the program.


Action: Rearranging the windows.
TheList.rtf ChapA1.uc and ChapA1.io.

Question A1.6. What is the program counter, PC? How is its initial value (right
after reset) established?

Question A1.7. What does the value PORTC=$0A in the ViewBox window mean?

Action: Changing the format of the ViewBox data.
Single step (tool bar or F10) the program until the value in PORTB just
changes to $0A.

To change the format of a ViewBox entry
1) Select the entry Click on the PORTC=$0A line in the ViewBox
2) Give the new format Type d in the Format box
3) Enter the change Type <Enter> or click on the Enter button

Introduction to Embedded Microcomputer Systems Lecture 3.17
Jonathan W. Valvano
Question A1.8. Using this procedure, click on the PC and give the values for the
following formats
H 16-bit unsigned hexadecimal ($F00F on the 6812)
+H 16-bit signed hexadecimal (+H and -H are the same format)
D 16-bit unsigned decimal
+D 16-bit signed decimal (+D and -D are the same format)
B 16-bit unsigned binary
+B 16-bit signed binary (+B and -B are the same format)
Using this procedure, click on the Data=$0A and give the values for the
following formats
h 8-bit unsigned hexadecimal (should be $0A)
+h 8-bit signed hexadecimal (+h and -h are the same format)
d 8-bit unsigned decimal
+d 8-bit signed decimal (+d and -d are the same format)
b 8-bit unsigned binary
+b 8-bit signed binary (+b and -b are the same format)
2d two unsigned decimal numbers

Action: Changing the value in the ViewBox data.
The current state of the microcomputer can be changed using this window.
To change the value of a ViewBox entry
1) Select the entry Click on the A=$0A line in the ViewBox
2) Give the new value Type 100 in the Data box
3) Enter the change Type <Enter> or click on the Enter button

To add new entries in the ViewBox (step 2 is optional)
1) Give the Address For the 6812 type the address $0900
2) Give the new value Type "TExaS" in the Data box (including the " ")
3) Enter the new format Type 6d in the Format box (try also s and 6c)

Debugging Tip: Choose the formats in the ViewBox to simplify debugging.

Debugging Tip: While debugging software adjust the parameters in the
ViewBox to include important information and exclude unimportant
information.

Action: Simulating the microcomputer hardware/software.
ChapA1.io and ChapA1.scp

Introduction to Embedded Microcomputer Systems Lecture 3.18
Jonathan W. Valvano
Observation: The simulation speed (real human time to run your program)
is greatly improved by closing (not hide) scope windows.

You might also like